import { test, expect, loginAs, api, seed, pickEvent } from "./fixtures"; import type { Page } from "@playwright/test"; // 1.52.0: a required attendee form no longer leaves paid door registrations without tickets, // and admins can put things right afterwards (Corrections). type Reg = { id: string; status: string; formsNeeded?: number; registrationOptions: { tickets?: { id: string }[] }[] }; type Row = { id: string; user: { name: string }; missingTickets: boolean; formsNeeded: number; balance: number; status: string; tickets: { id: string; checkedIn: Record }[] }; const ticketsOn = (r: Reg) => r.registrationOptions.reduce((n, o) => n + (o.tickets || []).length, 0); async function register(page: Page, name: string, email: string): Promise { const res = await api<{ data: Reg }>(page, "supervisor", "POST", "/api/v2/registrations/manual", { eventId: seed().events.form, options: [{ eventOptionId: seed().formOptionId, quantity: 1 }], user: { name, email }, skipActivationNotice: true, }); return res.data; } const full = async (page: Page, id: string) => (await api<{ data: Reg }>(page, "supervisor", "GET", `/api/v2/registrations/${id}/full`)).data; const pay = (page: Page, id: string, amount = 200) => api<{ data: { formsNeeded?: number } }>(page, "supervisor", "POST", "/api/v2/payments", { registrationId: id, amount, method: "cash" }); const rows = async (page: Page, eventId: string) => (await api<{ data: { registrations: Row[] } }>(page, "admin", "GET", `/api/v2/corrections/events/${eventId}`)).data.registrations; test.describe("required attendee forms at the door", () => { test("paid at the door: the form holds the tickets back until it's filled in or left for later", async ({ page }) => { const reg = await register(page, "Door Formless", "door-formless@e2e.test"); expect(reg.formsNeeded).toBe(1); const paid = await pay(page, reg.id); expect(paid.data.formsNeeded).toBe(1); expect(ticketsOn(await full(page, reg.id))).toBe(0); const later = await api<{ data: { ticketsIssued: number } }>(page, "staff", "POST", `/api/v2/registrations/${reg.id}/form-later`, { notify: false }); expect(later.data.ticketsIssued).toBe(1); expect(ticketsOn(await full(page, reg.id))).toBe(1); }); test("at the door the form pops up; filling it in issues the tickets once paid", async ({ page }) => { await loginAs(page, "supervisor"); await page.goto("/dashboard/supervisor/at-the-door"); await page.waitForLoadState("networkidle"); await pickEvent(page, "E2E Camp Weekend"); await page.waitForLoadState("networkidle"); await page.getByPlaceholder("Name, email or phone…").fill("Door Camper"); await page.getByText('New attendee "Door Camper"…').click(); await page.getByPlaceholder("Email address").fill("door-camper@e2e.test"); await page.getByRole("button", { name: "Next — Choose Items" }).click(); await page.getByRole("button", { name: "Confirm Registration" }).click(); const popup = page.getByRole("dialog", { name: /Attendee form/ }); await expect(popup).toBeVisible(); await expect(popup.getByText("About you")).toBeVisible(); await popup.getByRole("button", { name: "Save form" }).click(); await expect(popup.getByText('"Emergency contact" is required.')).toBeVisible(); await popup.getByLabel(/Emergency contact/).fill("Mom 082 000 0000"); await popup.getByRole("button", { name: "Save form" }).click(); await expect(popup).toBeHidden(); await expect(page.getByText("Attendee form saved.")).toBeVisible(); await page.getByRole("button", { name: "Full" }).click(); await page.getByRole("button", { name: "Capture Payment" }).click(); await expect(page.getByText("Payment recorded — tickets sent.")).toBeVisible(); await expect(page.getByRole("button", { name: /^Check In 1/ })).toBeVisible(); }); test("self-service kiosk: the visitor fills in the form and is registered", async ({ page }) => { await page.goto("/self-service"); await page.getByPlaceholder("supervisor@example.com").fill(seed().users.supervisor.email); await page.getByPlaceholder("••••••••").fill("E2e-password-123"); await page.getByRole("button", { name: "Sign In" }).click(); await pickEvent(page, "E2E Camp Weekend"); await page.getByRole("button", { name: "Start Kiosk" }).click(); await page.getByPlaceholder("john@example.com").fill("kiosk-camper@e2e.test"); await page.getByPlaceholder("John Smith").fill("Kiosk Camper"); await page.getByRole("button", { name: /^Add one / }).first().click(); await page.getByRole("button", { name: "Next — Fill in Form" }).click(); await expect(page.getByRole("heading", { name: "Attendee Information" })).toBeVisible(); // A heading is text to read, not a box to fill in. await expect(page.getByText("About you")).toBeVisible(); await expect(page.locator("textarea")).toHaveCount(0); await page.getByLabel(/Emergency contact/).fill("Dad 082 111 1111"); await page.getByRole("button", { name: "Complete Registration" }).click(); await expect(page.getByRole("heading", { name: "You're Registered!" })).toBeVisible(); }); }); test.describe("Corrections (admins)", () => { test("issue every missing ticket at an event in one go", async ({ page }) => { const reg = await register(page, "Missing Tickets", "missing-tickets@e2e.test"); await pay(page, reg.id); expect((await rows(page, seed().events.form)).find(r => r.id === reg.id)).toMatchObject({ missingTickets: true, formsNeeded: 1 }); const out = await api<{ data: { registrations: number; tickets: number } }>(page, "admin", "POST", `/api/v2/corrections/events/${seed().events.form}/issue-missing`, {}); expect(out.data.tickets).toBeGreaterThanOrEqual(1); expect((await rows(page, seed().events.form)).find(r => r.id === reg.id)).toMatchObject({ missingTickets: false, formsNeeded: 0 }); }); test("tickets before payment, and making a balance free", async ({ page }) => { const later = await register(page, "Pays Later", "pays-later@e2e.test"); const res = await api<{ data: { ticketsIssued: number; registration: Row } }>(page, "admin", "POST", `/api/v2/corrections/registrations/${later.id}/tickets`, { payLater: true, skipForm: true, reason: "Pays on Friday" }); expect(res.data.ticketsIssued).toBe(1); expect(res.data.registration).toMatchObject({ status: "pending", balance: 200 }); const comp = await register(page, "On The House", "on-the-house@e2e.test"); await pay(page, comp.id, 50); const free = await api<{ data: { amount: number; registration: Row } }>(page, "admin", "POST", `/api/v2/corrections/registrations/${comp.id}/complimentary`, { skipForm: true, reason: "Speaker" }); expect(free.data.amount).toBe(150); expect(free.data.registration).toMatchObject({ status: "paid", balance: 0 }); expect(free.data.registration.tickets).toHaveLength(1); // Not for staff or supervisors. await expect(api(page, "supervisor", "GET", `/api/v2/corrections/events/${seed().events.form}`)).rejects.toThrow("403"); }); test("check someone in after the event is over", async ({ page }) => { await loginAs(page, "admin"); await page.goto(`/dashboard/admin/corrections?event=${seed().events.past}`); await page.getByRole("button", { name: /^Not checked in/ }).click(); const card = page.locator("div.border.rounded-xl", { hasText: "Lerato Late" }); await expect(card.getByText("Checked in: 0/2")).toBeVisible(); await card.getByRole("button", { name: "Check in" }).click(); await expect(page.getByText("Lerato Late: checked in.")).toBeVisible(); const [row] = (await rows(page, seed().events.past)).filter(r => r.user.name === "Lerato Late"); expect(row.tickets[0].checkedIn.event).toBe(2); }); });