fix(admin): per-row check-in toggle; feat(db): front-desk gate + badge copies
Registrations table felt buggy because both row actions did setBusy(true) -> write -> reloadRegistrations() -> setBusy(false): the list is sorted by points, so a reload made the row you just touched jump (or vanish under a Checked-in filter), and the single `busy` flag disabled every control in the table for the whole request. The fix is per-row in-flight state (busyIds + withRowBusy) and no reload at all: the toggle patches its own row's checked_in plus the points delta the RPC returns, the type change patches `type`; a rejected write rolls both back. Only the touched row is disabled, shows a "Saving…" pulse, and two rows can save at once. Toggle hit area is now 40x41 px with a focus-visible ring. Front-desk gate: checkin_attendee reads registrations.checked_in and raises "This attendee needs to be checked in at the front desk first." when it is not true, and no longer sets checked_in as a side effect. checkins has no INSERT policy, so the RPC is the only write path and the gate cannot be bypassed. The scanner shows a dedicated "Not checked in yet" sheet instead of a toast. Badge copies: events.badge_copies (1..4, default 1). welcome_checkin sends that many pgmq jobs in one transaction (the Pi prints one label per job, so N jobs = N labels; no worker change) and clamps the value again itself. preview_welcome_checkin gained a `copies` column (drop + recreate) so the popup states the real count. Manual reprint still prints exactly one. Set from Settings -> Badge printing (active event) and the Events form, always as a single-column update; the Settings badge section now renders even when the LLM settings call fails. Tests: badge_print 113 (+6), leaderboard 47 (+1), new registration-checkin-toggle (6), front-desk-gate (3), welcome-badge-copies (3); the stale registrations-PATCH mock in registration-ticket-merge now targets set_registration_checked_in, the ambiguous Save button is "Save copies", and the print-copy assertion tolerates the typographic apostrophe. Docs updated (rpcs, schema, printing, tests, admin-app, screens) with a release record; NOT deployed - see docs/releases/2026-10-19.md. Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
d3531e1fac
commit
17473916a6
27 files changed
+1378
-73
No files matched your search
@@ -74,7 +74,9 @@ test.describe('Welcome Check-In + attendee access', () => {
|
||||
const confirm = scan.welcomeConfirm();
|
||||
await expect(confirm).toBeVisible();
|
||||
await expect(confirm).toContainText(/You are checking in/);
|
||||
await expect(confirm).toContainText(/print this person's label/i);
|
||||
// One label by default, so the singular wording applies. `.` covers the
|
||||
// typographic apostrophe in the app copy.
|
||||
await expect(confirm).toContainText(/print this person.s label/i);
|
||||
expect(db.isWelcomeCheckedIn(ID.attendeeNew.email)).toBe(false);
|
||||
|
||||
// "No" dismisses the popup and leaves the attendee unchecked in.
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
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 = '[email protected]';
|
||||
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)}`);
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
import { test, expect, type Page, type Route } from '@playwright/test';
|
||||
|
||||
const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001';
|
||||
const eventId = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
|
||||
const user = { id: '99999999-9999-4999-8999-999999999999', email: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
|
||||
|
||||
/**
|
||||
* The check-in toggle must feel instant and stay put. The regression this
|
||||
* guards: the handler used to set a GLOBAL busy flag and reload the whole
|
||||
* registration list after every toggle. Because the table is sorted by points,
|
||||
* the reload moved the row you had just touched somewhere else, a column filter
|
||||
* could make it vanish, and every control in the table went dead mid-request.
|
||||
*/
|
||||
|
||||
type Reg = {
|
||||
id: string; event_id: string; contact_email: string; type: string; qr_token: string | null;
|
||||
external_id: null; import_source: null; checked_in: boolean; points: number; created_at: string;
|
||||
};
|
||||
|
||||
const mkRegs = (): Reg[] => [
|
||||
{ id: 'r1', event_id: eventId, contact_email: '[email protected]', type: 'attendee', qr_token: 'CV-A', external_id: null, import_source: null, checked_in: false, points: 40, created_at: 'x' },
|
||||
{ id: 'r2', event_id: eventId, contact_email: '[email protected]', type: 'attendee', qr_token: 'CV-B', external_id: null, import_source: null, checked_in: false, points: 30, created_at: 'x' },
|
||||
{ id: 'r3', event_id: eventId, contact_email: '[email protected]', type: 'speaker', qr_token: 'CV-C', external_id: null, import_source: null, checked_in: false, points: 20, created_at: 'x' },
|
||||
{ id: 'r4', event_id: eventId, contact_email: '[email protected]', type: 'staff', qr_token: 'CV-D', external_id: null, import_source: null, checked_in: false, points: 10, created_at: 'x' },
|
||||
];
|
||||
const contacts = [
|
||||
{ email: '[email protected]', full_name: 'Admin User', linkedin_url: null, show_email: true, show_linkedin: true, is_admin: true, created_at: 'x' },
|
||||
{ email: '[email protected]', full_name: 'Ann A', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||||
{ email: '[email protected]', full_name: 'Bob B', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||||
{ email: '[email protected]', full_name: 'Cid C', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||||
{ email: '[email protected]', full_name: 'Dee D', linkedin_url: null, show_email: true, show_linkedin: false, is_admin: false, created_at: 'x' },
|
||||
];
|
||||
const event = {
|
||||
id: eventId, name: 'Toggle Conference', company: 'APPE', is_active: true, location: null,
|
||||
start_date: '2026-11-01', end_date: '2026-11-01', use_realtime_clock: false, sessionize_endpoint: null,
|
||||
pretix_organizer: null, pretix_event_slug: null, pretix_api_key: null, last_synced_at: null,
|
||||
talk_networking_bonus: 2, badge_copies: 1, num_registrations: 4, num_checked_in_registrations: 0,
|
||||
num_sessions: 0, num_speakers: 1, avg_feedback: null, created_at: 'x',
|
||||
};
|
||||
|
||||
/** Mutable per-test fixtures so a handler can observe its own writes. */
|
||||
type Harness = { regs: Reg[]; registrationFetches: number; setCheckedInDelayMs: number };
|
||||
|
||||
async function openAdmin(page: Page, view: 'Registrations' | 'Settings', h: Harness) {
|
||||
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
|
||||
const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'r', expires_in: 3600, token_type: 'bearer' };
|
||||
await page.route('**/auth/v1/**', (r) => r.fulfill({ json: new URL(r.request().url()).pathname.endsWith('/user') ? user : session }));
|
||||
await page.route('**/rest/v1/**', async (route: Route) => {
|
||||
const u = new URL(route.request().url());
|
||||
const t = u.pathname.split('/').pop();
|
||||
const method = route.request().method();
|
||||
if (t === 'contacts') return route.fulfill({ json: u.searchParams.has('email') ? contacts[0] : contacts });
|
||||
if (t === 'registrations' && method === 'GET') { h.registrationFetches++; return route.fulfill({ json: h.regs }); }
|
||||
if (t === 'badge_layouts') return route.fulfill({ json: [] });
|
||||
if (t === 'events') {
|
||||
if (method === 'PATCH') {
|
||||
const patch = JSON.parse(route.request().postData() || '{}') as Record<string, unknown>;
|
||||
Object.assign(event, patch);
|
||||
return route.fulfill({ status: 204, json: {} });
|
||||
}
|
||||
return route.fulfill({ json: u.searchParams.has('is_active') ? event : [event] });
|
||||
}
|
||||
if (t === 'rpc' || u.pathname.includes('/rpc/')) return route.fulfill({ json: [] });
|
||||
return route.fulfill({ json: [] });
|
||||
});
|
||||
// PostgREST RPC urls end with the function name, so the check-in write is
|
||||
// matched here (registered after, so it wins over the catch-all above).
|
||||
await page.route('**/rpc/set_registration_checked_in*', async (route: Route) => {
|
||||
if (h.setCheckedInDelayMs) await new Promise((r) => setTimeout(r, h.setCheckedInDelayMs));
|
||||
const body = JSON.parse(route.request().postData() || '{}') as { p_registration_id: string; p_checked_in: boolean };
|
||||
const row = h.regs.find((x) => x.id === body.p_registration_id);
|
||||
const removed = row && !body.p_checked_in ? row.points : 0;
|
||||
if (row) { row.checked_in = body.p_checked_in; if (!body.p_checked_in) row.points = 0; }
|
||||
return route.fulfill({ json: [{ registration_id: body.p_registration_id, checked_in: body.p_checked_in, points_removed: removed }] });
|
||||
});
|
||||
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=r&type=magiclink`);
|
||||
await expect(page.locator('.nav')).toBeVisible();
|
||||
await page.locator('.nav').getByRole('button', { name: new RegExp(view) }).click();
|
||||
}
|
||||
|
||||
const rows = (page: Page) => page.locator('table.data tbody tr');
|
||||
const order = (page: Page) => rows(page).locator('.cell-person .n').allTextContents();
|
||||
const rowToggle = (page: Page, rowText: string) =>
|
||||
rows(page).filter({ hasText: rowText }).first().locator('.toggle .track');
|
||||
|
||||
test.describe('Registrations check-in toggle', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 });
|
||||
});
|
||||
|
||||
test('toggling does not refetch the list, so rows keep their order', async ({ page }) => {
|
||||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||||
await openAdmin(page, 'Registrations', h);
|
||||
await expect(rows(page)).toHaveCount(4);
|
||||
const before = await order(page);
|
||||
const fetchesAfterLoad = h.registrationFetches;
|
||||
|
||||
await rowToggle(page, 'Ann A').click();
|
||||
await expect(page.getByText(/Ann A: checked in/)).toBeVisible();
|
||||
|
||||
// The whole point: no list reload, therefore no re-sort and no jumping row.
|
||||
expect(h.registrationFetches, 'the toggle must not refetch registrations').toBe(fetchesAfterLoad);
|
||||
expect(await order(page)).toEqual(before);
|
||||
// The row still shows the new state.
|
||||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
|
||||
});
|
||||
|
||||
test('only the toggled row is busy; the rest of the table stays usable', async ({ page }) => {
|
||||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 1500 };
|
||||
await openAdmin(page, 'Registrations', h);
|
||||
await expect(rows(page)).toHaveCount(4);
|
||||
|
||||
await rowToggle(page, 'Ann A').click();
|
||||
|
||||
// In flight: the touched row says so and its controls pause.
|
||||
const busyRow = rows(page).filter({ hasText: 'Ann A' }).first();
|
||||
await expect(busyRow.getByTestId('saving-r1')).toBeVisible();
|
||||
await expect(busyRow.locator('input[type=checkbox]')).toBeDisabled();
|
||||
// Optimistic value is already shown, so the click feels instant.
|
||||
await expect(busyRow.locator('input[type=checkbox]')).toBeChecked();
|
||||
|
||||
// Other rows are untouched — not disabled, no busy marker.
|
||||
const otherRow = rows(page).filter({ hasText: 'Bob B' }).first();
|
||||
await expect(otherRow.locator('input[type=checkbox]')).toBeEnabled();
|
||||
await expect(otherRow.locator('.row-saving')).toHaveCount(0);
|
||||
await expect(otherRow.locator('select')).toBeEnabled();
|
||||
// The event selector is not frozen either.
|
||||
await expect(page.locator('select.input').first()).toBeEnabled();
|
||||
|
||||
// And a second row can be toggled while the first one is still saving.
|
||||
await rowToggle(page, 'Cid C').click();
|
||||
await expect(rows(page).filter({ hasText: 'Cid C' }).getByTestId('saving-r3')).toBeVisible();
|
||||
|
||||
await expect(page.locator('.row-saving')).toHaveCount(0, { timeout: 10_000 });
|
||||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
|
||||
await expect(rows(page).filter({ hasText: 'Cid C' }).locator('input[type=checkbox]')).toBeChecked();
|
||||
});
|
||||
|
||||
test('un-checking removes the check-in points on that row', async ({ page }) => {
|
||||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||||
h.regs[1].checked_in = true; // Bob already checked in with 30 pts
|
||||
await openAdmin(page, 'Registrations', h);
|
||||
await expect(rows(page).filter({ hasText: 'Bob B' })).toContainText('30');
|
||||
|
||||
await rowToggle(page, 'Bob B').click();
|
||||
await expect(page.getByText(/un-checked in, −30/)).toBeVisible();
|
||||
await expect(rows(page).filter({ hasText: 'Bob B' })).toContainText('0');
|
||||
await expect(rows(page).filter({ hasText: 'Bob B' }).locator('input[type=checkbox]')).not.toBeChecked();
|
||||
});
|
||||
|
||||
test('a rejected toggle rolls the checkbox back', async ({ page }) => {
|
||||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||||
await openAdmin(page, 'Registrations', h);
|
||||
// Make the backend refuse the write.
|
||||
await page.unroute('**/rpc/set_registration_checked_in*');
|
||||
await page.route('**/rpc/set_registration_checked_in*', (route) =>
|
||||
route.fulfill({ status: 400, json: { message: 'This attendee needs to be checked in at the front desk first.' } }));
|
||||
|
||||
await rowToggle(page, 'Ann A').click();
|
||||
await expect(page.getByText(/front desk/)).toBeVisible();
|
||||
// The optimistic flip must not survive a failed write.
|
||||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).not.toBeChecked();
|
||||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('.row-saving')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('changing the pass type does not refetch or reorder the table', async ({ page }) => {
|
||||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||||
await openAdmin(page, 'Registrations', h);
|
||||
await page.route('**/rpc/set_registration_type*', (route) =>
|
||||
route.fulfill({ json: { ...h.regs[0], type: 'sponsor' } }));
|
||||
await expect(rows(page)).toHaveCount(4);
|
||||
const before = await order(page);
|
||||
const fetches = h.registrationFetches;
|
||||
|
||||
await rows(page).filter({ hasText: 'Ann A' }).first().locator('select').selectOption('staff');
|
||||
await expect(page.getByText(/Ann A → staff/)).toBeVisible();
|
||||
|
||||
expect(h.registrationFetches).toBe(fetches);
|
||||
expect(await order(page)).toEqual(before);
|
||||
await expect(rows(page).filter({ hasText: 'Ann A' }).first().locator('select')).toHaveValue('staff');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Settings — badge copies', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1280, height: 900 });
|
||||
});
|
||||
|
||||
test('the active event controls how many labels a welcome check-in prints', async ({ page }) => {
|
||||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||||
await openAdmin(page, 'Settings', h);
|
||||
const section = page.getByTestId('settings-badge-printing');
|
||||
await expect(section).toBeVisible();
|
||||
const picker = section.getByTestId('badge-copies');
|
||||
|
||||
// Default 1, and exactly four choices (1..4) — no free-text to mistype.
|
||||
await expect(picker.getByRole('button')).toHaveCount(4);
|
||||
await expect(picker.locator('button.active')).toHaveText('1');
|
||||
|
||||
await picker.getByRole('button', { name: '3', exact: true }).click();
|
||||
await expect(section.getByTestId('badge-copies-save')).toBeEnabled();
|
||||
await section.getByTestId('badge-copies-save').click();
|
||||
await expect(section.getByTestId('badge-copies-save')).toHaveText('Copies saved');
|
||||
// Persisted on the event.
|
||||
expect(event.badge_copies).toBe(3);
|
||||
|
||||
// Save is disabled when there is nothing to save.
|
||||
await expect(section.getByTestId('badge-copies-save')).toBeDisabled();
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,7 @@ const targetId = '22222222-2222-4222-8222-222222222222';
|
||||
const otherId = '33333333-3333-4333-8333-333333333333';
|
||||
const manualId = '44444444-4444-4444-8444-444444444444';
|
||||
|
||||
async function openRegistrations(page: Page, options: { patchFailure?: boolean; mergeFailure?: boolean } = {}) {
|
||||
async function openRegistrations(page: Page, options: { checkinFailure?: boolean; mergeFailure?: boolean } = {}) {
|
||||
const user = { id: '99999999-9999-4999-8999-999999999999', email: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
|
||||
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
|
||||
const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'mock-refresh-token', expires_in: 3600, token_type: 'bearer' };
|
||||
@@ -43,13 +43,16 @@ async function openRegistrations(page: Page, options: { patchFailure?: boolean;
|
||||
}
|
||||
if (table === 'contacts') return route.fulfill({ json: url.searchParams.has('email') ? contacts[0] : contacts });
|
||||
if (table === 'events') return route.fulfill({ json: url.searchParams.has('is_active') ? event : [event] });
|
||||
// The check-in toggle goes through the set_registration_checked_in RPC
|
||||
// (the single admin path — it also reverses check-in points), not a PATCH.
|
||||
if (table === 'set_registration_checked_in') {
|
||||
const body = route.request().postDataJSON() as { p_registration_id: string; p_checked_in: boolean };
|
||||
if (options.checkinFailure) return route.fulfill({ status: 500, json: { message: 'Check-in failed' } });
|
||||
const row = registrations.find((r) => r.id === body.p_registration_id);
|
||||
registrations = registrations.map(r => r.id === body.p_registration_id ? { ...r, checked_in: body.p_checked_in } : r);
|
||||
return route.fulfill({ json: [{ registration_id: body.p_registration_id, checked_in: body.p_checked_in, points_removed: 0 }] });
|
||||
}
|
||||
if (table === 'registrations') {
|
||||
if (route.request().method() === 'PATCH') {
|
||||
if (options.patchFailure) return route.fulfill({ status: 500, json: { message: 'Check-in failed' } });
|
||||
const id = url.searchParams.get('id')!.replace('eq.', '');
|
||||
registrations = registrations.map(row => row.id === id ? { ...row, ...route.request().postDataJSON() } : row);
|
||||
return route.fulfill({ json: { id } });
|
||||
}
|
||||
return route.fulfill({ json: registrations });
|
||||
}
|
||||
return route.fulfill({ json: [] });
|
||||
@@ -71,7 +74,7 @@ test('counts only QR tickets and check-in slides without refresh', async ({ page
|
||||
});
|
||||
|
||||
test('failed check-in rolls the toggle back', async ({ page }) => {
|
||||
await openRegistrations(page, { patchFailure: true });
|
||||
await openRegistrations(page, { checkinFailure: true });
|
||||
const row = page.getByRole('row').filter({ hasText: '[email protected]' });
|
||||
await row.locator('label.toggle').click();
|
||||
await expect(page.getByText('Check-in failed', { exact: true })).toBeVisible();
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import { test, expect } from './base';
|
||||
import { APP_URL, EVENT_ID, ID } from '../src/helpers/config';
|
||||
import { login } from '../src/helpers/auth';
|
||||
import { db, psql, sqlQuote } from '../src/helpers/db';
|
||||
import { ScanPage } from '../src/pages/ScanPage';
|
||||
|
||||
/**
|
||||
* Welcome check-in prints `events.badge_copies` labels (1..4, default 1), and
|
||||
* the confirmation popup states that number so staff are not surprised by a
|
||||
* small run of labels. A manual reprint always prints one, and a second welcome
|
||||
* scan of an already-checked-in attendee prints nothing.
|
||||
*
|
||||
* The suite provisions its own attendee + badge layout: printing depends on the
|
||||
* event having a layout with elements, which is operator data and not seeded.
|
||||
*/
|
||||
|
||||
const EMAIL = '[email protected]';
|
||||
const TOKEN = 'CVV-BADGE-COPIES-01';
|
||||
const LAYOUT = 'e2e badge copies layout';
|
||||
|
||||
/** One QR element is enough for a printable payload. */
|
||||
const ELEMENTS = JSON.stringify([{
|
||||
id: 'e2e-qr', type: 'qr', content: 'qr_token', static_value: '', x: 2, y: 2,
|
||||
width: 24, height: 24, rotation: 0,
|
||||
}]);
|
||||
|
||||
function provision(copies: number): void {
|
||||
psql(`insert into public.contacts (email, full_name, is_admin)
|
||||
values (${sqlQuote(EMAIL)}, 'Copies Test', 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(EMAIL)}, 'attendee', false, 0, ${sqlQuote(TOKEN)})
|
||||
on conflict (event_id, contact_email)
|
||||
do update set checked_in = false, points = 0, qr_token = excluded.qr_token`);
|
||||
psql(`insert into public.badge_layouts (event_id, name, is_default, page_width_mm, page_height_mm, elements)
|
||||
values (${sqlQuote(EVENT_ID)}, ${sqlQuote(LAYOUT)}, false, 101, 30, ${sqlQuote(ELEMENTS)}::jsonb)
|
||||
on conflict do nothing`);
|
||||
psql(`update public.events set badge_copies = ${copies}`);
|
||||
clearJobs();
|
||||
}
|
||||
|
||||
function clearJobs(): void {
|
||||
psql(`delete from pgmq.q_badge_print where message->'sample'->>'email' = ${sqlQuote(EMAIL)}`);
|
||||
}
|
||||
|
||||
const queuedLabels = (): number =>
|
||||
Number(psql(`select count(*) from pgmq.q_badge_print
|
||||
where message->'sample'->>'email' = ${sqlQuote(EMAIL)}`) || '0');
|
||||
|
||||
function teardown(): void {
|
||||
clearJobs();
|
||||
psql(`delete from public.badge_layouts where name = ${sqlQuote(LAYOUT)}`);
|
||||
psql(`delete from public.checkins where contact_email = ${sqlQuote(EMAIL)}`);
|
||||
psql(`delete from public.registrations where contact_email = ${sqlQuote(EMAIL)}`);
|
||||
psql(`delete from public.contacts where email = ${sqlQuote(EMAIL)}`);
|
||||
psql(`update public.events set badge_copies = 1`);
|
||||
}
|
||||
|
||||
test.describe('Welcome check-in badge copies', () => {
|
||||
test.afterAll(() => teardown());
|
||||
|
||||
test('CONV-COPIES-001 a welcome check-in queues badge_copies labels', async ({ page }) => {
|
||||
const scan = new ScanPage(page);
|
||||
provision(3);
|
||||
|
||||
await login(page, APP_URL, ID.staff);
|
||||
await page.getByTestId('tab-scan').click();
|
||||
await scan.setStaffMode();
|
||||
await scan.setWelcomeMode();
|
||||
|
||||
await scan.scanCode(TOKEN);
|
||||
await expect(scan.welcomeConfirm()).toBeVisible();
|
||||
// The popup states the real count instead of promising a single label.
|
||||
await expect(scan.welcomeConfirm()).toContainText(/their badge 3 times/i);
|
||||
|
||||
await scan.confirmWelcome();
|
||||
await expect(scan.welcomeResult()).toBeVisible();
|
||||
expect(queuedLabels()).toBe(3);
|
||||
});
|
||||
|
||||
test('CONV-COPIES-002 with copies = 1 the popup keeps the single-label wording', async ({ page }) => {
|
||||
const scan = new ScanPage(page);
|
||||
provision(1);
|
||||
|
||||
await login(page, APP_URL, ID.staff);
|
||||
await page.getByTestId('tab-scan').click();
|
||||
await scan.setStaffMode();
|
||||
await scan.setWelcomeMode();
|
||||
|
||||
await scan.scanCode(TOKEN);
|
||||
await expect(scan.welcomeConfirm()).toContainText(/label/i);
|
||||
await expect(scan.welcomeConfirm()).not.toContainText(/badge 1 times/i);
|
||||
|
||||
await scan.confirmWelcome();
|
||||
await expect(scan.welcomeResult()).toBeVisible();
|
||||
expect(queuedLabels()).toBe(1);
|
||||
});
|
||||
|
||||
test('CONV-COPIES-003 welcoming an already checked-in attendee prints nothing', async ({ page }) => {
|
||||
const scan = new ScanPage(page);
|
||||
provision(4); // even at the maximum, a repeat must not print
|
||||
|
||||
await login(page, APP_URL, ID.staff);
|
||||
await page.getByTestId('tab-scan').click();
|
||||
await scan.setStaffMode();
|
||||
await scan.setWelcomeMode();
|
||||
|
||||
// First welcome prints 4.
|
||||
await scan.scanCode(TOKEN);
|
||||
await scan.confirmWelcome();
|
||||
await expect(scan.welcomeResult()).toBeVisible();
|
||||
expect(queuedLabels()).toBe(4);
|
||||
await scan.dismissResult();
|
||||
|
||||
// Second welcome: flagged as already checked in, nothing added to the queue.
|
||||
await scan.scanCode(TOKEN);
|
||||
await expect(scan.welcomeConfirm()).toContainText(/Already checked in/i);
|
||||
await scan.confirmWelcome();
|
||||
await expect(scan.welcomeResult()).toBeVisible();
|
||||
expect(queuedLabels()).toBe(4);
|
||||
|
||||
expect(db.isWelcomeCheckedIn(EMAIL)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user