Files
Convivo/e2e/tests/convivo-admin-entry.spec.ts
a81ec4b787 fix(convivo): readable descriptions, no feedback UI on service sessions, no demo-clock badge
Three attendee-app polish items from hands-on testing (Sabrina). All
presentation-layer: no migration, no RPC, no admin/sidecar change.

- Session detail collapsed multi-paragraph descriptions into one block. The
  feed carries real newlines (the sidecar passes Sessionize description through
  untouched), so this was pure CSS: new .sd-desc uses white-space: pre-line.
  The AI feedback summary gets the same via .feedback-review .fr-text.
- Staff saw "Your session feedback" on Break/Lunch cards, because
  _assign_service_session_speakers makes every staff member a speaker of every
  service slot. showFeedback = !isService now gates all three feedback surfaces
  (review block, Give-feedback button, "not checked in" note). The sheet itself
  stays openable for service sessions.
- Removed the "Demo clock" badge from the Home header. The simulated clock is an
  internal demo aid; attendees were never meant to see it. useEvent() still
  exposes clockMode and the admin toggle is unchanged.

Tests: three new API-mocked cases in convivo-admin-entry.spec.ts (service
feedback suppression, multi-line description via pre-line CSS + exact textContent
+ rendered-height comparison, no demo-clock badge per clock mode). 45/45 green
against the local dev server; attendee build clean.

Docs synced: screens.md, app-structure.md, backend/tests.md, next-steps.md, plus
a release record at docs/releases/2026-10-18.md noting that items 1/3/7 of the
report were already shipped (84d3922, 2aa2b89) and that this change is not yet
deployed.

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-18 18:20:16 +02:00

