A pass sells a ticket at each of several events in a series for one price. Supervisors set passes up on the Event series page (events and ticket per event; fixed once sold). Buying on the series page registers the buyer at every event at once with one checkout (free passes give tickets straight away; Pay now if online payment isn't possible). The price is split over the events in proportion to their normal prices: each registration line is priced at its share and the webhook records one Payment per event, so cashups stay per event. Pass registrations aren't repriced, take no coupons and can't be edited. Migration 20261028150000_season_pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
6.9 KiB
TypeScript
115 lines
6.9 KiB
TypeScript
import { test, expect, loginAs, api, seed, API } 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 api<Series[]>(page, "supervisor", "GET", "/api/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));
|
||
// 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");
|
||
});
|
||
|
||
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 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");
|
||
expect(first.output.announced).toBe(1);
|
||
const again = await api<JobRun>(page, "admin", "POST", "/api/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 api<Mine>(page, "user", "GET", "/api/season-passes/mine");
|
||
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 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`, {
|
||
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)");
|
||
});
|
||
});
|