import { test, expect, loginAs, api } from "./fixtures"; type ProviderSetting = { id: string; label: string; enabled: boolean; configured: boolean }; test.describe("payment providers", () => { test("admin: Payments tab turns a provider on and off", async ({ page }) => { await loginAs(page, "admin"); // The tab's older name still opens it. await page.goto("/dashboard/admin/settings?tab=yoco"); await expect(page.getByRole("heading", { name: "Payments", exact: true })).toBeVisible(); await expect(page.getByRole("heading", { name: "Yoco payments" })).toBeVisible(); const providers = page.getByRole("list", { name: "Payment providers" }); const yoco = providers.getByRole("checkbox", { name: "Enable Yoco" }); await expect(yoco).toBeChecked(); try { await yoco.uncheck(); await expect(page.getByText("Payment providers saved")).toBeVisible(); await expect(page.getByText(/Online payments are off/)).toBeVisible(); // A switched-off provider's settings are hidden await expect(page.getByRole("heading", { name: "Yoco payments" })).toBeHidden(); const off = await api<{ providers: { id: string }[]; minimumAmount: number }>(page, "user", "GET", "/api/payments/providers"); expect(off.providers).toEqual([]); expect(off.minimumAmount).toBe(15); await yoco.check(); await expect(yoco).toBeChecked(); await expect(page.getByRole("heading", { name: "Yoco payments" })).toBeVisible(); const settings = await api<{ providers: ProviderSetting[] }>(page, "admin", "GET", "/api/payments/providers/settings"); expect(settings.providers.find((p) => p.id === "yoco")?.enabled).toBe(true); } finally { // Leave Yoco on for the other tests. await api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }] }); } }); });