import { expect, test } from "./utils/test"; import { getTenantCredentials, loginAsTenantUser, tenantSettingsSubscriptionPath, type TenantCredentials } from "./utils/auth"; import { expectNoCriticalA11yViolations } from "./utils/axe"; import { failOnPaymentProviderNetworkRequests, postDataIncludesField, skipIfUnavailable } from "./utils/navigation"; import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness"; const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH ?? "/app/dashboard"; const subscriptionPath = process.env.E2E_TENANT_SUBSCRIPTION_PATH ?? tenantSettingsSubscriptionPath(dashboardPath); const credentials = getTenantCredentials() ?? canonicalLocalCredentials(); test.describe("VA-P24a self-service subscription smoke", () => { test("validates plan and seats on the server without starting Mollie checkout", async ({ page }) => { requireTenantCredentials(); await failOnPaymentProviderNetworkRequests(page); const checkoutSubmissions: string[] = []; page.on("request", (request) => { if (request.method() === "POST" && postDataIncludesField(request.postData(), "intent", /^checkout$/u)) { checkoutSubmissions.push(request.url()); } }); await loginAsTenantUser(page, credentials!); const response = await page.goto(subscriptionPath, { waitUntil: "domcontentloaded" }); await skipIfUnavailable(page, response, `VA-P24a subscription path ${subscriptionPath} is unavailable`); expect(response?.ok(), `Subscription settings returned ${response?.status() ?? "no response"}`).toBe(true); await expect(page.locator('[data-ui-id="ui.billing.selfServiceSubscription.page"]')).toBeVisible(); const builder = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.builder"]'); await expect(builder).toBeVisible(); const planGroup = builder.getByRole("radiogroup", { name: /^(Tarif|Plan)$/iu }); const planOptions = planGroup.getByRole("radio"); if ((await planOptions.count()) === 0) { skipOrFailWhenE2eFixtureMissing("VA-P24a fixture needs at least one public plan with a recurring price"); } await expect(planGroup).toBeVisible(); await expect(planOptions.first()).toBeVisible(); await expect(planGroup.locator('[role="radio"][aria-checked="true"]').first()).toBeVisible(); await expect(builder.getByRole("radiogroup", { name: /^(Abrechnungszeitraum|Billing period)$/iu })).toBeVisible(); const officeSeats = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.officeSeats"]'); const fieldSeats = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.fieldSeats"]'); await expect(officeSeats).toBeVisible(); await expect(fieldSeats).toBeVisible(); if (!(await officeSeats.isEnabled()) || !(await fieldSeats.isEnabled())) { skipOrFailWhenE2eFixtureMissing("VA-P24a fixture user needs subscription update permission"); } const minimumOfficeSeats = Number(await officeSeats.getAttribute("min")) || 1; const currentOfficeSeats = Number(await officeSeats.inputValue()) || minimumOfficeSeats; const previewOfficeSeats = Math.max(minimumOfficeSeats, currentOfficeSeats) + 1; await officeSeats.fill(String(previewOfficeSeats)); await expect(officeSeats).toHaveValue(String(previewOfficeSeats)); const previewButton = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.preview"]'); await expect(previewButton).toBeVisible(); if (!(await previewButton.isEnabled())) { skipOrFailWhenE2eFixtureMissing("VA-P24a fixture cannot submit the server-side price preview"); } const previewResponsePromise = page.waitForResponse((previewResponse) => { const request = previewResponse.request(); if (request.method() !== "POST" || !postDataIncludesField(request.postData(), "intent", /^preview$/u)) return false; const requestPath = new URL(request.url()).pathname.replace(/\/$/u, ""); const expectedPath = new URL(subscriptionPath, "http://e2e.local").pathname.replace(/\/$/u, ""); return requestPath === expectedPath || requestPath === `${expectedPath}.data`; }); await previewButton.click(); const previewResponse = await previewResponsePromise; expect(previewResponse.ok(), `Server preview returned ${previewResponse.status()}`).toBe(true); const dialog = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.previewDialog"]'); await expect(dialog).toBeVisible(); const recurringLabel = dialog.getByText(/^(Monatlicher Nettobetrag|Monthly net amount)$/iu).first(); await expect(recurringLabel).toBeVisible(); const recurringValue = recurringLabel.locator("..").locator("span").last(); await expect(recurringValue).toHaveText(/\d/u); await expect(recurringValue).toHaveText(/\//u); const effectiveLabel = dialog.getByText(/^(Wirksam ab|Effective from)$/iu).first(); await expect(effectiveLabel).toBeVisible(); const effectiveValue = effectiveLabel.locator("..").locator("span").last(); await expect(effectiveValue).toHaveText(/(Sofort|Immediately|Ende|end|\d)/iu); const checkoutButton = dialog.locator('[data-ui-id="ui.billing.selfServiceSubscription.checkout"]'); await expect(checkoutButton).toBeVisible(); await expectNoCriticalA11yViolations(page); await dialog.getByRole("button", { name: /^(Auswahl ändern|Change selection)$/iu }).click(); await expect(dialog).toBeHidden(); expect(checkoutSubmissions).toEqual([]); expect(page.url()).not.toMatch(/mollie\.com/iu); }); }); function canonicalLocalCredentials(): TenantCredentials | null { const target = new URL(process.env.E2E_BASE_URL ?? "http://localhost:3000"); const local = target.hostname === "localhost" || target.hostname === "127.0.0.1" || target.hostname === "::1" || target.hostname.endsWith(".localhost"); return local ? { email: "admin@email.com", password: "password" } : null; } function requireTenantCredentials(): void { if (credentials) return; skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD"], "VA-P24a subscription smoke needs tenant credentials for a non-local target"); }