import { test, expect } from './base'; import { APP_URL, ID, SESSION_A, SESSION_B } from '../src/helpers/config'; import { login } from '../src/helpers/auth'; import { createUser } from '../src/helpers/multi'; import { db } from '../src/helpers/db'; import { AppPage } from '../src/pages/AppPage'; import { ScanPage } from '../src/pages/ScanPage'; /** * §21–§23 Session Check-In + Welcome/Session independence. */ test.describe('Session Check-In', () => { test('CONV-SESSION-001 staff checks an attendee into a session (QR)', async ({ page }) => { const app = new AppPage(page, APP_URL); const scan = new ScanPage(page); await login(page, APP_URL, ID.staff); await app.waitForAdmitted(); await app.gotoTab('scan'); await scan.setStaffMode(); await scan.setSessionMode(); // SESSION_A is explicitly selected. await scan.selectSession(SESSION_A); // Scan ATTENDEE_A and complete the check-in. await scan.scanCode(ID.attendeeA.qrToken); await expect(scan.sessionResult()).toBeVisible(); // Attendance is registered for (ATTENDEE_A, SESSION_A) and persisted. expect(await db.waitForSessionCheckin(ID.attendeeA.email, SESSION_A)).toBe(true); // Attendance is NOT automatically created for other sessions. const checkins = db.sessionCheckins(ID.attendeeA.email); expect(checkins).toContain(SESSION_A); expect(checkins).not.toContain(SESSION_B); }); test('CONV-SESSION-002 session check-in via manual code is equivalent to QR', async ({ page }) => { const app = new AppPage(page, APP_URL); const scan = new ScanPage(page); await login(page, APP_URL, ID.staff); await app.waitForAdmitted(); await app.gotoTab('scan'); await scan.setStaffMode(); await scan.setSessionMode(); await scan.selectSession(SESSION_A); // Manual code input (the same token the QR would carry). await scan.scanCode(ID.attendeeA.qrToken); await expect(scan.sessionResult()).toBeVisible(); // Equivalent backend state: (ATTENDEE_A, SESSION_A) checked in. expect(await db.waitForSessionCheckin(ID.attendeeA.email, SESSION_A)).toBe(true); }); test('CONV-SESSION-003 welcome check-in and session check-in are independent states', async ({ page }) => { const app = new AppPage(page, APP_URL); const scan = new ScanPage(page); await login(page, APP_URL, ID.staff); await app.waitForAdmitted(); await app.gotoTab('scan'); // 1. Welcome check-in only (no session). A confirmation popup appears // first; confirm it before the attendee is checked in. await scan.setWelcomeMode(); await scan.scanCode(ID.attendeeA.qrToken); await expect(scan.welcomeConfirm()).toBeVisible(); await scan.confirmWelcome(); await expect(scan.welcomeResult()).toBeVisible(); expect(await db.waitForWelcomeCheckedIn(ID.attendeeA.email)).toBe(true); // Welcome check-in must NOT create any session attendance. await new Promise((r) => setTimeout(r, 300)); expect(db.sessionCheckins(ID.attendeeA.email)).toEqual([]); // Dismiss the result sheet so its backdrop doesn't block the mode toggle. await scan.dismissResult(); // 2. Now a session check-in (SESSION_A) — a distinct, session-specific state. await scan.setSessionMode(); await scan.selectSession(SESSION_A); await scan.scanCode(ID.attendeeA.qrToken); await expect(scan.sessionResult()).toBeVisible(); expect(await db.waitForSessionCheckin(ID.attendeeA.email, SESSION_A)).toBe(true); // The session check-in references a specific session (SESSION_A, not SESSION_B). const checkins = db.sessionCheckins(ID.attendeeA.email); expect(checkins).toContain(SESSION_A); expect(checkins).not.toContain(SESSION_B); }); });