- v2: /events/manage, create, PATCH, deactivate, copy-from, notify-recipients. - src/services/events.ts (from eventController.js, with the schedule helpers); v1 uses it. - fetchManagedEvents() for every picker; the event wizard writes through v2. - pg-boss 11 in its own schema (pgboss_v11); old pgboss schema left in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
130 lines
8.7 KiB
TypeScript
130 lines
8.7 KiB
TypeScript
import { test, expect, seed, API } from "./fixtures";
|
|
|
|
// /api/v2 (1.51.0) against the real server and database: paged public events, the v2 error
|
|
// shape, the signed-in person, and the OpenAPI reference at /docs/v2.
|
|
test.describe("API v2", () => {
|
|
test("public events come a page at a time; errors have a code", async ({ request }) => {
|
|
const res = await request.get(`${API}/api/v2/events?limit=2`);
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.data).toHaveLength(2);
|
|
expect(body.meta).toMatchObject({ page: 1, limit: 2 });
|
|
expect(body.meta.total).toBeGreaterThan(2);
|
|
|
|
const search = await (await request.get(`${API}/api/v2/events?q=free%20evening`)).json();
|
|
expect(search.data.map((e: { title: string }) => e.title)).toEqual(["E2E Free Evening"]);
|
|
|
|
const one = await (await request.get(`${API}/api/v2/events/${seed().events.paid}`)).json();
|
|
expect(one.data.ticketOptions.length).toBeGreaterThan(0);
|
|
|
|
const bad = await request.get(`${API}/api/v2/events?limit=1000`);
|
|
expect(bad.status()).toBe(400);
|
|
expect((await bad.json()).error).toMatchObject({ code: "VALIDATION_FAILED", fields: { limit: expect.any(String) } });
|
|
|
|
const missing = await request.get(`${API}/api/v2/events/00000000-0000-4000-8000-000000000000`);
|
|
expect((await missing.json()).error.code).toBe("NOT_FOUND");
|
|
});
|
|
|
|
test("me and my registrations need a token", async ({ request }) => {
|
|
expect((await request.get(`${API}/api/v2/me`)).status()).toBe(401);
|
|
const headers = { Authorization: `Bearer ${seed().users.user.token}` };
|
|
const me = await (await request.get(`${API}/api/v2/me`, { headers })).json();
|
|
expect(me.data).toMatchObject({ id: seed().users.user.id, role: "user" });
|
|
const regs = await (await request.get(`${API}/api/v2/me/registrations?past=true`, { headers })).json();
|
|
expect(regs.meta).toMatchObject({ page: 1, limit: 25 });
|
|
expect(regs.data.length).toBe(Math.min(25, regs.meta.total));
|
|
});
|
|
|
|
test("register for a free event, then cancel it", async ({ request }) => {
|
|
const headers = { Authorization: `Bearer ${seed().users.staff.token}` };
|
|
const event = (await (await request.get(`${API}/api/v2/events/${seed().events.free}`)).json()).data;
|
|
const made = await request.post(`${API}/api/v2/registrations`, { headers, data: { eventId: event.id, options: [{ eventOptionId: event.ticketOptions[0].id, quantity: 1 }] } });
|
|
expect(made.status()).toBe(201);
|
|
const reg = (await made.json()).data;
|
|
expect(reg).toMatchObject({ status: "paid", balance: 0, event: { id: event.id } });
|
|
|
|
const someoneElse = await request.post(`${API}/api/v2/registrations/${reg.id}/cancel`, { headers: { Authorization: `Bearer ${seed().users.user.token}` } });
|
|
expect((await someoneElse.json()).error.code).toBe("NOT_FOUND");
|
|
|
|
const cancelled = await request.post(`${API}/api/v2/registrations/${reg.id}/cancel`, { headers });
|
|
expect((await cancelled.json()).data.status).toBe("cancelled");
|
|
const again = await request.post(`${API}/api/v2/registrations/${reg.id}/cancel`, { headers });
|
|
expect((await again.json()).error).toMatchObject({ code: "VALIDATION_FAILED", message: "Registration is already cancelled" });
|
|
});
|
|
|
|
test("log in, change my details, and check a ticket in", async ({ request }) => {
|
|
const bad = await request.post(`${API}/api/v2/auth/login`, { data: { identifier: seed().users.user.email, password: "wrong-password" } });
|
|
expect(bad.status()).toBe(401);
|
|
expect((await bad.json()).error).toMatchObject({ code: "UNAUTHENTICATED", message: "Invalid email or password" });
|
|
|
|
const login = await (await request.post(`${API}/api/v2/auth/login`, { data: { identifier: seed().users.user.email, password: "E2e-password-123" } })).json();
|
|
expect(login.data).toMatchObject({ status: "signed_in", user: { id: seed().users.user.id, role: "user" } });
|
|
const headers = { Authorization: `Bearer ${login.data.token}` };
|
|
|
|
const changed = await (await request.patch(`${API}/api/v2/me`, { headers, data: { notificationPreference: "email" } })).json();
|
|
expect(changed.data).toMatchObject({ id: seed().users.user.id, notificationPreference: "email" });
|
|
expect(changed.token).toEqual(expect.any(String));
|
|
|
|
// 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 qr = tickets.find((t: { eventId: string; qrCode: string }) => t.eventId === event.id).qrCode;
|
|
|
|
const staff = { Authorization: `Bearer ${seed().users.staff.token}` };
|
|
expect((await request.post(`${API}/api/v2/checkin/${qr}`, { headers, data: {} })).status()).toBe(403);
|
|
const look = await (await request.get(`${API}/api/v2/checkin/${qr}`, { headers: staff })).json();
|
|
expect(look.data).toMatchObject({ outcome: "found", ticket: { eventId: event.id } });
|
|
expect(look.data.ticket.remaining).toBeGreaterThan(0);
|
|
|
|
const scanned = await (await request.post(`${API}/api/v2/checkin/${qr}`, { headers: staff, data: { eventId: event.id } })).json();
|
|
expect(scanned.data).toMatchObject({ outcome: "checked_in", remaining: 0 });
|
|
const again = await (await request.post(`${API}/api/v2/checkin/${qr}`, { headers: staff, data: {} })).json();
|
|
expect(again.data).toMatchObject({ outcome: "already_used", checkedIn: 0 });
|
|
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 }) => {
|
|
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"`);
|
|
// Endpoints with no v2 version yet say nothing.
|
|
expect((await request.get(`${API}/api/settings/needs-setup`)).headers()["deprecation"]).toBeUndefined();
|
|
});
|
|
|
|
test("staff list every event; supervisors create, change and admins deactivate", async ({ request }) => {
|
|
const staff = { Authorization: `Bearer ${seed().users.staff.token}` };
|
|
const list = await (await request.get(`${API}/api/v2/events/manage`, { headers: staff })).json();
|
|
// The kids event is hidden from the public list but staff see it.
|
|
expect(list.data.map((e: { id: string }) => e.id)).toContain(seed().events.kids);
|
|
expect((await (await request.get(`${API}/api/v2/events?limit=100`)).json()).data.map((e: { id: string }) => e.id)).not.toContain(seed().events.kids);
|
|
|
|
const sup = { Authorization: `Bearer ${seed().users.supervisor.token}` };
|
|
const start = new Date(Date.now() + 20 * 864e5);
|
|
const made = await request.post(`${API}/api/v2/events`, { headers: sup, data: { title: "E2E v2 Event", description: "Made through v2", price: 0, location: "1 Test Street", startDate: start.toISOString(), endDate: new Date(start.getTime() + 3600e3).toISOString() } });
|
|
expect(made.status()).toBe(201);
|
|
const ev = (await made.json()).data;
|
|
expect(ev.eventOptions.map((o: { name: string }) => o.name)).toEqual(["Main Ticket"]);
|
|
|
|
const changed = await (await request.patch(`${API}/api/v2/events/${ev.id}`, { headers: sup, data: { title: "E2E v2 Event (renamed)", waitlistEnabled: true } })).json();
|
|
expect(changed.data).toMatchObject({ title: "E2E v2 Event (renamed)", waitlistEnabled: true, sessionChanges: null });
|
|
|
|
expect((await request.delete(`${API}/api/v2/events/${ev.id}`, { headers: sup })).status()).toBe(403);
|
|
const admin = { Authorization: `Bearer ${seed().users.admin.token}` };
|
|
expect((await (await request.delete(`${API}/api/v2/events/${ev.id}`, { headers: admin })).json()).data).toEqual({ id: ev.id, isActive: false });
|
|
});
|
|
|
|
test("an admin can read the OpenAPI reference at /docs/v2", async ({ page, request }) => {
|
|
const headers = { Authorization: `Bearer ${seed().users.user.token}` };
|
|
expect((await request.get(`${API}/api/v2/openapi.json`, { headers })).status()).toBe(403);
|
|
|
|
await page.goto(`${API}/docs/v2?token=${seed().users.admin.token}`);
|
|
await expect(page.getByRole("heading", { name: /Cross Events API/ })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: /^GET \/events\/\{id\} One public/ })).toBeVisible();
|
|
// The token isn't left in the address bar.
|
|
expect(page.url()).not.toContain("token=");
|
|
});
|
|
});
|