Files
Convivo/e2e/tests/welcome-badge-copies.spec.ts
17473916a6 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]>
2026-10-19 15:10:20 +02:00

125 lines
4.9 KiB
TypeScript

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);
});
});