import { expect, type Page } from "@playwright/test" import { certificateState, server } from "./certificates" export async function certificateRoutes(page: Page) { await page.route("**/health", r => r.fulfill({ json: { ok: true } })) await page.route("**/api/**", r => { const path = new URL(r.request().url()).pathname return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? [server] : path === "/api/certificates/state" ? certificateState() : path === "/api/certificates/renew-settings" ? { enabled: false, intervalSec: 300, renewBeforeDays: 30 } : { directoryUrl: "https://acme.example.test/directory", tokenConfigured: true } }) }) } export function issueJob(request: Record, overrides: Record = {}) { return { id: request.requestId, serverId: String(request.serverId), certName: request.certName, domainNames: request.domainNames, status: "done", step: "done", requestedAt: "2026-10-01T00:00:00Z", finishedAt: "2026-10-01T00:01:00Z", ...overrides } } export async function openIssue(page: Page) { await page.goto("/certificates"); const action = page.getByRole("button", { name: "Выпустить сертификат", exact: true }); await expect(action).toBeEnabled(); await action.click() const dialog = page.getByRole("dialog", { name: "Выпуск сертификата", exact: true }) await dialog.getByRole("combobox", { name: "Сервер выпуска", exact: true }).selectOption("1") await dialog.getByRole("textbox", { name: "Имя сертификата", exact: true }).fill("new-cert") await dialog.getByRole("button", { name: "Далее", exact: true }).click() await dialog.getByRole("textbox", { name: "Основной домен", exact: true }).fill("test.example") await dialog.getByRole("button", { name: "Далее", exact: true }).click() await dialog.getByRole("button", { name: "Далее", exact: true }).click() return dialog }