WIP 2.0.0: v1 removed; Argon2id passwords; node-fetch gone
- /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>
This commit is contained in:
@@ -68,7 +68,7 @@ test.describe("API v2", () => {
|
||||
// A free ticket for the user, then check it in twice through v2.
|
||||
const event = (await (await request.get(`${API}/api/v2/events/${seed().events.free}`)).json()).data;
|
||||
await request.post(`${API}/api/v2/registrations`, { headers, data: { eventId: event.id, options: [{ eventOptionId: event.ticketOptions[0].id, quantity: 1 }] } });
|
||||
const tickets = await (await request.get(`${API}/api/tickets/mytickets`, { headers })).json();
|
||||
const tickets = (await (await request.get(`${API}/api/v2/me/tickets`, { headers })).json()).data;
|
||||
const qr = tickets.find((t: { eventId: string; qrCode: string }) => t.eventId === event.id).qrCode;
|
||||
|
||||
const staff = { Authorization: `Bearer ${seed().users.staff.token}` };
|
||||
@@ -84,17 +84,14 @@ test.describe("API v2", () => {
|
||||
expect((await (await request.post(`${API}/api/v2/checkin/NOT-A-CODE`, { headers: staff, data: {} })).json()).error.code).toBe("NOT_FOUND");
|
||||
});
|
||||
|
||||
test("v1 endpoints with a v2 version say so", async ({ request }) => {
|
||||
test("v1 is gone in 2.0, except webhooks and links in messages already sent", async ({ request }) => {
|
||||
const v1 = await request.get(`${API}/api/events`);
|
||||
expect(v1.headers()["deprecation"]).toMatch(/^@\d+$/);
|
||||
expect(v1.headers()["link"]).toBe(`</api/v2/events>; rel="successor-version"`);
|
||||
const all = await request.get(`${API}/api/events/all`, { headers: { Authorization: `Bearer ${seed().users.staff.token}` } });
|
||||
expect(all.headers()["link"]).toBe(`</api/v2/events/manage>; rel="successor-version"`);
|
||||
expect((await request.get(`${API}/api/settings/needs-setup`)).headers()["link"]).toBe(`</api/v2/setup/needed>; rel="successor-version"`);
|
||||
// Incoming webhooks: the v1 address still works (same handler) and names its v2 one.
|
||||
const hook = await request.post(`${API}/api/webhooks/whatsapp`, { data: {} });
|
||||
expect(hook.status()).toBe(200);
|
||||
expect(hook.headers()["link"]).toBe(`</api/v2/webhooks/whatsapp>; rel="successor-version"`);
|
||||
expect(v1.status()).toBe(410);
|
||||
expect((await v1.json()).code).toBe("API_V1_REMOVED");
|
||||
expect((await request.post(`${API}/api/users/login`, { data: {} })).status()).toBe(410);
|
||||
// Incoming webhooks: the v1 addresses still reach the same handlers.
|
||||
expect((await request.post(`${API}/api/webhooks/whatsapp`, { data: {} })).status()).toBe(200);
|
||||
expect((await request.post(`${API}/api/whatsapp/webhook`, { data: {} })).status()).toBe(200);
|
||||
expect((await request.post(`${API}/api/v2/webhooks/whatsapp`, { data: { event: "noop" } })).status()).toBe(200);
|
||||
// A calendar link in an email already sent goes to its v2 address.
|
||||
const ics = await request.get(`${API}/api/events/${seed().events.conference}/ics`, { maxRedirects: 0 });
|
||||
@@ -102,6 +99,9 @@ test.describe("API v2", () => {
|
||||
expect(ics.headers()["location"]).toBe(`/api/v2/events/${seed().events.conference}/calendar.ics`);
|
||||
const followed = await request.get(`${API}/api/events/${seed().events.conference}/ics`);
|
||||
expect(followed.headers()["content-type"]).toContain("text/calendar");
|
||||
// The old API reference sends people to the v2 one.
|
||||
const docs = await request.get(`${API}/docs`, { maxRedirects: 0 });
|
||||
expect(docs.headers()["location"]).toBe("/docs/v2");
|
||||
});
|
||||
|
||||
test("staff list every event; supervisors create, change and admins deactivate", async ({ request }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, loginAs, api } from "./fixtures";
|
||||
import { test, expect, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
// Bulk actions on the registrations list (1.49.1): tick several, mark them paid, move them to
|
||||
// another ticket, cancel — each through the same rules as one at a time.
|
||||
@@ -14,15 +14,15 @@ test.describe.serial("bulk actions on registrations", () => {
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
const page = await browser.newPage();
|
||||
const start = new Date(Date.now() + 20 * 864e5);
|
||||
event = await api<Ev>(page, "admin", "POST", "/api/events", {
|
||||
event = await v2<Ev>(page, "admin", "POST", "/api/v2/events", {
|
||||
title: "E2E Bulk Night", startDate: start.toISOString(), endDate: new Date(start.getTime() + 3 * 3600e3).toISOString(),
|
||||
price: 100, location: "Church hall",
|
||||
});
|
||||
const full = await api<Ev>(page, "admin", "GET", `/api/events/${event.id}`);
|
||||
const full = await v2<Ev>(page, "admin", "GET", `/api/v2/events/${event.id}/full`);
|
||||
main = full.eventOptions!.find(o => o.isMainTicket)!.id;
|
||||
vip = (await api<{ id: string }>(page, "admin", "POST", `/api/events/${event.id}/options`, { name: "VIP", price: 150, isMainTicket: true })).id;
|
||||
vip = (await v2<{ id: string }>(page, "admin", "POST", `/api/v2/events/${event.id}/ticket-options`, { name: "VIP", price: 150, isMainTicket: true })).id;
|
||||
for (const role of ["staff", "supervisor", "user"] as const) {
|
||||
regs.push((await api<{ id: string }>(page, role, "POST", "/api/registrations", { eventId: event.id, options: [{ eventOptionId: main, quantity: 1 }] })).id);
|
||||
regs.push((await v2<{ id: string }>(page, role, "POST", "/api/v2/registrations", { eventId: event.id, options: [{ eventOptionId: main, quantity: 1 }] })).id);
|
||||
}
|
||||
await page.close();
|
||||
});
|
||||
@@ -45,7 +45,7 @@ test.describe.serial("bulk actions on registrations", () => {
|
||||
await expect(page.getByTestId("bulk-result")).toContainText("3 done");
|
||||
|
||||
for (const id of regs) {
|
||||
const r = await api<Reg>(page, "admin", "GET", `/api/registrations/${id}`);
|
||||
const r = await v2<Reg>(page, "admin", "GET", `/api/v2/registrations/${id}/full`);
|
||||
expect(r.status).toBe("paid");
|
||||
expect(r.payments?.map(p => [p.amount, p.method])).toEqual([[100, "cash"]]);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ test.describe.serial("bulk actions on registrations", () => {
|
||||
await bar.getByRole("button", { name: /Move to another ticket/ }).click();
|
||||
await expect(page.getByTestId("bulk-result")).toContainText("2 done");
|
||||
|
||||
const moved = await Promise.all(regs.map(id => api<Reg>(page, "admin", "GET", `/api/registrations/${id}`)));
|
||||
const moved = await Promise.all(regs.map(id => v2<Reg>(page, "admin", "GET", `/api/v2/registrations/${id}/full`)));
|
||||
const onVip = moved.filter(r => r.registrationOptions?.some(o => o.eventOptionId === vip));
|
||||
expect(onVip).toHaveLength(2);
|
||||
// R150 now, R100 paid: they owe the difference.
|
||||
@@ -73,14 +73,14 @@ test.describe.serial("bulk actions on registrations", () => {
|
||||
await bar.getByRole("button", { name: "Clear selection" }).click();
|
||||
const left = moved.find(r => !r.registrationOptions?.some(o => o.eventOptionId === vip))!;
|
||||
await page.getByRole("checkbox", { name: /^Select / }).nth(2).check();
|
||||
const selectedId = (await api<Reg>(page, "admin", "GET", `/api/registrations/${left.id}`)).id;
|
||||
const selectedId = (await v2<Reg>(page, "admin", "GET", `/api/v2/registrations/${left.id}/full`)).id;
|
||||
expect(selectedId).toBe(left.id);
|
||||
const bar2 = page.getByTestId("bulk-bar");
|
||||
await bar2.getByLabel("Bulk action").selectOption("cancel");
|
||||
page.once("dialog", d => d.accept());
|
||||
await bar2.getByRole("button", { name: /Cancel — 1/ }).click();
|
||||
await expect(page.getByTestId("bulk-result")).toContainText("1 done");
|
||||
const cancelled = (await Promise.all(regs.map(id => api<Reg>(page, "admin", "GET", `/api/registrations/${id}`)))).filter(r => r.status === "cancelled");
|
||||
const cancelled = (await Promise.all(regs.map(id => v2<Reg>(page, "admin", "GET", `/api/v2/registrations/${id}/full`)))).filter(r => r.status === "cancelled");
|
||||
expect(cancelled).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { test, expect, seed, api, loginAs, API } from "./fixtures";
|
||||
import { test, expect, seed, api, loginAs, API, v2 } from "./fixtures";
|
||||
|
||||
// Campus-scoped staff (1.44.0): the seeded staff member and supervisor are limited to E2E South
|
||||
// for these tests; afterwards the limits are cleared and campuses turned off again.
|
||||
test.describe("campus-scoped staff", () => {
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
const page = await browser.newPage();
|
||||
await api(page, "admin", "PUT", "/api/campuses/settings", { enabled: true });
|
||||
await v2(page, "admin", "PUT", "/api/v2/campuses/enabled", { enabled: true });
|
||||
for (const role of ["staff", "supervisor"] as const) {
|
||||
await api(page, "admin", "PUT", `/api/users/${seed().users[role].id}`, { scopedCampusIds: [seed().campuses.south.id] });
|
||||
await v2(page, "admin", "PATCH", `/api/v2/users/${seed().users[role].id}`, { scopedCampusIds: [seed().campuses.south.id] });
|
||||
}
|
||||
await page.close();
|
||||
});
|
||||
@@ -15,17 +15,17 @@ test.describe("campus-scoped staff", () => {
|
||||
test.afterAll(async ({ browser }) => {
|
||||
const page = await browser.newPage();
|
||||
for (const role of ["staff", "supervisor"] as const) {
|
||||
await api(page, "admin", "PUT", `/api/users/${seed().users[role].id}`, { scopedCampusIds: [] });
|
||||
await v2(page, "admin", "PATCH", `/api/v2/users/${seed().users[role].id}`, { scopedCampusIds: [] });
|
||||
}
|
||||
await api(page, "admin", "PUT", "/api/campuses/settings", { enabled: false });
|
||||
await v2(page, "admin", "PUT", "/api/v2/campuses/enabled", { enabled: false });
|
||||
await page.close();
|
||||
});
|
||||
|
||||
test("the scanner refuses another campus's ticket and says which campus", async ({ page }) => {
|
||||
const scan = (qr: string) => page.request.get(`${API}/api/tickets/scan-preview/${encodeURIComponent(qr)}`, { headers: { Authorization: `Bearer ${seed().users.staff.token}` } });
|
||||
const scan = (qr: string) => page.request.get(`${API}/api/v2/checkin/${encodeURIComponent(qr)}`, { headers: { Authorization: `Bearer ${seed().users.staff.token}` } });
|
||||
const north = await scan(seed().northTicketQr);
|
||||
expect(north.status()).toBe(403);
|
||||
expect((await north.json()).message).toBe("This ticket is for an event at E2E North.");
|
||||
expect((await north.json()).error.message).toBe("This ticket is for an event at E2E North.");
|
||||
// The course is for all campuses, so it scans.
|
||||
expect((await scan(seed().course.qrCode)).status()).toBe(200);
|
||||
});
|
||||
@@ -46,7 +46,7 @@ test.describe("campus-scoped staff", () => {
|
||||
});
|
||||
|
||||
test("another campus's registrations are not found for a scoped supervisor", async ({ page }) => {
|
||||
const res = await page.request.get(`${API}/api/registrations/event/${seed().events.free}`, { headers: { Authorization: `Bearer ${seed().users.supervisor.token}` } });
|
||||
const res = await page.request.get(`${API}/api/v2/events/${seed().events.free}/registrations`, { headers: { Authorization: `Bearer ${seed().users.supervisor.token}` } });
|
||||
expect(res.status()).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, api, API } from "./fixtures";
|
||||
import { test, expect, seed, api, API, v2 } from "./fixtures";
|
||||
|
||||
// Multi-campus. The campuses and the two events' campuses are seeded (e2e/support/prepare-db.js)
|
||||
// with campuses off; these tests turn them on, and off again afterwards so the other specs see a
|
||||
@@ -6,13 +6,13 @@ import { test, expect, seed, api, API } from "./fixtures";
|
||||
test.describe("campuses", () => {
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
const page = await browser.newPage();
|
||||
await api(page, "admin", "PUT", "/api/campuses/settings", { enabled: true });
|
||||
await v2(page, "admin", "PUT", "/api/v2/campuses/enabled", { enabled: true });
|
||||
await page.close();
|
||||
});
|
||||
|
||||
test.afterAll(async ({ browser }) => {
|
||||
const page = await browser.newPage();
|
||||
await api(page, "admin", "PUT", "/api/campuses/settings", { enabled: false });
|
||||
await v2(page, "admin", "PUT", "/api/v2/campuses/enabled", { enabled: false });
|
||||
await page.close();
|
||||
});
|
||||
|
||||
@@ -38,8 +38,8 @@ test.describe("campuses", () => {
|
||||
});
|
||||
|
||||
test("a campus with events can't be deleted", async ({ page }) => {
|
||||
const res = await page.request.delete(`${API}/api/campuses/${seed().campuses.north.id}`, { headers: { Authorization: `Bearer ${seed().users.admin.token}` } });
|
||||
const res = await page.request.delete(`${API}/api/v2/campuses/${seed().campuses.north.id}`, { headers: { Authorization: `Bearer ${seed().users.admin.token}` } });
|
||||
expect(res.status()).toBe(409);
|
||||
expect((await res.json()).code).toBe("CAMPUS_HAS_EVENTS");
|
||||
expect((await res.json()).error.reason).toBe("CAMPUS_HAS_EVENTS");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import AxeBuilder from "@axe-core/playwright";
|
||||
import { test, expect, loginAs, api } from "./fixtures";
|
||||
import { test, expect, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
// 1.50.2: event dropdowns are a searchable picker — upcoming events first, past ones a click
|
||||
// away, and typing searches them all.
|
||||
test.describe("event picker", () => {
|
||||
test("opens on upcoming events; past ones are behind a button or found by searching", async ({ page }) => {
|
||||
const start = new Date(Date.now() - 40 * 864e5);
|
||||
await api(page, "supervisor", "POST", "/api/events", {
|
||||
await v2(page, "supervisor", "POST", "/api/v2/events", {
|
||||
title: "E2E Picker Old Gathering", description: "A past event for the picker test.", price: 0, location: "1 Test Street, Pretoria",
|
||||
startDate: start.toISOString(), endDate: new Date(start.getTime() + 2 * 3600e3).toISOString(),
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ async function open(body: Buffer) {
|
||||
|
||||
test.describe("Excel exports", () => {
|
||||
test("a report with stats, a chart and a table", async ({ request }) => {
|
||||
const res = await request.post(`${API}/api/reports/excel`, {
|
||||
const res = await request.post(`${API}/api/v2/reports/excel`, {
|
||||
headers: { Authorization: `Bearer ${seed().users.supervisor.token}` },
|
||||
data: {
|
||||
title: "E2E Payments",
|
||||
@@ -36,7 +36,7 @@ test.describe("Excel exports", () => {
|
||||
});
|
||||
|
||||
test("the attendance register", async ({ request }) => {
|
||||
const res = await request.get(`${API}/api/attendance/${seed().events.course}/export?format=xlsx`, {
|
||||
const res = await request.get(`${API}/api/v2/events/${seed().events.course}/attendance/export?format=xlsx`, {
|
||||
headers: { Authorization: `Bearer ${seed().users.supervisor.token}` },
|
||||
});
|
||||
expect(res.status()).toBe(200);
|
||||
|
||||
@@ -52,6 +52,11 @@ export async function api<T = unknown>(page: Page, role: Role, method: string, u
|
||||
return (text ? JSON.parse(text) : null) as T;
|
||||
}
|
||||
|
||||
/** Calls `/api/v2` as a seeded user and returns the answer's `data` (throws on an error, like `api`). */
|
||||
export async function v2<T = unknown>(page: Page, role: Role, method: string, url: string, body?: unknown): Promise<T> {
|
||||
return (await api<{ data: T }>(page, role, method, url, body)).data;
|
||||
}
|
||||
|
||||
/** Chooses an event in an EventPicker (the first on the page, or the one labelled `label`) by searching its title. */
|
||||
export async function pickEvent(page: Page, title: string, label?: string) {
|
||||
const button = label ? page.getByRole("button", { name: new RegExp(`^${label}:`) }) : page.getByTestId("event-picker").first().getByRole("button").first();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { test, expect, seed, loginAs, api } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
// 1.50.1: long lists load a page (or just what's needed) at a time, with search and filters.
|
||||
test.describe("long lists", () => {
|
||||
test("Payments: today, recent and a person's payments for a refund", async ({ page }) => {
|
||||
// A donation recorded today for the seeded user (on an event no other test totals up).
|
||||
await api(page, "supervisor", "POST", "/api/payments", {
|
||||
await v2(page, "supervisor", "POST", "/api/v2/payments", {
|
||||
amount: 77, method: "cash", isDonation: true, eventId: seed().events.conference, userId: seed().users.user.id,
|
||||
});
|
||||
|
||||
@@ -21,11 +21,11 @@ test.describe("long lists", () => {
|
||||
|
||||
test("Payments API: narrowing filters", async ({ page }) => {
|
||||
const userId = seed().users.user.id;
|
||||
const mine = await api<{ data: { userId: string }[] }>(page, "supervisor", "GET", `/api/payments?userId=${userId}&limit=200`);
|
||||
const mine = await v2<{ data: { userId: string }[] }>(page, "supervisor", "GET", `/api/v2/payments?userId=${userId}&limit=200`);
|
||||
expect(mine.data.length).toBeGreaterThan(0);
|
||||
expect(mine.data.every((p) => p.userId === userId)).toBe(true);
|
||||
|
||||
const unpaid = await api<{ status: string }[]>(page, "supervisor", "GET", "/api/registrations?unpaid=1");
|
||||
const unpaid = await v2<{ status: string }[]>(page, "supervisor", "GET", "/api/v2/registrations?unpaid=true");
|
||||
expect(unpaid.every((r) => ["pending", "confirmed", "partial_paid"].includes(r.status))).toBe(true);
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ test.describe("long lists", () => {
|
||||
});
|
||||
|
||||
test("Data requests: search", async ({ page }) => {
|
||||
const res = await api<{ requests: unknown[]; total: number }>(page, "admin", "GET", "/api/privacy/requests?status=closed&search=nobody-matches-this-xyz");
|
||||
const res = await v2<{ requests: unknown[]; total: number }>(page, "admin", "GET", "/api/v2/privacy/requests?status=closed&search=nobody-matches-this-xyz");
|
||||
expect(res.requests).toEqual([]);
|
||||
expect(res.total).toBe(0);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
// Pays into a real PayFast sandbox account, so it needs one:
|
||||
// E2E_PAYFAST_MERCHANT_ID, E2E_PAYFAST_MERCHANT_KEY, E2E_PAYFAST_PASSPHRASE
|
||||
@@ -17,17 +17,17 @@ test.describe("PayFast", () => {
|
||||
test.skip(!PF.merchantId, "Set E2E_PAYFAST_* to test against a PayFast sandbox account");
|
||||
|
||||
test("choose PayFast on the pay page and land on PayFast's payment page", async ({ page }) => {
|
||||
await api(page, "admin", "PUT", "/api/payfast/config", { ...PF, mode: "sandbox" });
|
||||
await v2(page, "admin", "PUT", "/api/v2/payments/payfast/config", { ...PF, mode: "sandbox" });
|
||||
try {
|
||||
await api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }, { id: "payfast", enabled: true }] });
|
||||
await v2(page, "admin", "PUT", "/api/v2/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }, { id: "payfast", enabled: true }] });
|
||||
|
||||
// A booking for the paid conference, then an online checkout for it
|
||||
const event = await api<EventWithOptions>(page, "staff", "GET", `/api/events/${seed().events.paid}`);
|
||||
const event = await v2<EventWithOptions>(page, "staff", "GET", `/api/v2/events/${seed().events.paid}/full`);
|
||||
const option = event.eventOptions.find((o) => o.isMainTicket)!;
|
||||
const reg = await api<Registration>(page, "staff", "POST", "/api/registrations", { eventId: seed().events.paid, options: [{ eventOptionId: option.id, quantity: 1 }] });
|
||||
const reg = await v2<Registration>(page, "staff", "POST", "/api/v2/registrations", { eventId: seed().events.paid, options: [{ eventOptionId: option.id, quantity: 1 }] });
|
||||
const origin = new URL(page.url() === "about:blank" ? "http://localhost:3100" : page.url()).origin;
|
||||
const checkout = await api<Checkout>(page, "staff", "POST", "/api/payments/checkout", {
|
||||
registrationId: reg.id, successUrl: `${origin}/payment/success`, cancelUrl: `${origin}/payment/cancel`, failureUrl: `${origin}/payment/failure`,
|
||||
const checkout = await v2<Checkout>(page, "staff", "POST", `/api/v2/registrations/${reg.id}/checkout`, {
|
||||
successUrl: `${origin}/payment/success`, cancelUrl: `${origin}/payment/cancel`, failureUrl: `${origin}/payment/failure`,
|
||||
});
|
||||
// Yoco and PayFast are both on, so the payer chooses
|
||||
expect(checkout.provider).toBeNull();
|
||||
@@ -53,8 +53,8 @@ test.describe("PayFast", () => {
|
||||
await expect(row.getByText("Not paid (yet)")).toBeVisible({ timeout: 30_000 });
|
||||
await expect(page.getByText("No new payments found.")).toBeVisible();
|
||||
} finally {
|
||||
await api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }, { id: "payfast", enabled: false }] });
|
||||
await api(page, "admin", "PUT", "/api/payfast/config", { merchantId: "", merchantKey: "", passphrase: "" });
|
||||
await v2(page, "admin", "PUT", "/api/v2/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }, { id: "payfast", enabled: false }] });
|
||||
await v2(page, "admin", "PUT", "/api/v2/payments/payfast/config", { merchantId: "", merchantKey: "", passphrase: "" });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
type ProviderSetting = { id: string; label: string; enabled: boolean; configured: boolean };
|
||||
|
||||
@@ -20,28 +20,28 @@ test.describe("payment providers", () => {
|
||||
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");
|
||||
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 api<{ providers: ProviderSetting[] }>(page, "admin", "GET", "/api/payments/providers/settings");
|
||||
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 api(page, "admin", "PUT", "/api/payments/providers/settings", { providers: [{ id: "yoco", enabled: true }] });
|
||||
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 api<EventWithOptions>(page, "admin", "GET", `/api/events/${seed().events.paid}`);
|
||||
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 api<{ id: string }>(page, "admin", "POST", "/api/registrations", { eventId: seed().events.paid, options: [{ eventOptionId: option.id, quantity: 1 }] });
|
||||
const reg = await v2<{ id: string }>(page, "admin", "POST", "/api/v2/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 }] });
|
||||
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}`);
|
||||
@@ -53,11 +53,11 @@ test.describe("payment providers", () => {
|
||||
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 }] });
|
||||
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 api<{ providers: unknown[] }>(page, "admin", "GET", "/api/payments/providers");
|
||||
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();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api, pickEvent } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, pickEvent, v2 } from "./fixtures";
|
||||
|
||||
type Registration = { id: string; eventId: string; user?: { name: string }; registrationOptions: { sessionId?: string | null; sessionIds?: string[]; priceSnapshot: number; quantity: number }[] };
|
||||
type WaitlistEntry = { eventId: string; sessionId: string | null; quantity: number };
|
||||
@@ -20,7 +20,7 @@ test.describe("pick sessions", () => {
|
||||
await page.getByRole("button", { name: "Register", exact: true }).click();
|
||||
await page.waitForURL(/\/registration\/success/);
|
||||
|
||||
const regs = await api<Registration[]>(page, "user", "GET", "/api/registrations/myregistrations");
|
||||
const regs = await v2<Registration[]>(page, "user", "GET", "/api/v2/me/registrations/full");
|
||||
const reg = regs.find((r) => r.eventId === seed().events.dropIn);
|
||||
expect(reg?.registrationOptions.filter((o) => o.sessionId)).toHaveLength(2);
|
||||
});
|
||||
@@ -39,7 +39,7 @@ test.describe("pick sessions", () => {
|
||||
await page.getByRole("button", { name: "Register", exact: true }).click();
|
||||
await page.waitForURL(/\/registration\/success/);
|
||||
|
||||
const regs = await api<Registration[]>(page, "user", "GET", "/api/registrations/myregistrations");
|
||||
const regs = await v2<Registration[]>(page, "user", "GET", "/api/v2/me/registrations/full");
|
||||
const line = regs.find((r) => r.eventId === seed().events.conference)?.registrationOptions[0];
|
||||
expect(line?.sessionId ?? null).toBeNull();
|
||||
expect(line?.sessionIds).toHaveLength(2);
|
||||
@@ -58,7 +58,7 @@ test.describe("pick sessions", () => {
|
||||
await page.locator("form").filter({ hasText: "Join the waitlist" }).getByRole("button", { name: "Join waitlist" }).click();
|
||||
await expect(page.getByText(/You're on the waitlist/)).toBeVisible();
|
||||
|
||||
const mine = await api<WaitlistEntry[]>(page, "admin", "GET", "/api/waitlist/mine");
|
||||
const mine = await v2<WaitlistEntry[]>(page, "admin", "GET", "/api/v2/me/waitlist");
|
||||
const entry = mine.find((e) => e.eventId === seed().events.dropIn);
|
||||
expect(entry?.sessionId).toBeTruthy();
|
||||
expect(entry?.quantity).toBe(1);
|
||||
@@ -86,7 +86,7 @@ test.describe("pick sessions", () => {
|
||||
await page.getByRole("button", { name: "Confirm Registration" }).click();
|
||||
await expect(page.getByText("Select Items")).toBeHidden();
|
||||
|
||||
const regs = await api<Registration[]>(page, "supervisor", "GET", `/api/registrations/event/${seed().events.dropIn}`);
|
||||
const regs = await v2<Registration[]>(page, "supervisor", "GET", `/api/v2/events/${seed().events.dropIn}/registrations`);
|
||||
const reg = regs.find((r) => r.user?.name === "Door Walk In");
|
||||
expect(reg?.registrationOptions.filter((o) => o.sessionId)).toHaveLength(1);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api, API, type Role } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, API, type Role, v2 } from "./fixtures";
|
||||
|
||||
type Section = { id: string; title: string; body: string };
|
||||
type Draft = { sections: Section[]; versions: { version: number; acceptances: number }[] };
|
||||
@@ -13,12 +13,12 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
test.afterAll(async ({ request }) => {
|
||||
const tokens = [...(["admin", "supervisor", "staff", "user"] as Role[]).map(r => seed().users[r].token), seed().newsPromptUser.token, seed().noticeFirstUser.token];
|
||||
for (const token of tokens) {
|
||||
await request.post(`${API}/api/privacy/me/notice/accept`, { headers: { Authorization: `Bearer ${token}` } });
|
||||
await request.post(`${API}/api/v2/me/privacy/notice/accept`, { headers: { Authorization: `Bearer ${token}` } });
|
||||
}
|
||||
});
|
||||
|
||||
test("the built-in notice is shown until a version is published, with the operator register filled in", async ({ page }) => {
|
||||
const notice = await (await page.request.get(`${API}/api/privacy/notice`)).json() as Notice;
|
||||
const notice = await (await (await page.request.get(`${API}/api/v2/privacy/notice`)).json()).data as Notice;
|
||||
expect(notice.version).toBe(0);
|
||||
expect(notice.sections.find(s => s.id === "sharing")?.body).toContain("• PayFast (South Africa)");
|
||||
|
||||
@@ -29,7 +29,7 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
|
||||
test("an admin edits and publishes; operators feed the notice", async ({ page }) => {
|
||||
// A new operator appears in the notice's {operators} list.
|
||||
const op = await api<Operator>(page, "admin", "POST", "/api/privacy/operators", { name: "E2E Mailer", purpose: "Sending emails", dataShared: "Email address", location: "Ireland" });
|
||||
const op = await v2<Operator>(page, "admin", "POST", "/api/v2/privacy/operators", { name: "E2E Mailer", purpose: "Sending emails", dataShared: "Email address", location: "Ireland" });
|
||||
|
||||
await loginAs(page, "admin");
|
||||
await page.goto("/dashboard/admin/privacy?tab=notice");
|
||||
@@ -40,7 +40,7 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
await expect(page.getByText("Draft saved.")).toBeVisible();
|
||||
|
||||
// Nothing public changes until it's published.
|
||||
expect(((await (await page.request.get(`${API}/api/privacy/notice`)).json()) as Notice).version).toBe(0);
|
||||
expect(((await (await page.request.get(`${API}/api/v2/privacy/notice`)).json()).data as Notice).version).toBe(0);
|
||||
|
||||
await page.getByRole("button", { name: "Publish…" }).click();
|
||||
await page.getByPlaceholder("e.g. We now use PayFast for online payments.").fill("Clearer introduction.");
|
||||
@@ -52,15 +52,15 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
await expect(page.getByText("• E2E Mailer (Ireland) — Sending emails.", { exact: false })).toBeVisible();
|
||||
await expect(page.getByText(/Version 1/).first()).toBeVisible();
|
||||
|
||||
await api(page, "admin", "DELETE", `/api/privacy/operators/${op.id}`);
|
||||
await v2(page, "admin", "DELETE", `/api/v2/privacy/operators/${op.id}`);
|
||||
});
|
||||
|
||||
test("after publishing its own version, the editor points out new built-in text", async ({ page }) => {
|
||||
// The published version came from the built-in text; put an older wording back in one changed
|
||||
// section so it shows as having new text.
|
||||
const draft = await api<Draft>(page, "admin", "GET", "/api/privacy/notice/draft");
|
||||
const draft = await v2<Draft>(page, "admin", "GET", "/api/v2/privacy/notice/draft");
|
||||
const sections = draft.sections.map(s => (s.id === "changes" ? { ...s, body: "We may update this notice from time to time." } : s));
|
||||
await api(page, "admin", "PUT", "/api/privacy/notice/draft", { sections });
|
||||
await v2(page, "admin", "PUT", "/api/v2/privacy/notice/draft", { sections });
|
||||
|
||||
await loginAs(page, "admin");
|
||||
await page.goto("/dashboard/admin/privacy?tab=notice");
|
||||
@@ -80,7 +80,7 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
await page.reload();
|
||||
await expect(page.getByLabel("1. Introduction text")).toBeVisible();
|
||||
await expect(page.getByTestId("builtin-updates")).toHaveCount(0);
|
||||
await api(page, "admin", "DELETE", "/api/privacy/notice/draft");
|
||||
await v2(page, "admin", "DELETE", "/api/v2/privacy/notice/draft");
|
||||
});
|
||||
|
||||
test("someone who never accepted the notice is asked once, after login", async ({ page }) => {
|
||||
@@ -102,10 +102,10 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
});
|
||||
|
||||
test("a significant change is accepted once, after login", async ({ page }) => {
|
||||
const draft = await api<Draft>(page, "admin", "GET", "/api/privacy/notice/draft");
|
||||
const draft = await v2<Draft>(page, "admin", "GET", "/api/v2/privacy/notice/draft");
|
||||
// Re-acceptance needs a summary of what changed.
|
||||
await expect(api(page, "admin", "POST", "/api/privacy/notice/publish", { sections: draft.sections, requiresAcceptance: true })).rejects.toThrow(/400/);
|
||||
const published = await api<{ version: number }>(page, "admin", "POST", "/api/privacy/notice/publish", { sections: draft.sections, requiresAcceptance: true, changeSummary: "We added WhatsApp news." });
|
||||
await expect(v2(page, "admin", "POST", "/api/v2/privacy/notice/publish", { sections: draft.sections, requiresAcceptance: true })).rejects.toThrow(/400/);
|
||||
const published = await v2<{ version: number }>(page, "admin", "POST", "/api/v2/privacy/notice/publish", { sections: draft.sections, requiresAcceptance: true, changeSummary: "We added WhatsApp news." });
|
||||
|
||||
await loginAs(page, "user");
|
||||
await page.goto("/dashboard/user");
|
||||
@@ -118,19 +118,19 @@ test.describe("privacy notice, operators and access log (POPIA)", () => {
|
||||
await expect(page.getByText("My Events").first()).toBeVisible();
|
||||
await expect(page.getByRole("dialog", { name: "We've updated our privacy notice" })).toHaveCount(0);
|
||||
|
||||
const log = await api<ConsentLog>(page, "admin", "GET", `/api/privacy/consent-log?type=notice&q=${encodeURIComponent(seed().users.user.email)}`);
|
||||
const log = await v2<ConsentLog>(page, "admin", "GET", `/api/v2/privacy/consent-log?type=notice&q=${encodeURIComponent(seed().users.user.email)}`);
|
||||
expect(log.rows[0]).toMatchObject({ version: published.version, source: "prompt" });
|
||||
});
|
||||
|
||||
test("bulk exports are in the access log", async ({ page }) => {
|
||||
const res = await page.request.post(`${API}/api/reports/pdf`, {
|
||||
const res = await page.request.post(`${API}/api/v2/reports/pdf`, {
|
||||
headers: { Authorization: `Bearer ${seed().users.supervisor.token}`, "Content-Type": "application/json" },
|
||||
data: JSON.stringify({ title: "E2E attendee list", kind: "table", table: { columns: ["Name"], rows: [["A"], ["B"], ["C"]] } }),
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
await api(page, "supervisor", "GET", `/api/consent/events/${seed().events.free}`);
|
||||
await v2(page, "supervisor", "GET", `/api/v2/events/${seed().events.free}/consent`);
|
||||
|
||||
const log = await api<AccessLog>(page, "admin", "GET", "/api/privacy/access-log");
|
||||
const log = await v2<AccessLog>(page, "admin", "GET", "/api/v2/privacy/access-log");
|
||||
expect(log.rows.find(r => r.action === "report_pdf")).toMatchObject({ what: "E2E attendee list", records: 3, actor: "Sam Supervisor" });
|
||||
expect(log.rows.some(r => r.action === "consent_list")).toBe(true);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
type RunResult = { result: Record<string, Record<string, number>> };
|
||||
type UserRow = { name: string; email: string; isActive: boolean };
|
||||
@@ -7,32 +7,32 @@ type Breach = { id: string; status: string; regulatorNotifiedAt: string | null }
|
||||
|
||||
test.describe("retention, breaches and readiness (POPIA)", () => {
|
||||
test("the retention job warns inactive accounts first, and anonymises them 30 days after the warning", async ({ page }) => {
|
||||
const { result } = await api<RunResult>(page, "admin", "POST", "/api/privacy/retention/run");
|
||||
const { result } = await v2<RunResult>(page, "admin", "POST", "/api/v2/privacy/retention/run");
|
||||
expect(result.inactive_accounts.warned).toBeGreaterThanOrEqual(1);
|
||||
expect(result.inactive_accounts.anonymised).toBeGreaterThanOrEqual(1);
|
||||
expect(result.login_history.deleted).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const warned = await api<UserRow>(page, "admin", "GET", `/api/users/${seed().retention.toWarn}`);
|
||||
const warned = await v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().retention.toWarn}`);
|
||||
expect(warned.email).toBe("dormant@e2e.test");
|
||||
const gone = await api<UserRow>(page, "admin", "GET", `/api/users/${seed().retention.toAnonymise}`);
|
||||
const gone = await v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().retention.toAnonymise}`);
|
||||
expect(gone.name).toBe("Deleted User");
|
||||
expect(gone.email).toMatch(/@deleted\.invalid$/);
|
||||
|
||||
// Seeded accounts (staff roles, and the recently active user) are untouched.
|
||||
expect((await api<UserRow>(page, "admin", "GET", `/api/users/${seed().users.user.id}`)).email).toBe("user@e2e.test");
|
||||
expect((await v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().users.user.id}`)).email).toBe("user@e2e.test");
|
||||
});
|
||||
|
||||
test("retention periods are validated and saved; the notice follows them", async ({ page }) => {
|
||||
const state = await api<{ policies: Record<string, { enabled: boolean; months: number }> }>(page, "admin", "GET", "/api/privacy/retention");
|
||||
await expect(api(page, "admin", "PUT", "/api/privacy/retention", { policies: { ...state.policies, inactive_accounts: { enabled: true, months: 3 } } })).rejects.toThrow(/400/);
|
||||
await api(page, "admin", "PUT", "/api/privacy/retention", { policies: { ...state.policies, form_answers: { enabled: true, months: 18 } } });
|
||||
const state = await v2<{ policies: Record<string, { enabled: boolean; months: number }> }>(page, "admin", "GET", "/api/v2/privacy/retention");
|
||||
await expect(v2(page, "admin", "PUT", "/api/v2/privacy/retention", { policies: { ...state.policies, inactive_accounts: { enabled: true, months: 3 } } })).rejects.toThrow(/400/);
|
||||
await v2(page, "admin", "PUT", "/api/v2/privacy/retention", { policies: { ...state.policies, form_answers: { enabled: true, months: 18 } } });
|
||||
|
||||
await page.goto("/legal/privacy");
|
||||
await expect(page.getByText("Answers to event forms are deleted 18 months after the event.", { exact: false })).toBeVisible();
|
||||
});
|
||||
|
||||
test("a breach is recorded, reported, and drafts are ready to copy", async ({ page }) => {
|
||||
const breach = await api<Breach>(page, "admin", "POST", "/api/privacy/breaches", {
|
||||
const breach = await v2<Breach>(page, "admin", "POST", "/api/v2/privacy/breaches", {
|
||||
title: "Phone with the attendee list lost", discoveredAt: new Date().toISOString(),
|
||||
description: "A leader's phone was stolen at the camp site.", dataAffected: "Names and phone numbers of 40 campers",
|
||||
});
|
||||
@@ -46,12 +46,12 @@ test.describe("retention, breaches and readiness (POPIA)", () => {
|
||||
await page.getByRole("button", { name: "Regulator told today" }).click();
|
||||
await expect(page.getByRole("button", { name: "Regulator told today" })).toHaveCount(0);
|
||||
|
||||
const list = await api<Breach[]>(page, "admin", "GET", "/api/privacy/breaches");
|
||||
const list = await v2<Breach[]>(page, "admin", "GET", "/api/v2/privacy/breaches");
|
||||
expect(list.find(b => b.id === breach.id)?.regulatorNotifiedAt).toBeTruthy();
|
||||
});
|
||||
|
||||
test("the readiness page scores the install", async ({ page }) => {
|
||||
const r = await api<Readiness>(page, "admin", "GET", "/api/privacy/readiness");
|
||||
const r = await v2<Readiness>(page, "admin", "GET", "/api/v2/privacy/readiness");
|
||||
expect(r.score).toBeGreaterThan(0);
|
||||
expect(r.checks.find(c => c.key === "retention_reviewed")?.ok).toBe(true);
|
||||
expect(r.checks.find(c => c.key === "retention_running")?.ok).toBe(false); // jobs are off in e2e
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import { test, expect, seed, loginAs, api, API } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, API, v2 } from "./fixtures";
|
||||
|
||||
type Account = { id: string; token: string; email: string };
|
||||
type PrivacyInfo = { news: { email: boolean; whatsapp: boolean }; history: { source: string }[]; requests: { type: string; status: string }[] };
|
||||
@@ -9,12 +9,12 @@ type Requests = { requests: { id: string; type: string; userId: string; blockers
|
||||
/** A brand-new account made through sign-up, so tests can change it freely. */
|
||||
async function signUp(page: Page, newsOptIn: boolean): Promise<Account> {
|
||||
const email = `privacy-${Date.now()}-${Math.floor(Math.random() * 1e6)}@e2e.test`;
|
||||
const res = await page.request.post(`${API}/api/users`, {
|
||||
data: { name: "Pat Privacy", email, password: "E2e-password-123", newsOptIn },
|
||||
const res = await page.request.post(`${API}/api/v2/auth/signup`, {
|
||||
data: { name: "Pat Privacy", email, password: "E2e-password-123", newsOptIn, acceptTerms: true },
|
||||
});
|
||||
expect(res.ok()).toBe(true);
|
||||
const body = await res.json();
|
||||
return { id: body.id, token: body.token, email };
|
||||
const { data } = await res.json();
|
||||
return { id: data.user.id, token: data.token, email };
|
||||
}
|
||||
|
||||
async function asAccount<T>(page: Page, account: Account, method: string, url: string, body?: unknown) {
|
||||
@@ -23,13 +23,15 @@ async function asAccount<T>(page: Page, account: Account, method: string, url: s
|
||||
headers: { Authorization: `Bearer ${account.token}`, "Content-Type": "application/json" },
|
||||
data: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
return { status: res.status(), body: (await res.json().catch(() => null)) as T };
|
||||
// v2 answers { data }; a download (my data) is the file itself.
|
||||
const json = await res.json().catch(() => null);
|
||||
return { status: res.status(), body: (json && typeof json === "object" && "data" in json ? json.data : json) as T };
|
||||
}
|
||||
|
||||
test.describe("privacy (POPIA)", () => {
|
||||
test("sign-up records the news choice; the privacy page changes it and downloads my data", async ({ page }) => {
|
||||
const me = await signUp(page, false);
|
||||
const before = await asAccount<PrivacyInfo>(page, me, "GET", "/api/privacy/me");
|
||||
const before = await asAccount<PrivacyInfo>(page, me, "GET", "/api/v2/me/privacy");
|
||||
expect(before.body.news.email).toBe(false);
|
||||
expect(before.body.history.map((h) => h.source)).toContain("signup");
|
||||
|
||||
@@ -41,7 +43,7 @@ test.describe("privacy (POPIA)", () => {
|
||||
await expect(page.getByText("You're subscribed.")).toBeVisible();
|
||||
await expect(byEmail).toBeChecked();
|
||||
|
||||
const exported = await asAccount<{ account: { email: string }; communication: { news: { email: boolean } } }>(page, me, "GET", "/api/privacy/me/export");
|
||||
const exported = await asAccount<{ account: { email: string }; communication: { news: { email: boolean } } }>(page, me, "GET", "/api/v2/me/privacy/export");
|
||||
expect(exported.status).toBe(200);
|
||||
expect(exported.body.account.email).toBe(me.email);
|
||||
expect(exported.body.communication.news.email).toBe(true);
|
||||
@@ -49,10 +51,10 @@ test.describe("privacy (POPIA)", () => {
|
||||
|
||||
test("news broadcasts skip people who aren't opted in; event updates don't", async ({ page }) => {
|
||||
const out = await signUp(page, false);
|
||||
const news = await api<Preview>(page, "supervisor", "POST", "/api/broadcasts/preview", { userIds: [out.id, seed().users.admin.id], emails: "", kind: "news" });
|
||||
const news = await v2<Preview>(page, "supervisor", "POST", "/api/v2/broadcasts/email/preview", { userIds: [out.id, seed().users.admin.id], emails: "", kind: "news" });
|
||||
expect(news.matched).toBe(1);
|
||||
expect(news.skipped).toBe(1);
|
||||
const update = await api<Preview>(page, "supervisor", "POST", "/api/broadcasts/preview", { userIds: [out.id, seed().users.admin.id], emails: "", kind: "update" });
|
||||
const update = await v2<Preview>(page, "supervisor", "POST", "/api/v2/broadcasts/email/preview", { userIds: [out.id, seed().users.admin.id], emails: "", kind: "update" });
|
||||
expect(update.matched).toBe(2);
|
||||
expect(update.skipped).toBe(0);
|
||||
});
|
||||
@@ -61,11 +63,11 @@ test.describe("privacy (POPIA)", () => {
|
||||
await page.goto(`/unsubscribe?t=${encodeURIComponent(seed().unsubscribeToken)}`);
|
||||
await page.getByRole("button", { name: "Unsubscribe from all news" }).click();
|
||||
await expect(page.getByText(/You're unsubscribed from news and announcements/)).toBeVisible();
|
||||
const after = await api<PrivacyInfo>(page, "user", "GET", "/api/privacy/me");
|
||||
const after = await v2<PrivacyInfo>(page, "user", "GET", "/api/v2/me/privacy");
|
||||
expect(after.news).toEqual({ email: false, whatsapp: false });
|
||||
expect(after.history.some((h) => h.source === "unsubscribe_link")).toBe(true);
|
||||
|
||||
const bad = await page.request.get(`${API}/api/privacy/unsubscribe/not-a-real-token`);
|
||||
const bad = await page.request.get(`${API}/api/v2/unsubscribe/not-a-real-token`);
|
||||
expect(bad.status()).toBe(404);
|
||||
});
|
||||
|
||||
@@ -84,17 +86,17 @@ test.describe("privacy (POPIA)", () => {
|
||||
|
||||
test("delete my account: closed at once, anonymised when an admin completes the request", async ({ page }) => {
|
||||
const me = await signUp(page, true);
|
||||
const wrong = await asAccount(page, me, "POST", "/api/privacy/me/requests", { type: "deletion", password: "nope" });
|
||||
const wrong = await asAccount(page, me, "POST", "/api/v2/me/privacy/requests", { type: "deletion", password: "nope" });
|
||||
expect(wrong.status).toBe(400);
|
||||
const made = await asAccount(page, me, "POST", "/api/privacy/me/requests", { type: "deletion", password: "E2e-password-123" });
|
||||
const made = await asAccount(page, me, "POST", "/api/v2/me/privacy/requests", { type: "deletion", password: "E2e-password-123" });
|
||||
expect(made.status).toBe(201);
|
||||
|
||||
// The account is closed: the old session no longer works, and logging in is refused.
|
||||
expect((await asAccount(page, me, "GET", "/api/privacy/me")).status).toBe(401);
|
||||
const login = await page.request.post(`${API}/api/users/login`, { data: { email: me.email, password: "E2e-password-123" } });
|
||||
expect((await asAccount(page, me, "GET", "/api/v2/me/privacy")).status).toBe(401);
|
||||
const login = await page.request.post(`${API}/api/v2/auth/login`, { data: { identifier: me.email, password: "E2e-password-123" } });
|
||||
expect(login.ok()).toBe(false);
|
||||
|
||||
const inbox = await api<Requests>(page, "admin", "GET", "/api/privacy/requests?status=open");
|
||||
const inbox = await v2<Requests>(page, "admin", "GET", "/api/v2/privacy/requests?status=open");
|
||||
const request = inbox.requests.find((r) => r.userId === me.id);
|
||||
expect(request?.type).toBe("deletion");
|
||||
expect(request?.blockers).toEqual([]);
|
||||
@@ -103,8 +105,8 @@ test.describe("privacy (POPIA)", () => {
|
||||
await loginAs(page, "admin");
|
||||
await page.goto("/dashboard/admin/data-requests");
|
||||
await expect(page.getByText(me.email)).toBeVisible();
|
||||
await api(page, "admin", "POST", `/api/privacy/requests/${request!.id}/complete`, {});
|
||||
const user = await api<{ name: string; email: string }>(page, "admin", "GET", `/api/users/${me.id}`);
|
||||
await v2(page, "admin", "POST", `/api/v2/privacy/requests/${request!.id}/complete`, {});
|
||||
const user = await v2<{ name: string; email: string }>(page, "admin", "GET", `/api/v2/users/${me.id}`);
|
||||
expect(user.name).toBe("Deleted User");
|
||||
expect(user.email).toMatch(/@deleted\.invalid$/);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
type Registration = { id: string; status: string; eventId: string };
|
||||
type Ticket = { id: string; qrCode: string; eventId: string };
|
||||
@@ -14,7 +14,7 @@ test.describe("registration → payment → ticket → check-in → cashup", ()
|
||||
await page.getByRole("button", { name: "Register", exact: true }).click();
|
||||
await page.waitForURL(/\/registration\/success/);
|
||||
|
||||
const tickets = await api<Ticket[]>(page, "user", "GET", "/api/tickets/mytickets");
|
||||
const tickets = await v2<Ticket[]>(page, "user", "GET", "/api/v2/me/tickets");
|
||||
expect(tickets.some((t) => t.eventId === seed().events.free)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -26,14 +26,14 @@ test.describe("registration → payment → ticket → check-in → cashup", ()
|
||||
await page.getByRole("button", { name: "Register", exact: true }).click();
|
||||
await page.waitForURL(/\/registration\/success/);
|
||||
|
||||
const regs = await api<Registration[]>(page, "user", "GET", "/api/registrations/myregistrations");
|
||||
const regs = await v2<Registration[]>(page, "user", "GET", "/api/v2/me/registrations/full");
|
||||
const reg = regs.find((r) => r.eventId === seed().events.paid);
|
||||
expect(reg?.status).not.toBe("paid");
|
||||
expect((await api<Ticket[]>(page, "user", "GET", "/api/tickets/mytickets")).some((t) => t.eventId === seed().events.paid)).toBe(false);
|
||||
expect((await v2<Ticket[]>(page, "user", "GET", "/api/v2/me/tickets")).some((t) => t.eventId === seed().events.paid)).toBe(false);
|
||||
|
||||
// A supervisor records the cash payment at the desk.
|
||||
await api(page, "supervisor", "POST", "/api/payments", { amount: 150, method: "cash", registrationId: reg!.id, eventId: seed().events.paid, userId: seed().users.user.id });
|
||||
const ticket = (await api<Ticket[]>(page, "user", "GET", "/api/tickets/mytickets")).find((t) => t.eventId === seed().events.paid);
|
||||
await v2(page, "supervisor", "POST", "/api/v2/payments", { amount: 150, method: "cash", registrationId: reg!.id, eventId: seed().events.paid, userId: seed().users.user.id });
|
||||
const ticket = (await v2<Ticket[]>(page, "user", "GET", "/api/v2/me/tickets")).find((t) => t.eventId === seed().events.paid);
|
||||
expect(ticket).toBeTruthy();
|
||||
|
||||
// My Events shows it.
|
||||
@@ -41,11 +41,11 @@ test.describe("registration → payment → ticket → check-in → cashup", ()
|
||||
await expect(page.getByText("E2E Paid Conference").first()).toBeVisible();
|
||||
|
||||
// Staff check it in; a second scan is refused.
|
||||
await api(page, "staff", "POST", `/api/tickets/scan/${ticket!.qrCode}`, { qty: 1 });
|
||||
await expect(api(page, "staff", "POST", `/api/tickets/scan/${ticket!.qrCode}`, { qty: 1 })).rejects.toThrow(/403.*fully used/);
|
||||
expect((await v2<{ outcome: string }>(page, "staff", "POST", `/api/v2/checkin/${ticket!.qrCode}`, { people: 1 })).outcome).toBe("checked_in");
|
||||
expect(await v2(page, "staff", "POST", `/api/v2/checkin/${ticket!.qrCode}`, { people: 1 })).toMatchObject({ outcome: "already_used", message: expect.stringMatching(/fully used/) });
|
||||
|
||||
// Cashup: the R150 cash is on the supervisor who took it.
|
||||
const cash = await api<CashByUser>(page, "supervisor", "GET", `/api/cashups/event/${seed().events.paid}/cash-by-user`);
|
||||
const cash = await v2<CashByUser>(page, "supervisor", "GET", `/api/v2/events/${seed().events.paid}/cashup/cash-by-user`);
|
||||
const mine = cash.rows.find((r) => r.userId === seed().users.supervisor.id);
|
||||
expect(mine?.cash.total).toBe(150);
|
||||
expect(mine?.cash.count).toBe(1);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, loginAs, api, seed, API } from "./fixtures";
|
||||
import { test, expect, loginAs, api, seed, API, v2 } from "./fixtures";
|
||||
|
||||
// Event series (1.47.1): a supervisor makes a series, events join it, the public series page
|
||||
// lists them, an event page links to the next one, a user follows it, and the series job tells
|
||||
@@ -28,12 +28,12 @@ test.describe.serial("event series", () => {
|
||||
await expect(page.getByRole("status")).toContainText("E2E Breakfast");
|
||||
await expect(page.getByTestId("series-row").filter({ hasText: "E2E Breakfast" })).toContainText("/series/e2e-breakfast");
|
||||
|
||||
const all = await api<Series[]>(page, "supervisor", "GET", "/api/series");
|
||||
const all = await v2<Series[]>(page, "supervisor", "GET", "/api/v2/series");
|
||||
series = all.find((s) => s.name === "E2E Breakfast")!;
|
||||
past = await api<Created>(page, "supervisor", "POST", "/api/events", event("E2E Breakfast (last month)", -30, series.id));
|
||||
next = await api<Created>(page, "supervisor", "POST", "/api/events", event("E2E Breakfast (next month)", 30, series.id));
|
||||
past = await v2<Created>(page, "supervisor", "POST", "/api/v2/events", event("E2E Breakfast (last month)", -30, series.id));
|
||||
next = await v2<Created>(page, "supervisor", "POST", "/api/v2/events", event("E2E Breakfast (next month)", 30, series.id));
|
||||
// Both are live already; announce them now so only the event made after following counts below.
|
||||
await api<JobRun>(page, "admin", "POST", "/api/admin/jobs/series/run");
|
||||
await v2<JobRun>(page, "admin", "POST", "/api/v2/admin/jobs/series/run");
|
||||
});
|
||||
|
||||
test("the series page lists what's coming up and what's past", async ({ page }) => {
|
||||
@@ -56,10 +56,10 @@ test.describe.serial("event series", () => {
|
||||
await page.getByRole("button", { name: "Follow this series" }).click();
|
||||
await expect(page.getByRole("button", { name: "Unfollow" })).toBeVisible();
|
||||
|
||||
await api<Created>(page, "supervisor", "POST", "/api/events", event("E2E Breakfast (in two months)", 60, series.id));
|
||||
const first = await api<JobRun>(page, "admin", "POST", "/api/admin/jobs/series/run");
|
||||
await v2<Created>(page, "supervisor", "POST", "/api/v2/events", event("E2E Breakfast (in two months)", 60, series.id));
|
||||
const first = await v2<JobRun>(page, "admin", "POST", "/api/v2/admin/jobs/series/run");
|
||||
expect(first.output.announced).toBe(1);
|
||||
const again = await api<JobRun>(page, "admin", "POST", "/api/admin/jobs/series/run");
|
||||
const again = await v2<JobRun>(page, "admin", "POST", "/api/v2/admin/jobs/series/run");
|
||||
expect(again.output.announced).toBe(0);
|
||||
});
|
||||
|
||||
@@ -86,17 +86,17 @@ test.describe.serial("event series", () => {
|
||||
await expect(page.getByTestId("my-passes").getByRole("button", { name: "Pay now" })).toBeVisible();
|
||||
|
||||
type Mine = { id: string; total: number; registrations: { id: string; event: { title: string } }[] }[];
|
||||
const [purchase] = await api<Mine>(page, "user", "GET", "/api/season-passes/mine");
|
||||
const [purchase] = await v2<Mine>(page, "user", "GET", "/api/v2/me/season-passes");
|
||||
expect(purchase.total).toBe(60);
|
||||
expect(purchase.registrations.map((r) => r.event.title).sort()).toEqual(["E2E Breakfast (in two months)", "E2E Breakfast (next month)"]);
|
||||
// Each event's registration owes its share: 2 × R15.
|
||||
type Reg = { id: string; totalDueComputed?: number; registrationOptions: { quantity: number; priceSnapshot: number }[] };
|
||||
const regs = await api<Reg[]>(page, "supervisor", "GET", `/api/registrations/event/${next.id}`);
|
||||
const regs = await v2<Reg[]>(page, "supervisor", "GET", `/api/v2/events/${next.id}/registrations`);
|
||||
const fromPass = regs.find((r) => r.id === purchase.registrations.find((x) => x.event.title === "E2E Breakfast (next month)")!.id)!;
|
||||
expect(fromPass.registrationOptions[0]).toMatchObject({ quantity: 2, priceSnapshot: 15 });
|
||||
|
||||
// A pass registration keeps its tickets as bought: no codes.
|
||||
const res = await page.request.post(`${API}/api/registrations/${fromPass.id}/coupon`, {
|
||||
const res = await page.request.post(`${API}/api/v2/registrations/${fromPass.id}/coupon`, {
|
||||
headers: { Authorization: `Bearer ${seed().users.user.token}` }, data: { code: "ANY" },
|
||||
});
|
||||
expect(res.status()).toBe(409);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { test, expect, seed, loginAs, api, pickEvent } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, pickEvent, v2 } from "./fixtures";
|
||||
|
||||
test.describe("multi-day events", () => {
|
||||
test("check-in is once per session, and the register and certificates follow", async ({ page }) => {
|
||||
const { course, events } = seed();
|
||||
|
||||
// Scanning today: Week 2.
|
||||
const scan = await api<{ session: { label: string } }>(page, "staff", "POST", `/api/tickets/scan/${course.qrCode}`, { qty: 1 });
|
||||
const scan = await v2<{ session: { label: string } }>(page, "staff", "POST", `/api/v2/checkin/${course.qrCode}`, { people: 1 });
|
||||
expect(scan.session.label).toBe("Week 2");
|
||||
await expect(api(page, "staff", "POST", `/api/tickets/scan/${course.qrCode}`, { qty: 1 })).rejects.toThrow(/Already checked in for Week 2/);
|
||||
expect(await v2(page, "staff", "POST", `/api/v2/checkin/${course.qrCode}`, { people: 1 })).toMatchObject({ outcome: "already_used", message: expect.stringMatching(/Already checked in for Week 2/) });
|
||||
|
||||
// The register shows weeks 1 and 2 ticked.
|
||||
await loginAs(page, "supervisor");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api, pickEvent } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, pickEvent, v2 } from "./fixtures";
|
||||
|
||||
type EventRow = { id: string; title: string; scheduleType?: string; sessions?: { cancelled?: boolean }[] };
|
||||
|
||||
@@ -26,7 +26,7 @@ test.describe("supervisor tools", () => {
|
||||
|
||||
const row = page.locator("li", { hasText: "E2E Wizard Course" });
|
||||
await expect(row.getByText(/5 sessions · /)).toBeVisible();
|
||||
const all = await api<EventRow[]>(page, "supervisor", "GET", "/api/events/all");
|
||||
const all = await v2<EventRow[]>(page, "supervisor", "GET", "/api/v2/events/manage");
|
||||
const created = all.find((e) => e.title === "E2E Wizard Course");
|
||||
expect(created?.scheduleType).toBe("sessions");
|
||||
expect(created?.sessions?.filter((s) => !s.cancelled)).toHaveLength(5);
|
||||
@@ -34,7 +34,7 @@ test.describe("supervisor tools", () => {
|
||||
|
||||
test("copy an event: the popup is filled in and every date moves with the new start", async ({ page }) => {
|
||||
type Full = EventRow & { eventOptions: { name: string; price: number }[]; sessions: { startsAt: string; label?: string | null }[] };
|
||||
const source = await api<Full>(page, "supervisor", "GET", `/api/events/${seed().events.course}`);
|
||||
const source = await v2<Full>(page, "supervisor", "GET", `/api/v2/events/${seed().events.course}/full`);
|
||||
|
||||
await loginAs(page, "supervisor");
|
||||
await page.goto("/dashboard/supervisor/events");
|
||||
@@ -57,10 +57,10 @@ test.describe("supervisor tools", () => {
|
||||
await create.click();
|
||||
await expect(page.getByRole("heading", { name: "Copy Event" })).toBeHidden();
|
||||
|
||||
const all = await api<EventRow[]>(page, "supervisor", "GET", "/api/events/all?includePast=true");
|
||||
const all = await v2<EventRow[]>(page, "supervisor", "GET", "/api/v2/events/manage?past=true");
|
||||
const row = all.find((e) => e.title === "E2E Alpha Course (next term)");
|
||||
expect(row).toBeTruthy();
|
||||
const copy = await api<Full>(page, "supervisor", "GET", `/api/events/${row!.id}`);
|
||||
const copy = await v2<Full>(page, "supervisor", "GET", `/api/v2/events/${row!.id}/full`);
|
||||
expect(copy.scheduleType).toBe("sessions");
|
||||
const active = (s: Full) => s.sessions.filter((x) => !(x as { cancelled?: boolean }).cancelled);
|
||||
expect(active(copy)).toHaveLength(active(source).length);
|
||||
|
||||
@@ -20,9 +20,9 @@ test.describe.serial("volunteer rosters", () => {
|
||||
});
|
||||
|
||||
test("the volunteer ticket isn't offered publicly", async ({ request }) => {
|
||||
const res = await request.get(`${API}/api/events/${seed().events.serving}`);
|
||||
const ev = await res.json();
|
||||
expect(ev.eventOptions.map((o: { name: string }) => o.name)).toEqual(["Entry"]);
|
||||
const res = await request.get(`${API}/api/v2/events/${seed().events.serving}`);
|
||||
const ev = (await res.json()).data;
|
||||
expect(ev.ticketOptions.map((o: { name: string }) => o.name)).toEqual(["Entry"]);
|
||||
});
|
||||
|
||||
test("a user signs up, then asks for cover", async ({ page }) => {
|
||||
@@ -48,8 +48,8 @@ test.describe.serial("volunteer rosters", () => {
|
||||
await expect(page.getByTestId("my-shift").filter({ hasText: "Welcome team" })).toBeVisible();
|
||||
|
||||
// The QR code on the wall holds this; a phone camera opens the check-in page.
|
||||
const qr = await request.get(`${API}/api/volunteers/manage/events/${seed().events.serving}/qr`, { headers: { Authorization: `Bearer ${seed().users.supervisor.token}` } });
|
||||
const { qr: code } = await qr.json();
|
||||
const qr = await request.get(`${API}/api/v2/events/${seed().events.serving}/volunteers/qr`, { headers: { Authorization: `Bearer ${seed().users.supervisor.token}` } });
|
||||
const { qr: code } = (await qr.json()).data;
|
||||
await page.goto(`/serve/check-in?code=${encodeURIComponent(code)}`);
|
||||
await expect(page.getByTestId("volunteer-checked-in")).toContainText("Welcome team");
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ test.describe.serial("outbound webhooks", () => {
|
||||
|
||||
test("a new account is sent, signed, and shows in the delivery log", async ({ page, request }) => {
|
||||
const email = `webhook-${Date.now()}@test.local`;
|
||||
const res = await request.post(`${API}/api/users`, { data: { name: "Webhook Person", email, password: "E2e-password-123", phoneNumber: "0820000123" } });
|
||||
const res = await request.post(`${API}/api/v2/auth/signup`, { data: { name: "Webhook Person", email, password: "E2e-password-123", phone: "0820000123", acceptTerms: true } });
|
||||
expect(res.ok()).toBe(true);
|
||||
|
||||
await expect.poll(() => received.filter(r => r.headers["x-crossevents-event"] === "user.created").length, { timeout: 15000 }).toBeGreaterThan(0);
|
||||
|
||||
Reference in New Issue
Block a user