import { test, expect, seed, api, loginAs, API, v2 } from "./fixtures"; // Campus-scoped staff (1.44.0): the seeded staff member and supervisor are limited to E2E South // for these tests; afterwards the limits are cleared and campuses turned off again. test.describe("campus-scoped staff", () => { test.beforeAll(async ({ browser }) => { const page = await browser.newPage(); await v2(page, "admin", "PUT", "/api/v2/campuses/enabled", { enabled: true }); for (const role of ["staff", "supervisor"] as const) { await v2(page, "admin", "PATCH", `/api/v2/users/${seed().users[role].id}`, { scopedCampusIds: [seed().campuses.south.id] }); } await page.close(); }); test.afterAll(async ({ browser }) => { const page = await browser.newPage(); for (const role of ["staff", "supervisor"] as const) { await v2(page, "admin", "PATCH", `/api/v2/users/${seed().users[role].id}`, { scopedCampusIds: [] }); } await v2(page, "admin", "PUT", "/api/v2/campuses/enabled", { enabled: false }); await page.close(); }); test("the scanner refuses another campus's ticket and says which campus", async ({ page }) => { const scan = (qr: string) => page.request.get(`${API}/api/v2/checkin/${encodeURIComponent(qr)}`, { headers: { Authorization: `Bearer ${seed().users.staff.token}` } }); const north = await scan(seed().northTicketQr); expect(north.status()).toBe(403); expect((await north.json()).error.message).toBe("This ticket is for an event at E2E North."); // The course is for all campuses, so it scans. expect((await scan(seed().course.qrCode)).status()).toBe(200); }); test("a scoped supervisor sees their campus and church-wide events, and can't edit church-wide ones", async ({ page }) => { await loginAs(page, "supervisor"); await page.goto("/dashboard/supervisor"); await expect(page.getByText("You work with E2E South, and events for all campuses.")).toBeVisible(); await page.goto("/dashboard/supervisor/events"); await expect(page.getByText("E2E Paid Conference")).toBeVisible(); // South await expect(page.getByText("E2E Alpha Course")).toBeVisible(); // all campuses await expect(page.getByText("E2E Free Evening")).toBeHidden(); // North await page.getByText("E2E Alpha Course").click(); await expect(page.getByText(/This is an event for all campuses — only admins and supervisors for every campus can change it/)).toBeVisible(); await expect(page.getByRole("button", { name: "Save Changes" })).toBeDisabled(); }); test("another campus's registrations are not found for a scoped supervisor", async ({ page }) => { const res = await page.request.get(`${API}/api/v2/events/${seed().events.free}/registrations`, { headers: { Authorization: `Bearer ${seed().users.supervisor.token}` } }); expect(res.status()).toBe(404); }); });