680 lines
42 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect, type Page } from '@playwright/test';
const appUrl = process.env.CONVIVO_BASE_URL || 'http://localhost:3000';
const notice = 'If this email belongs to an eligible admin account, a sign-in link has been sent.';
const invalidLink = 'This sign-in link is invalid or expired. Please request a new link.';
test.describe('Service agenda', () => {
for (const width of [360, 1280]) {
test(`orders supplemental services and retains staff names through filters at ${width}px`, async ({ page }, testInfo) => {
await page.setViewportSize({ width, height: 900 });
const { session } = await mockApi(page, { registered: true, checkedIn: true });
const staffNames = 'Staff One, Staff Two, Staff Three, Staff Four';
const rows = [
{ slot_id: 1, start_time: '10:15:00', end_time: '11:00:00', title: 'Advanced Talk', slot_type: 'session', level: 'Advanced', speakers: 'Talk Speaker' },
{ slot_id: 2, start_time: '11:15:00', end_time: '12:00:00', title: 'Beginner Talk', slot_type: 'session', level: 'Beginner', speakers: 'Talk Speaker' },
{ slot_id: 902, start_time: '11:15:00', end_time: '12:00:00', title: 'Placeholder', slot_type: 'service_session', level: null, speakers: staffNames },
{ slot_id: 901, start_time: '12:00:00', end_time: '13:00:00', title: 'Lunch', slot_type: 'service_session', level: null, speakers: staffNames },
{ slot_id: 900, start_time: '08:30:00', end_time: '09:00:00', title: 'Arrival & Coffee', slot_type: 'service_session', level: null, speakers: staffNames },
].map(row => ({ ...row, session_id: `session-${row.slot_id}`, slot_name: row.title,
slot_date: '2026-02-20', room: '', description: '', material_path: null, capacity: null,
average_feedback: null, ai_generated_feedback: null, area: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
await page.route('**/rest/v1/session_speakers**', route => route.fulfill({ json: [{ session_id: 'session-902' }] }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await page.getByTestId('tab-agenda').click();
await expect(page.locator('.sess .title')).toHaveText(['Arrival & Coffee', 'Advanced Talk', 'Beginner Talk', 'Placeholder', 'Lunch']);
await expect(page.locator('.slot-card')).toHaveCount(4);
await expect(page.getByText('4 slots', { exact: true })).toBeVisible();
const talkBlock = page.locator('.slot-card').filter({ has: page.locator('.sess .title', { hasText: 'Beginner Talk' }) });
await expect(talkBlock.locator('.sess .title')).toHaveText(['Beginner Talk', 'Placeholder']);
const placeholder = page.locator('.sess').filter({ has: page.locator('.title', { hasText: 'Placeholder' }) });
await expect(placeholder.locator('.check')).toHaveCount(0);
await expect(page.locator('.sess .meta').filter({ hasText: staffNames })).toHaveCount(3);
await page.getByLabel('Filter by level').selectOption('Beginner');
await expect(page.locator('.sess .title')).toHaveText(['Arrival & Coffee', 'Beginner Talk', 'Placeholder', 'Lunch']);
await expect(page.locator('.sess .meta').filter({ hasText: staffNames })).toHaveCount(3);
await page.locator('.screen').evaluate(screen => { screen.scrollTop = 0; });
await page.screenshot({ path: testInfo.outputPath(`service-agenda-${width}.png`), fullPage: true });
await page.getByLabel('Filter by level').selectOption('Advanced');
await expect(page.locator('.sess .title')).toHaveText(['Arrival & Coffee', 'Advanced Talk', 'Placeholder', 'Lunch']);
await placeholder.click();
await expect(page.getByText('No pick needed for this slot.', { exact: true })).toBeVisible();
await expect(page.getByRole('button', { name: 'Pick this session', exact: true })).toHaveCount(0);
await expect(page.getByTestId('material-upload-notice')).toHaveCount(0);
});
}
test('merges only Placeholders with the exact same date and start/end times', async ({ page }) => {
const { session } = await mockApi(page, { registered: true, checkedIn: true });
const rows = [
{ slot_id: 1, title: 'Talk', slot_type: 'session', room: 'Talk room', slot_date: '2026-02-20', end_time: '12:00:00' },
{ slot_id: 2, title: 'Placeholder', slot_type: 'service_session', room: 'Matching room', slot_date: '2026-02-20', end_time: '12:00:00' },
{ slot_id: 3, title: 'Placeholder', slot_type: 'service_session', room: 'Next day room', slot_date: '2026-02-21', end_time: '12:00:00' },
{ slot_id: 4, title: 'Placeholder', slot_type: 'service_session', room: 'Different end room', slot_date: '2026-02-20', end_time: '12:30:00' },
{ slot_id: 5, title: 'Lunch', slot_type: 'service_session', room: 'Lunch room', slot_date: '2026-02-20', end_time: '12:00:00' },
].map(row => ({ ...row, session_id: `session-${row.slot_id}`, slot_name: row.title, start_time: '11:15:00',
speakers: 'Staff', description: '', material_path: null, capacity: null, average_feedback: null,
ai_generated_feedback: null, level: null, area: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await page.getByTestId('tab-agenda').click();
await expect(page.locator('.slot-card')).toHaveCount(4);
const talkBlock = page.locator('.slot-card').filter({ has: page.locator('.sess .title', { hasText: /^Talk$/ }) });
await expect(talkBlock.locator('.sess .title')).toHaveText(['Talk', 'Placeholder']);
await expect(talkBlock.getByText('Matching room', { exact: false })).toBeVisible();
await expect(talkBlock.getByText('Next day room', { exact: false })).toHaveCount(0);
await expect(talkBlock.getByText('Different end room', { exact: false })).toHaveCount(0);
await expect(talkBlock.getByText('Lunch room', { exact: false })).toHaveCount(0);
});
test('hides an orphan service slot that has no session behind it', async ({ page }) => {
const { session } = await mockApi(page, { registered: true, checkedIn: true });
// get_agenda LEFT JOINs sessions onto slots, so an orphan service slot
// arrives as a row with the slot fields set but a null session. It must not
// render a header-only card (the inconsistency), while real service slots
// and talk slots stay.
const rows = [
{ slot_id: 1, slot_name: 'Arrival & Coffee', start_time: '08:30:00', end_time: '09:00:00', slot_type: 'service_session', session_id: 'session-1', title: 'Arrival & Coffee', room: 'Main', speakers: 'Staff' },
{ slot_id: 2, slot_name: 'Slot 10:15–11:00', start_time: '10:15:00', end_time: '11:00:00', slot_type: 'session', session_id: 'session-2', title: 'A Talk', room: 'Main', speakers: 'Speaker' },
{ slot_id: 67, slot_name: 'Service Session', start_time: '11:15:00', end_time: '12:00:00', slot_type: 'service_session', session_id: null, title: null, room: null, speakers: null },
{ slot_id: 3, slot_name: 'Lunch', start_time: '12:00:00', end_time: '13:00:00', slot_type: 'service_session', session_id: 'session-3', title: 'Lunch', room: 'Main', speakers: 'Staff' },
].map(row => ({ ...row, slot_date: '2026-02-20', description: '', material_path: null, capacity: null,
average_feedback: null, ai_generated_feedback: null, level: null, area: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await page.getByTestId('tab-agenda').click();
await expect(page.locator('.slot-card')).toHaveCount(3);
await expect(page.getByText('3 slots', { exact: true })).toBeVisible();
await expect(page.locator('.slot-card').filter({ hasText: '11:15' })).toHaveCount(0);
await expect(page.locator('.sess .title')).toHaveText(['Arrival & Coffee', 'A Talk', 'Lunch']);
});
// Every staff member is auto-assigned as a speaker of a service slot, so
// without an explicit guard a staff user gets a "Your session feedback" block
// (and the checked-in feedback entry) on a break/lunch card. Feedback never
// applies to a service session: it cannot be checked into.
test('service session detail shows no feedback UI for a staff speaker', async ({ page }) => {
const { session } = await mockApi(page, { registered: true, checkedIn: true, staff: true });
const rows = [
{ slot_id: 1, slot_name: 'Lunch', start_time: '08:30:00', end_time: '09:00:00', slot_type: 'service_session',
session_id: 'session-1', title: 'Lunch', room: 'Main', speakers: 'Staff One, Staff Two' },
].map(row => ({ ...row, slot_date: '2026-02-20', description: 'Lunch is served.', material_path: null, capacity: null,
average_feedback: 4.5, ai_generated_feedback: 'Guests liked the coffee.', level: null, area: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
// The staff contact is the assigned speaker of the (finished) service slot.
await page.route('**/rest/v1/session_speakers**', route => route.fulfill({ json: [{ session_id: 'session-1' }] }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await page.getByTestId('tab-agenda').click();
await page.locator('.sess .title', { hasText: /^Lunch$/ }).click();
// The sheet still opens with the basic facts…
await expect(page.locator('.sheet h3')).toHaveText('Lunch');
await expect(page.getByText('No pick needed for this slot.', { exact: true })).toBeVisible();
// …but no feedback surface of any kind.
await expect(page.getByText('Your session feedback')).toHaveCount(0);
await expect(page.getByTestId('give-feedback')).toHaveCount(0);
await expect(page.getByText('You weren’t checked in to this session.')).toHaveCount(0);
});
});
test.describe('Home session picks', () => {
test('tapping a pick opens its session detail in place instead of routing to the Agenda', async ({ page }) => {
const { session } = await mockApi(page, {
registered: true, checkedIn: true,
picks: [{ slot_id: 1, session_id: 'session-1' }],
});
const rows = [
{ slot_id: 1, slot_name: 'Slot 10:15–11:00', start_time: '10:15:00', end_time: '11:00:00', slot_type: 'session',
session_id: 'session-1', title: 'My Picked Talk', room: 'Room A', speakers: 'Ada Lovelace',
description: 'Deep dive into picks.', level: 'Beginner', area: 'Power Apps' },
{ slot_id: 2, slot_name: 'Slot 11:15–12:00', start_time: '11:15:00', end_time: '12:00:00', slot_type: 'session',
session_id: 'session-2', title: 'Other Talk', room: 'Room B', speakers: 'Grace Hopper',
description: '', level: null, area: null },
].map(row => ({ ...row, slot_date: '2026-02-20', material_path: null, capacity: null,
average_feedback: null, ai_generated_feedback: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByTestId('tab-home')).toHaveClass(/active/);
const chip = page.getByTestId('home-pick');
await expect(chip).toHaveCount(1);
await expect(chip).toContainText('My Picked Talk');
await chip.click();
// The same detail sheet the Agenda shows, opened over Home.
await expect(page.locator('.sheet h3')).toHaveText('My Picked Talk');
await expect(page.locator('#sd-desc')).toHaveText('Deep dive into picks.');
// The auto slot name ("Slot 10:15–11:00") only repeats the time range, so
// the subtitle must not show it twice.
await expect(page.locator('.sheet .sub')).toHaveText('10:15–11:00 · Room A');
await expect(page.locator('.sheet')).toContainText('10:15–11:00');
await expect(page.locator('.sheet')).toContainText('Room A');
await expect(page.locator('.sheet')).toContainText('Ada Lovelace');
await expect(page.locator('.sheet')).toContainText('📶 Beginner');
// It is the user's pick, so the sheet offers to remove it.
await expect(page.getByRole('button', { name: 'Remove my pick', exact: true })).toBeVisible();
await expect(page.getByRole('button', { name: 'Pick this session', exact: true })).toHaveCount(0);
// Still on Home — no round trip to the Agenda tab.
await expect(page.getByTestId('tab-home')).toHaveClass(/active/);
await expect(page.getByTestId('tab-agenda')).not.toHaveClass(/active/);
await page.locator('.sheet').getByRole('button', { name: '✕', exact: true }).click();
await expect(page.locator('.sheet')).toHaveCount(0);
await expect(page.getByTestId('home-pick')).toHaveCount(1);
});
// Sessionize/Excel descriptions carry real paragraphs; without pre-line they
// collapse into one hard-to-read block.
test('keeps the paragraph breaks of a multi-line description', async ({ page }) => {
const { session } = await mockApi(page, {
registered: true, checkedIn: true,
picks: [{ slot_id: 1, session_id: 'session-1' }],
});
const rows = [
{ slot_id: 1, slot_name: 'Slot 10:15–11:00', start_time: '10:15:00', end_time: '11:00:00', slot_type: 'session',
session_id: 'session-1', title: 'Wrapped Talk', room: 'Room A', speakers: 'Ada Lovelace',
description: 'First paragraph.\n\nSecond paragraph.\nA single break.', level: null, area: null },
].map(row => ({ ...row, slot_date: '2026-02-20', material_path: null, capacity: null,
average_feedback: null, ai_generated_feedback: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await page.getByTestId('home-pick').click();
const desc = page.locator('#sd-desc');
await expect(desc).toHaveCSS('white-space', 'pre-line');
// The newlines survive in the DOM…
await expect(desc.evaluate((el) => el.textContent)).resolves.toBe(
'First paragraph.\n\nSecond paragraph.\nA single break.',
);
// …and they actually break the lines (the block is taller than the same
// text rendered with collapsed whitespace).
const heightWith = (whiteSpace: string) => desc.evaluate(
(el, value) => {
const node = el as HTMLElement;
const previous = node.style.whiteSpace;
node.style.whiteSpace = value;
const height = node.getBoundingClientRect().height;
node.style.whiteSpace = previous;
return height;
},
whiteSpace,
);
expect(await heightWith('pre-line')).toBeGreaterThan(await heightWith('normal'));
});
// The Now/Next card lists concurrent sessions when the user has no pick for
// that specific slot. Its "No pick yet" nudge must disappear once the user
// has any pick at all — otherwise it contradicts the "My picks today" list
// shown right below it (the reported bug).
const nowNextRows = [
{ slot_id: 1, slot_name: 'Slot 10:15–11:00', start_time: '10:15:00', end_time: '11:00:00', slot_type: 'session',
session_id: 'session-1', title: 'Now Talk', room: 'Room A', speakers: 'Ada Lovelace' },
{ slot_id: 2, slot_name: 'Slot 11:15–12:00', start_time: '11:15:00', end_time: '12:00:00', slot_type: 'session',
session_id: 'session-2', title: 'Next Talk', room: 'Room B', speakers: 'Grace Hopper' },
].map(row => ({ ...row, slot_date: '2026-02-20', description: '', material_path: null, capacity: null,
average_feedback: null, ai_generated_feedback: null, level: null, area: null }));
test('hides the "No pick yet" nudge once the user has any pick', async ({ page }) => {
const { session } = await mockApi(page, {
registered: true, checkedIn: true,
picks: [{ slot_id: 2, session_id: 'session-2' }],
});
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: nowNextRows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByTestId('tab-home')).toHaveClass(/active/);
// The pick lives on the Next slot, so the Now card falls back to the
// concurrent-session list — and must not nag about having no pick.
await expect(page.getByTestId('home-pick')).toHaveCount(1);
await expect(page.locator('.now-card')).toContainText('Now Talk');
await expect(page.getByText('No pick yet — tap a session in the Agenda to choose.')).toHaveCount(0);
});
test('still shows the "No pick yet" nudge when the user has no picks', async ({ page }) => {
const { session } = await mockApi(page, { registered: true, checkedIn: true });
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: nowNextRows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByTestId('tab-home')).toHaveClass(/active/);
await expect(page.getByTestId('home-pick')).toHaveCount(0);
await expect(page.locator('.now-card')).toContainText('Now Talk');
// Both the Now and the Next card fall back to the concurrent list, so the
// nudge is asserted per card rather than page-wide.
await expect(page.locator('.now-card').getByText('No pick yet — tap a session in the Agenda to choose.')).toBeVisible();
});
});
test.describe('Event demo clock', () => {
for (const scenario of [
{ eventDate: '2026-10-23', realtimeClock: false },
{ eventDate: '2027-05-10', realtimeClock: false },
{ eventDate: '2026-10-23', realtimeClock: true },
]) {
test(`uses ${scenario.realtimeClock ? 'system' : 'event'} date for ${scenario.eventDate}`, async ({ page }) => {
await page.clock.setFixedTime(new Date('2028-01-01T10:20:00'));
const { session } = await mockApi(page, { registered: true, checkedIn: true, ...scenario });
const rows = [
{ slot_id: 1, title: 'Morning service', start_time: '08:30:00', end_time: '09:00:00', slot_type: 'service_session' },
{ slot_id: 2, title: 'Current talk', start_time: '10:15:00', end_time: '11:00:00', slot_type: 'session' },
{ slot_id: 3, title: 'Later talk', start_time: '11:15:00', end_time: '12:00:00', slot_type: 'session' },
].map(row => ({ ...row, session_id: `clock-${row.slot_id}`, slot_name: row.title, slot_date: scenario.eventDate,
room: '', speakers: 'Staff', description: '', material_path: null, capacity: null,
average_feedback: null, ai_generated_feedback: null, level: null, area: null }));
await page.route('**/rest/v1/rpc/get_agenda', route => route.fulfill({ json: rows }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await page.getByTestId('tab-agenda').click();
const status = (title: string) => page.locator('.slot-card').filter({
has: page.locator('.sess .title', { hasText: new RegExp(`^${title}$`) }),
}).locator('.slot-head .pill').last();
await expect(status('Morning service')).toHaveText('Done');
await expect(status('Current talk')).toHaveText(scenario.realtimeClock ? 'Done' : '● Live');
await expect(status('Later talk')).toHaveText(scenario.realtimeClock ? 'Done' : 'Up next');
// The simulated clock is an internal demo aid only — the Home header must
// never advertise it to attendees, in either mode.
await page.getByTestId('tab-home').click();
await expect(page.getByText('Demo clock')).toHaveCount(0);
});
}
});
test.describe('Profile Manfred', () => {
for (const viewport of [{ width: 360, height: 800 }, { width: 1280, height: 900 }]) {
test(`randomizes on entry and refresh without shifting the layout at ${viewport.width}px`, async ({ page }, testInfo) => {
await page.setViewportSize(viewport);
await page.addInitScript(() => {
Math.random = () => Number(sessionStorage.getItem('test-manfred-choice') || '0.01');
});
const { session } = await mockApi(page, { registered: true, checkedIn: true });
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByTestId('tab-home')).toBeVisible();
const mascot = page.getByTestId('profile-manfred');
const poses = ['confident', 'coffee', 'celebrating', 'waving'];
for (const [index, pose] of poses.entries()) {
await page.evaluate((choice) => sessionStorage.setItem('test-manfred-choice', String(choice)), (index + 0.1) / 4);
await page.getByTestId('tab-profile').click();
await expect(mascot).toHaveAttribute('src', `/manfred/${pose}.webp`);
await expect.poll(() => mascot.evaluate((image: HTMLImageElement) => image.complete && image.naturalWidth > 0)).toBe(true);
await page.getByTestId('profile-linkedin-url').fill(`https://linkedin.com/in/test-${index}`);
await expect(mascot).toHaveAttribute('src', `/manfred/${pose}.webp`);
await page.locator('.screen').evaluate((screen) => { screen.scrollTop = 0; });
const bounds = await mascot.boundingBox();
expect(bounds).not.toBeNull();
expect(bounds!.y).toBeGreaterThanOrEqual(0);
expect(bounds!.width).toBe(76);
expect(bounds!.height).toBe(76);
expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(viewport.width);
const heading = await page.locator('.screen > div .h1').boundingBox();
expect(heading!.x + heading!.width).toBeLessThan(bounds!.x);
if (index === poses.length - 1) await page.screenshot({ path: testInfo.outputPath(`profile-manfred-${viewport.width}.png`), fullPage: true });
await page.getByTestId('tab-home').click();
await expect(mascot).toHaveCount(0);
}
await page.evaluate(() => sessionStorage.setItem('test-manfred-choice', '0.01'));
await page.reload();
await page.getByTestId('tab-profile').click();
await expect(mascot).toHaveAttribute('src', '/manfred/confident.webp');
});
}
});
function mockSession(email: string) {
const user = {
id: '11111111-1111-4111-8111-111111111111', aud: 'authenticated', role: 'authenticated', email,
app_metadata: {}, user_metadata: { is_admin: true }, created_at: '2026-01-01T00:00:00Z',
};
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
return { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test-signature`, refresh_token: 'mock-refresh-token', token_type: 'bearer', expires_in: 3600 };
}
async function mockApi(page: Page, options: { email?: string; admin?: boolean; registered?: boolean; checkedIn?: boolean; staff?: boolean; eventDate?: string; realtimeClock?: boolean; picks?: { slot_id: number; session_id: string }[] } = {}) {
const email = options.email || '[email protected]';
const session = mockSession(email);
const calls = { users: 0, exchanges: 0, passwords: 0, logouts: 0, otp: 0, lanyards: 0, mutations: [] as string[] };
await page.route('**/auth/v1/**', async (route) => {
const url = new URL(route.request().url());
if (url.pathname.endsWith('/user')) {
calls.users++;
await route.fulfill({ json: session.user });
} else if (url.pathname.endsWith('/token')) {
if (url.searchParams.get('grant_type') === 'pkce') calls.exchanges++;
if (url.searchParams.get('grant_type') === 'password') calls.passwords++;
await route.fulfill({ json: session });
} else if (url.pathname.endsWith('/logout')) {
calls.logouts++;
await route.fulfill({ status: 204 });
} else {
if (url.pathname.endsWith('/otp')) calls.otp++;
await route.fulfill({ json: {} });
}
});
await page.route('**/rest/v1/**', async (route) => {
const request = route.request();
const pathname = new URL(request.url()).pathname;
const readRpc = /\/(is_admin|can_request_admin_magic_link|lanyard_lookup|get_[a-z_]+)$/.test(pathname);
if (request.method() !== 'GET' && !readRpc) calls.mutations.push(pathname);
if (pathname.endsWith('/rpc/can_request_admin_magic_link')) {
expect(request.postDataJSON()).toEqual({ p_email: email.toLowerCase() });
await route.fulfill({ json: options.admin !== false });
}
else if (pathname.endsWith('/rpc/is_admin')) await route.fulfill({ json: options.admin !== false });
else if (pathname.endsWith('/preferences')) {
await route.fulfill({ json: (options.picks ?? []).map((p, index) => ({
id: `pref-${index}`, event_id: '33333333-3333-4333-8333-333333333333',
contact_email: email, session_id: p.session_id, slot_id: p.slot_id,
})) });
}
else if (pathname.endsWith('/contacts')) await route.fulfill({ json: { email, full_name: 'Test Member', is_admin: false, show_email: false, show_linkedin: false } });
else if (pathname.endsWith('/registrations')) {
expect(new URL(request.url()).searchParams.get('event_id')).toBe('eq.33333333-3333-4333-8333-333333333333');
await route.fulfill({ json: options.registered ? {
id: '22222222-2222-4222-8222-222222222222', event_id: '33333333-3333-4333-8333-333333333333',
contact_email: email, type: options.staff ? 'staff' : 'attendee', checked_in: !!options.checkedIn, points: 0, qr_token: 'CVV-TEST-1234',
} : null });
}
else if (pathname.endsWith('/events')) await route.fulfill({ json: {
id: '33333333-3333-4333-8333-333333333333', name: 'Test Event', is_active: true,
start_date: options.eventDate || '2026-02-20', end_date: options.eventDate || '2026-02-20', use_realtime_clock: options.realtimeClock || false,
} });
else if (pathname.endsWith('/rpc/lanyard_lookup')) {
calls.lanyards++;
expect(request.postDataJSON()).toEqual({ p_qr_token: 'CVV-TEST-1234' });
await route.fulfill({ json: [{ email, full_name: 'Test Member', registration_type: options.staff ? 'staff' : 'attendee' }] });
} else await route.fulfill({ json: [] });
});
return { session, calls };
}
async function openEntry(page: Page) {
await page.goto(appUrl);
await page.getByTestId('login-splash').click();
await expect(page.getByLabel('QR Code')).toBeVisible();
await expect(page.getByLabel('QR Code')).toHaveAttribute('placeholder', 'QR Code');
}
test.describe('Convivo admin email entry', () => {
for (const email of ['[email protected]', '[email protected]', '[email protected]']) {
test(`ineligible ${email} gets private confirmation without OTP`, async ({ page }) => {
const { calls } = await mockApi(page, { email, admin: false });
await openEntry(page);
await page.getByLabel('QR Code').fill(email);
await page.getByLabel('QR Code').press('Enter');
await expect(page.getByRole('status')).toHaveText(notice);
expect(calls.otp).toBe(0);
expect(calls.lanyards).toBe(0);
expect(calls.mutations).toEqual([]);
});
}
test('eligibility server failure never sends OTP', async ({ page }) => {
const { calls } = await mockApi(page);
await page.route('**/rest/v1/rpc/can_request_admin_magic_link', (route) => route.fulfill({ status: 401, json: { message: 'Sensitive eligibility detail' } }));
await openEntry(page);
await page.getByLabel('QR Code').fill('[email protected]');
await page.getByTestId('scanner-manual-go').click();
await expect(page.getByRole('alert')).toHaveText('Unable to send a sign-in link right now. Please try again later.');
expect(calls.otp).toBe(0);
await expect(page.getByText('Sensitive eligibility detail')).toHaveCount(0);
});
for (const responseStatus of [400, 422, 429, 500]) {
test(`OTP response ${responseStatus} stays generic and recoverable`, async ({ page }) => {
await mockApi(page);
await page.route('**/auth/v1/otp**', (route) => route.fulfill({ status: responseStatus, json: { message: 'Sensitive account detail' } }));
await openEntry(page);
await page.getByLabel('QR Code').fill('[email protected]');
await page.getByTestId('scanner-manual-go').click();
if (responseStatus === 400 || responseStatus === 422) {
await expect(page.getByRole('status')).toHaveText(notice);
} else {
await expect(page.getByRole('alert')).toHaveText('Unable to send a sign-in link right now. Please try again later.');
await expect(page.getByTestId('scanner-manual-go')).toBeEnabled();
}
await expect(page.getByText('Sensitive account detail')).toHaveCount(0);
await expect(page.getByLabel('QR Code')).toBeEnabled();
});
}
test('same field requests an admin-only link, normalizes email, supports keyboard and resend', async ({ page }) => {
const { calls } = await mockApi(page);
await page.clock.install();
let sends = 0;
await page.route('**/auth/v1/otp**', async (route) => {
sends++;
expect(route.request().postDataJSON()).toMatchObject({ email: '[email protected]', create_user: false });
expect(new URL(route.request().url()).searchParams.get('redirect_to')).toBe(`${appUrl}/auth/callback`);
await route.fulfill({ status: 202, json: { ok: true } });
});
await openEntry(page);
const entry = page.getByLabel('QR Code');
await expect(entry).toHaveAttribute('type', 'text');
await entry.fill(' [email protected] ');
await expect(page.getByTestId('scanner-manual-go')).toHaveText('Send magic link');
await entry.press('Enter');
await expect(page.getByRole('status')).toHaveText(notice);
await expect(page.getByRole('button', { name: 'Resend in 60s' })).toBeDisabled();
await expect(entry).toBeEnabled();
await page.clock.runFor(60_000);
await page.getByRole('button', { name: 'Resend magic link', exact: true }).click();
await expect(page.getByRole('button', { name: 'Resend in 60s' })).toBeDisabled();
expect(sends).toBe(2);
expect(calls.otp).toBe(0);
expect(calls.lanyards).toBe(0);
expect(calls.passwords).toBe(0);
});
test('pending send locks controls and failed resend clears the sent state', async ({ page }) => {
await mockApi(page);
await page.clock.install();
let release!: () => void;
const pending = new Promise<void>((resolve) => { release = resolve; });
let sends = 0;
await page.route('**/auth/v1/otp**', async (route) => {
sends++;
if (sends === 1) { await pending; await route.fulfill({ status: 202, json: {} }); }
else await route.fulfill({ status: 503, json: { error: 'Sensitive server detail' } });
});
await openEntry(page);
await page.getByLabel('QR Code').fill('[email protected]');
await page.getByTestId('scanner-manual-go').click();
await expect(page.getByLabel('QR Code')).toBeDisabled();
await expect(page.getByRole('button', { name: 'Sending...' })).toBeDisabled();
release();
await expect(page.getByRole('status')).toHaveText(notice);
await page.clock.runFor(60_000);
await page.getByRole('button', { name: 'Resend magic link', exact: true }).click();
await expect(page.getByRole('alert')).toHaveText('Unable to send a sign-in link right now. Please try again later.');
await expect(page.getByRole('status')).toHaveCount(0);
await expect(page.getByTestId('scanner-manual-go')).toBeEnabled();
await expect(page.getByText('Sensitive server detail')).toHaveCount(0);
});
test('invalid email and network failures are recoverable without QR lookup', async ({ page }) => {
const { calls } = await mockApi(page);
await page.route('**/auth/v1/otp**', (route) => route.abort());
await openEntry(page);
const entry = page.getByLabel('QR Code');
await entry.fill('admin@');
await entry.press('Enter');
await expect(page.getByRole('alert')).toHaveText('Enter a valid email address.');
await entry.fill('[email protected]');
await entry.press('Enter');
await expect(page.getByRole('alert')).toHaveText('Unable to send a sign-in link right now. Please try again later.');
await expect(entry).toBeEnabled();
expect(calls.lanyards).toBe(0);
expect(calls.otp).toBe(0);
});
for (const registered of [false, true]) {
test(`verified admin callback enters Convivo with registered=${registered}, without attendance writes`, async ({ page }) => {
const { session, calls } = await mockApi(page, { registered, checkedIn: false });
await page.goto(`${appUrl}/auth/callback?next=https://example.org#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByTestId('tab-home')).toBeVisible();
await expect(page.getByTestId('checkin-required-gate')).toHaveCount(0);
await expect(page).toHaveURL(`${appUrl}/`);
await page.getByTestId('tab-scan').click();
await expect(page.getByTestId('scan-mode-staff')).toBeVisible();
await page.reload();
await expect(page.getByTestId('tab-home')).toBeVisible();
expect(calls.users).toBeGreaterThan(0);
expect(calls.passwords).toBe(0);
expect(calls.lanyards).toBe(0);
expect(calls.mutations).toEqual([]);
});
}
for (const email of ['[email protected]', '[email protected]', '[email protected]']) {
test(`server denies non-admin callback ${email} despite editable admin metadata`, async ({ page }) => {
const { session, calls } = await mockApi(page, { email, admin: false, registered: true, checkedIn: true });
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByRole('alert')).toHaveText('This account is not an admin.');
await expect(page.getByTestId('tab-home')).toHaveCount(0);
await expect(page).toHaveURL(`${appUrl}/`);
expect(calls.logouts).toBe(1);
expect(calls.mutations).toEqual([]);
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
});
}
test('code exchange is consumed once under StrictMode and scrubbed', async ({ page }) => {
const { calls } = await mockApi(page);
await page.goto(`${appUrl}/auth/callback?code=mock-code&redirect_to=https://example.org`);
await expect(page.getByTestId('tab-home')).toBeVisible();
await expect(page).toHaveURL(`${appUrl}/`);
expect(calls.exchanges).toBe(1);
});
test('root callback also rejects non-admins and removes callback credentials', async ({ page }) => {
const { session } = await mockApi(page, { admin: false, registered: true, checkedIn: true });
await page.goto(`${appUrl}/#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByRole('alert')).toHaveText('This account is not an admin.');
await expect(page).toHaveURL(`${appUrl}/`);
await expect(page.getByTestId('tab-home')).toHaveCount(0);
});
test('denied callback clears local credentials even when logout fails', async ({ page }) => {
const { session } = await mockApi(page, { admin: false, registered: true, checkedIn: true });
await page.route('**/auth/v1/logout**', (route) => route.fulfill({ status: 500, json: { message: 'Logout unavailable' } }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByRole('alert')).toHaveText('This account is not an admin.');
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
await page.reload();
await expect(page.getByTestId('tab-home')).toHaveCount(0);
await expect(page.getByTestId('login-splash')).toBeVisible();
});
test('rejected exchange clears an existing local session and offers a fresh request', async ({ page }) => {
const { session } = await mockApi(page);
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByTestId('tab-home')).toBeVisible();
await page.route('**/auth/v1/token**', (route) => route.fulfill({ status: 400, json: { error: 'invalid_grant', error_description: 'Sensitive exchange detail' } }));
await page.goto(`${appUrl}/auth/callback?code=expired-code`);
await expect(page.getByRole('alert')).toHaveText(invalidLink);
await expect(page).toHaveURL(`${appUrl}/`);
expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]);
await page.getByLabel('QR Code').fill('[email protected]');
await page.getByRole('button', { name: 'Send magic link', exact: true }).click();
await expect(page.getByRole('status')).toHaveText(notice);
await expect(page.getByRole('alert')).toHaveCount(0);
await expect(page.getByText('Sensitive exchange detail')).toHaveCount(0);
});
for (const endpoint of ['user', 'is_admin', 'contacts']) {
test(`callback stays denied when server ${endpoint} verification fails`, async ({ page }) => {
const { session, calls } = await mockApi(page);
const path = endpoint === 'user' ? '**/auth/v1/user' : endpoint === 'is_admin' ? '**/rest/v1/rpc/is_admin' : '**/rest/v1/contacts**';
await page.route(path, (route) => route.fulfill({ status: 401, json: { message: 'Sensitive authorization detail' } }));
await page.goto(`${appUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
await expect(page.getByRole('alert')).toHaveText(invalidLink);
await expect(page.getByTestId('tab-home')).toHaveCount(0);
await expect(page).toHaveURL(`${appUrl}/`);
expect(calls.mutations).toEqual([]);
await expect(page.getByText('Sensitive authorization detail')).toHaveCount(0);
});
}
test('staff QR still requires the staff password and enables staff mode', async ({ page }) => {
const { calls } = await mockApi(page, { staff: true, registered: true, checkedIn: false });
await page.route('**/auth/v1/token**', async (route) => {
expect(route.request().postDataJSON()).toMatchObject({ email: '[email protected]', password: 'mock-staff-password' });
calls.passwords++;
await route.fulfill({ json: mockSession('[email protected]') });
});
await openEntry(page);
await page.getByLabel('QR Code').fill('CVV-TEST-1234');
await page.getByLabel('QR Code').press('Enter');
await expect(page.getByTestId('staff-login-password')).toBeVisible();
await expect(page.getByTestId('login-confirm')).toBeDisabled();
await page.getByTestId('staff-login-password').fill('mock-staff-password');
await page.getByTestId('staff-login-password').press('Enter');
await expect(page.getByTestId('tab-home')).toBeVisible();
await page.getByTestId('tab-scan').click();
await expect(page.getByTestId('scan-mode-staff')).toBeVisible();
expect(calls.passwords).toBe(1);
expect(calls.otp).toBe(0);
expect(calls.mutations).toEqual([]);
});
test('failed attendee QR confirmation stays outside the app', async ({ page }) => {
await mockApi(page, { admin: false, registered: true, checkedIn: true });
await page.route('**/auth/v1/token**', (route) => route.fulfill({ status: 400, json: { error: 'invalid_grant', error_description: 'Invalid login credentials' } }));
await openEntry(page);
await page.getByLabel('QR Code').fill('CVV-TEST-1234');
await page.getByTestId('scanner-manual-go').click();
await page.getByTestId('attendee-login-email').fill('[email protected]');
await page.getByTestId('login-confirm').click();
await expect(page.getByTestId('login-error')).toHaveText('Email and QR code do not match. Please try again.');
await expect(page.getByTestId('tab-home')).toHaveCount(0);
});
test('mobile email controls fit and QR remains available during cooldown', async ({ page }) => {
await page.setViewportSize({ width: 375, height: 812 });
const { calls } = await mockApi(page);
await openEntry(page);
await page.getByLabel('QR Code').fill('[email protected]');
await page.getByRole('button', { name: 'Send magic link', exact: true }).click();
await expect(page.getByRole('status')).toHaveText(notice);
const button = await page.getByTestId('scanner-manual-go').boundingBox();
const input = await page.getByLabel('QR Code').boundingBox();
expect(button).not.toBeNull();
expect(input).not.toBeNull();
expect(input!.x + input!.width).toBeLessThanOrEqual(button!.x);
expect(button!.x + button!.width).toBeLessThanOrEqual(375);
await page.screenshot({ path: '/tmp/convivo-admin-entry-mobile.png', fullPage: true });
await page.getByLabel('QR Code').fill('CVV-TEST-1234');
await expect(page.getByTestId('scanner-manual-go')).toHaveText('Go');
await expect(page.getByTestId('scanner-manual-go')).toBeEnabled();
await page.getByTestId('scanner-manual-go').click();
await expect(page.getByTestId('attendee-login-email')).toBeVisible();
expect(calls.lanyards).toBe(1);
});
for (const suffix of ['#error=access_denied&error_code=otp_expired&error_description=Sensitive+detail', '#access_token=incomplete', '']) {
test(`invalid callback is scrubbed and recoverable ${suffix || 'empty'}`, async ({ page }) => {
const { calls } = await mockApi(page);
await page.goto(`${appUrl}/auth/callback${suffix}`);
await expect(page.getByRole('alert')).toHaveText(invalidLink);
await expect(page.getByLabel('QR Code')).toBeVisible();
await expect(page).toHaveURL(`${appUrl}/`);
expect(calls.exchanges).toBe(0);
expect(calls.users).toBe(0);
await expect(page.getByText('Sensitive detail')).toHaveCount(0);
});
}
for (const checkedIn of [false, true]) {
test(`attendee QR login retains the checked-in=${checkedIn} gate`, async ({ page }) => {
const email = '[email protected]';
const { calls } = await mockApi(page, { email, admin: false, registered: true, checkedIn });
await openEntry(page);
await page.getByLabel('QR Code').fill('CVV-TEST-1234');
await page.getByTestId('scanner-manual-go').click();
await page.getByTestId('attendee-login-email').fill(email);
await page.getByTestId('login-confirm').click();
if (checkedIn) await expect(page.getByTestId('tab-home')).toBeVisible();
else await expect(page.getByTestId('checkin-required-gate')).toBeVisible();
expect(calls.passwords).toBe(1);
expect(calls.lanyards).toBe(1);
expect(calls.otp).toBe(0);
expect(calls.mutations).toEqual([]);
});
}
});