A shared useOnlinePayments hook (GET /api/payments/providers) gates the registration success page, My Events (Make payment, Make donation), the donate page, Sponsor a spot, the register form's donation box and the supervisor Payment Link tab; they explain why where it helps. Roadmap: SnapScan and Zapper dropped; later versions move up by two. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
3.6 KiB
TypeScript
67 lines
3.6 KiB
TypeScript
import { test, expect, seed, 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 }] });
|
|
}
|
|
});
|
|
|
|
test("with no provider on, nothing offers to pay online", async ({ page }) => {
|
|
type EventWithOptions = { eventOptions: { id: string; isMainTicket: boolean }[] };
|
|
const event = await api<EventWithOptions>(page, "admin", "GET", `/api/events/${seed().events.paid}`);
|
|
const option = event.eventOptions.find((o) => o.isMainTicket)!;
|
|
const reg = await api<{ id: string }>(page, "admin", "POST", "/api/registrations", { eventId: seed().events.paid, options: [{ eventOptionId: option.id, quantity: 1 }] });
|
|
|
|
await api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: false }, { id: "payfast", enabled: false }] });
|
|
try {
|
|
await loginAs(page, "admin");
|
|
await page.goto(`/registration/success?registrationId=${reg.id}`);
|
|
await expect(page.getByText(/Online payment isn.t available/)).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Pay online" })).toHaveCount(0);
|
|
|
|
await page.goto("/dashboard/user");
|
|
await expect(page.getByRole("button", { name: "Make donation" })).toHaveCount(0);
|
|
await page.goto("/dashboard/user/donate");
|
|
await expect(page.getByText(/Online donations aren.t available/)).toBeVisible();
|
|
} finally {
|
|
await api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }, { id: "payfast", enabled: false }] });
|
|
}
|
|
|
|
// Back on (when Yoco is set up in this environment), the button returns
|
|
const on = await api<{ providers: unknown[] }>(page, "admin", "GET", "/api/payments/providers");
|
|
if (on.providers.length > 0) {
|
|
await page.goto(`/registration/success?registrationId=${reg.id}`);
|
|
await expect(page.getByRole("button", { name: "Pay online" })).toBeVisible();
|
|
}
|
|
});
|
|
});
|