import { test, expect } from './base'; import { APP_URL, EVENT_ID, ID } from '../src/helpers/config'; import { login } from '../src/helpers/auth'; import { db, psql, psqlScalar, sqlQuote } from '../src/helpers/db'; import { AppPage } from '../src/pages/AppPage'; import { ScanPage } from '../src/pages/ScanPage'; /** * Front-desk gate: an attendee must be checked in to the EVENT (the welcome * check-in at the front desk) before they can be scanned into any SESSION. * The database enforces it (`checkin_attendee` raises); the scanner turns that * into a dedicated sheet so staff can relay it to the attendee. * * These specs provision their own attendee and pick a real session from the * active event instead of relying on seeded demo rows, so they survive data * re-imports (the historic fixtures were replaced by imported pretix data). */ const GATE_EMAIL = 'gate-test@example.test'; const GATE_TOKEN = 'CVV-GATE-TEST-01'; const GATE_NAME = 'Gate Test Attendee'; /** Ensure a known ticketed attendee exists in the active event, unchecked in. */ function ensureGateAttendee(): void { psql(`insert into public.contacts (email, full_name, is_admin) values (${sqlQuote(GATE_EMAIL)}, ${sqlQuote(GATE_NAME)}, false) on conflict (email) do update set full_name = excluded.full_name`); psql(`insert into public.registrations (event_id, contact_email, type, checked_in, points, qr_token) values (${sqlQuote(EVENT_ID)}, ${sqlQuote(GATE_EMAIL)}, 'attendee', false, 0, ${sqlQuote(GATE_TOKEN)}) on conflict (event_id, contact_email) do update set checked_in = false, points = 0, qr_token = excluded.qr_token, type = 'attendee'`); } function removeGateAttendee(): void { psql(`delete from public.checkins where contact_email = ${sqlQuote(GATE_EMAIL)}`); // The welcome scan in CONV-GATE-002 legitimately queued a label; with no Pi // attached locally it would sit in the queue forever, so drop it here. psql(`delete from pgmq.q_badge_print where message->'sample'->>'email' = ${sqlQuote(GATE_EMAIL)}`); psql(`delete from public.registrations where contact_email = ${sqlQuote(GATE_EMAIL)}`); psql(`delete from public.contacts where email = ${sqlQuote(GATE_EMAIL)}`); } /** Any checkable (non-service) session of the active event. */ function someSessionId(): string { return psqlScalar(`select s.id from public.sessions s join public.slots sl on sl.id = s.slot_id where s.event_id = ${sqlQuote(EVENT_ID)} and sl.type <> 'service_session' order by sl.id, s.id limit 1`); } function setWelcome(checkedIn: boolean): void { psql(`update public.registrations set checked_in = ${checkedIn} where contact_email = ${sqlQuote(GATE_EMAIL)} and event_id = ${sqlQuote(EVENT_ID)}`); } test.describe('Front-desk gate (no session check-in before welcome check-in)', () => { test.beforeEach(() => { ensureGateAttendee(); removeGateAttendeeCheckins(); }); test.afterAll(() => removeGateAttendee()); test('CONV-GATE-001 a session scan of an unchecked attendee is refused with a front-desk message', async ({ page }) => { const app = new AppPage(page, APP_URL); const scan = new ScanPage(page); const session = someSessionId(); expect(session, 'the active event needs at least one checkable session').toBeTruthy(); await login(page, APP_URL, ID.staff); await app.waitForAdmitted(); await app.gotoTab('scan'); await scan.setStaffMode(); await scan.setSessionMode(); await scan.selectSession(session); await scan.scanCode(GATE_TOKEN); // A blocking sheet, not a transient toast. await expect(scan.frontDeskSheet()).toBeVisible(); await expect(scan.frontDeskSheet()).toContainText(/front desk/i); // No session result, and nothing persisted. await expect(scan.sessionResult()).toHaveCount(0); expect(db.sessionCheckins(GATE_EMAIL)).toEqual([]); expect(db.isWelcomeCheckedIn(GATE_EMAIL)).toBe(false); // Acknowledging clears it (and re-arms the camera via `paused`). await scan.dismissFrontDesk(); await expect(scan.frontDeskSheet()).toHaveCount(0); }); test('CONV-GATE-002 after the welcome check-in the same session scan succeeds', async ({ page }) => { const app = new AppPage(page, APP_URL); const scan = new ScanPage(page); const session = someSessionId(); expect(session).toBeTruthy(); await login(page, APP_URL, ID.staff); await app.waitForAdmitted(); await app.gotoTab('scan'); await scan.setStaffMode(); // 1. Blocked in session mode. await scan.setSessionMode(); await scan.selectSession(session); await scan.scanCode(GATE_TOKEN); await expect(scan.frontDeskSheet()).toBeVisible(); await scan.dismissFrontDesk(); // 2. Welcome (front desk) check-in. await scan.setWelcomeMode(); await scan.scanWelcome(GATE_TOKEN); expect(await db.waitForWelcomeCheckedIn(GATE_EMAIL)).toBe(true); await scan.dismissResult(); // 3. The very same session scan now goes through. await scan.setSessionMode(); await scan.selectSession(session); await scan.scanCode(GATE_TOKEN); await expect(scan.sessionResult()).toBeVisible(); expect(await db.waitForSessionCheckin(GATE_EMAIL, session)).toBe(true); }); test('CONV-GATE-003 a session check-in no longer checks the attendee into the event by itself', async ({ page }) => { const app = new AppPage(page, APP_URL); const scan = new ScanPage(page); const session = someSessionId(); expect(session).toBeTruthy(); // Front desk already done, so the gate is open — but the event flag is then // cleared by hand to prove the session check-in does not set it again. setWelcome(true); await login(page, APP_URL, ID.staff); await app.waitForAdmitted(); await app.gotoTab('scan'); await scan.setStaffMode(); await scan.setSessionMode(); await scan.selectSession(session); setWelcome(false); // undo the precondition: now the gate must refuse await scan.scanCode(GATE_TOKEN); await expect(scan.frontDeskSheet()).toBeVisible(); expect(db.sessionCheckins(GATE_EMAIL)).toEqual([]); setWelcome(true); await scan.dismissFrontDesk(); await scan.scanCode(GATE_TOKEN); await expect(scan.sessionResult()).toBeVisible(); expect(await db.waitForSessionCheckin(GATE_EMAIL, session)).toBe(true); }); }); function removeGateAttendeeCheckins(): void { psql(`delete from public.checkins where contact_email = ${sqlQuote(GATE_EMAIL)}`); psql(`delete from pgmq.q_badge_print where message->'sample'->>'email' = ${sqlQuote(GATE_EMAIL)}`); psql(`update public.registrations set checked_in = false, points = 0 where contact_email = ${sqlQuote(GATE_EMAIL)}`); }