The front-desk check-in set checked_in and printed badges but awarded nothing, so the +10 depended on which check-in a person happened to get. Every award path was reviewed: - welcome_checkin awards +10 (category checkin) on a genuine first check-in and returns points + points_awarded; checkin_attendee and preview_welcome_checkin return points_awarded too. - set_registration_checked_in(false) deleted all checkin points while keeping the checkins rows, and switching back on awarded nothing -- one mistaken toggle destroyed those points permanently. ON now recomputes from the rows that still exist and awards only the shortfall: reversible, still unfarmable. - The staff/Admin/@appe.at exclusion stays (product decision) but is no longer silent: three-way points sheets in the scanner, "no points" with a tooltip in Registrations, and the Contacts points modal refuses to apply rather than letting adjust_points (void) no-op quietly. Also in this change: - admin silent refresh (5s poll + 500ms after writes) across all data views; Registrations patches in place so rows never slide under the cursor - Settings "Validate AI connection" via a new sidecar POST /llm-test verdict endpoint (never leaks the key, distinguishes "no usage block" from "off") - new Sessions view between Schedule and Activity: speakers, attendance, ratings, attendee filter, and one button that summarises every session with feedback (one request each, concurrency 3, UI blocked until all settle) - provider requests disable thinking through one shared body builder sending both reasoning_effort:"none" and chat_template_kwargs.enable_thinking SQL: 113 / 57 / 24 assertions (set_registration_checked_in section 3 was rewritten, it asserted the bug). Sidecar 34 unit tests. Full e2e 202 passed, 0 failed. Migration applied locally only -- not deployed.
248 lines
14 KiB
TypeScript
248 lines
14 KiB
TypeScript
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' | 'Contacts', 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 reload on the write path, therefore no re-sort and no
|
||
// jumping row. The checkbox still shows the new state.
|
||
expect(h.registrationFetches, 'the toggle must not refetch registrations').toBe(fetchesAfterLoad);
|
||
expect(await order(page)).toEqual(before);
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
|
||
|
||
// The silent pull does arrive (500 ms after the write), and this is the other
|
||
// half of the promise: it patches in place instead of reordering or blanking.
|
||
await expect.poll(() => h.registrationFetches, { timeout: 5_000 }).toBeGreaterThan(fetchesAfterLoad);
|
||
await expect(rows(page)).toHaveCount(4);
|
||
expect(await order(page)).toEqual(before);
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).locator('input[type=checkbox]')).toBeChecked();
|
||
});
|
||
|
||
test('a staff row says why it has no points instead of showing 0', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
h.regs[3].points = 0; // Dee D, type staff — never earns anything
|
||
await openAdmin(page, 'Registrations', h);
|
||
|
||
const staffRow = rows(page).filter({ hasText: 'Dee D' }).first();
|
||
await expect(staffRow.getByTestId('points-exempt-r4')).toBeVisible();
|
||
await expect(staffRow.getByTestId('points-exempt-r4')).toContainText('no points');
|
||
// Attendees keep the plain number.
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).first().locator('.pts')).toHaveText('40');
|
||
await expect(rows(page).filter({ hasText: 'Ann A' }).first().getByTestId('points-exempt-r1')).toHaveCount(0);
|
||
});
|
||
|
||
test('restoring check-in on a row that lost its points reports the award', async ({ page }) => {
|
||
const h: Harness = { regs: mkRegs(), registrationFetches: 0, setCheckedInDelayMs: 0 };
|
||
// The toggle had been switched off before, so points sit at 0 while the
|
||
// server still counts real check-in rows: restoring must top up, not zero.
|
||
h.regs[1].checked_in = false;
|
||
h.regs[1].points = 0;
|
||
await openAdmin(page, 'Registrations', h);
|
||
// Registered after openAdmin's handler so it wins (Playwright matches the
|
||
// most recently added route first).
|
||
await page.route('**/rpc/set_registration_checked_in*', (route) =>
|
||
route.fulfill({ json: [{ registration_id: 'r2', checked_in: true, points_removed: 0, points_added: 20 }] }));
|
||
|
||
await rowToggle(page, 'Bob B').click();
|
||
await expect(page.getByText(/\+20 check-in pts restored/)).toBeVisible();
|
||
await expect(rows(page).filter({ hasText: 'Bob B' }).locator('.pts')).toHaveText('20');
|
||
});
|
||
|
||
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();
|
||
});
|
||
});
|