- /api (v1) answers 410 API_V1_REMOVED, except provider webhooks (/api/webhooks/*, /api/whatsapp/webhook) and links in sent messages (308s, one-click POST). 43 v1 route files and deprecation.ts removed; /docs redirects to /docs/v2; API_DOCUMENTATION.md points there. - Read-only and impersonation lists name v2 paths only. The campus scope route test now runs over v2 routes (v2CampusScope.test.ts). - Passwords hashed with Argon2id (@node-rs/argon2); bcrypt hashes still sign in and are re-hashed at the next sign-in. - e2e on /api/v2 only (v2() helper); Playwright waits on /api/v2. - MIGRATING-TO-2.md with the full v1 -> v2 table. - Two documented response shapes corrected. Backend 690 tests and e2e 102/102 (PayFast sandbox skipped) pass. 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, v2 } 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 v2<{ providers: { id: string }[]; minimumAmount: number }>(page, "user", "GET", "/api/v2/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 v2<{ providers: ProviderSetting[] }>(page, "admin", "GET", "/api/v2/payments/providers/settings");
|
|
expect(settings.providers.find((p) => p.id === "yoco")?.enabled).toBe(true);
|
|
} finally {
|
|
// Leave Yoco on for the other tests.
|
|
await v2(page, "admin", "PUT", "/api/v2/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 v2<EventWithOptions>(page, "admin", "GET", `/api/v2/events/${seed().events.paid}/full`);
|
|
const option = event.eventOptions.find((o) => o.isMainTicket)!;
|
|
const reg = await v2<{ id: string }>(page, "admin", "POST", "/api/v2/registrations", { eventId: seed().events.paid, options: [{ eventOptionId: option.id, quantity: 1 }] });
|
|
|
|
await v2(page, "admin", "PUT", "/api/v2/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 v2(page, "admin", "PUT", "/api/v2/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 v2<{ providers: unknown[] }>(page, "admin", "GET", "/api/v2/payments/providers");
|
|
if (on.providers.length > 0) {
|
|
await page.goto(`/registration/success?registrationId=${reg.id}`);
|
|
await expect(page.getByRole("button", { name: "Pay online" })).toBeVisible();
|
|
}
|
|
});
|
|
});
|