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(page, "supervisor", "GET", "/api/v2/series"); series = all.find((s) => s.name === "E2E Breakfast")!; past = await v2(page, "supervisor", "POST", "/api/v2/events", event("E2E Breakfast (last month)", -30, series.id)); next = await v2(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(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(page, "supervisor", "POST", "/api/v2/events", event("E2E Breakfast (in two months)", 60, series.id)); const first = await v2(page, "admin", "POST", "/api/v2/admin/jobs/series/run"); expect(first.output.announced).toBe(1); const again = await v2(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(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(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)"); }); });