Files
joshuaandClaude Opus 5.5 3f59164ab2 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>
2026-11-02 16:35:06 +02:00

115 lines
6.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
// followers once when a new event goes live.
type Created = { id: string; title: string };
type Series = { id: string; slug: string; name: string };
type JobRun = { queued: boolean; output: { announced: number; sent: number; skipped: number } };
const day = 24 * 60 * 60 * 1000;
const event = (title: string, startsInDays: number, seriesId: string) => {
const start = new Date(Date.now() + startsInDays * day);
return { title, description: "A breakfast for the tests.", startDate: start.toISOString(), endDate: new Date(start.getTime() + 2 * 60 * 60 * 1000).toISOString(), price: 0, location: "1 Test Street, Pretoria", seriesId };
};
test.describe.serial("event series", () => {
let series: Series;
let past: Created;
let next: Created;
test("a supervisor makes a series", async ({ page }) => {
await loginAs(page, "supervisor");
await page.goto("/dashboard/supervisor/series");
await page.getByRole("button", { name: "+ New series" }).click();
await page.getByLabel("Name").fill("E2E Breakfast");
await page.getByLabel("Description").fill("Men's breakfast, once a month.");
await page.getByRole("button", { name: "Create series" }).click();
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 v2<Series[]>(page, "supervisor", "GET", "/api/v2/series");
series = all.find((s) => s.name === "E2E Breakfast")!;
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 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 }) => {
await page.goto(`/series/${series.slug}`);
await expect(page.getByRole("heading", { name: "E2E Breakfast", exact: true })).toBeVisible();
await expect(page.getByText("E2E Breakfast (next month)")).toBeVisible();
await expect(page.getByTestId("series-past")).toContainText("E2E Breakfast (last month)");
});
test("an event page links to its series and the next event in it", async ({ page }) => {
await page.goto(`/events/${past.id}`);
await expect(page.getByTestId("event-series")).toContainText("Part of E2E Breakfast");
await page.getByTestId("next-in-series").click();
await expect(page).toHaveURL(new RegExp(`/events/${next.id}`));
});
test("a user follows the series and hears once about a new event", async ({ page }) => {
await loginAs(page, "user");
await page.goto(`/series/${series.slug}`);
await page.getByRole("button", { name: "Follow this series" }).click();
await expect(page.getByRole("button", { name: "Unfollow" })).toBeVisible();
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 v2<JobRun>(page, "admin", "POST", "/api/v2/admin/jobs/series/run");
expect(again.output.announced).toBe(0);
});
test("season pass: a supervisor sets one up, a user buys two, each event gets its share", async ({ page }) => {
await loginAs(page, "supervisor");
await page.goto("/dashboard/supervisor/series");
const row = page.getByTestId("series-row").filter({ hasText: "E2E Breakfast" });
await row.getByRole("button", { name: "+ New pass" }).click();
await row.getByLabel("Pass name").fill("E2E Breakfast pass");
await row.getByLabel("Price (R)").fill("30");
// The two upcoming breakfasts are ticked; both tickets are free normally, so the split is equal.
await row.getByRole("button", { name: "Create pass" }).click();
await expect(row.getByTestId("season-pass")).toContainText("E2E Breakfast pass");
await expect(row.getByTestId("season-pass")).toContainText("share R 15.00");
// E2E has no online payment provider, so the places are booked and wait for payment.
await loginAs(page, "user");
await page.goto(`/series/${series.slug}`);
const offer = page.getByTestId("season-pass-offer").filter({ hasText: "E2E Breakfast pass" });
await offer.getByLabel("How many of E2E Breakfast pass").selectOption("2");
await offer.getByRole("button", { name: "Buy · R 60.00" }).click();
await expect(page.getByTestId("season-pass-offers").getByRole("status")).toContainText("Your places are booked");
await expect(page.getByTestId("my-passes")).toContainText("2 × E2E Breakfast pass");
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 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 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/v2/registrations/${fromPass.id}/coupon`, {
headers: { Authorization: `Bearer ${seed().users.user.token}` }, data: { code: "ANY" },
});
expect(res.status()).toBe(409);
});
test("year on year: the series report compares its events, oldest first", async ({ page }) => {
await loginAs(page, "supervisor");
await page.goto("/dashboard/supervisor/series");
await page.getByTestId("series-row").filter({ hasText: "E2E Breakfast" }).getByRole("link", { name: "Compare" }).click();
const rows = page.getByTestId("comparison-row");
await expect(rows).toHaveCount(3);
await expect(rows.first()).toContainText("E2E Breakfast (last month)");
await expect(rows.last()).toContainText("E2E Breakfast (in two months)");
});
});