feat: finalize ticket merging and speaker-aware imports
This commit is contained in:
1 parent
648daa0794
commit
4e71e9b797
35 files changed
+1772
-348
No files matched your search
@@ -0,0 +1,361 @@
|
||||
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.';
|
||||
|
||||
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 } = {}) {
|
||||
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('/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: '2026-02-20', end_date: '2026-02-20', use_realtime_clock: 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 or admin email')).toBeVisible();
|
||||
}
|
||||
|
||||
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 or admin email').fill(email);
|
||||
await page.getByLabel('QR code or admin email').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 or admin email').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 or admin email').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 or admin email')).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 or admin email');
|
||||
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 or admin email').fill('[email protected]');
|
||||
await page.getByTestId('scanner-manual-go').click();
|
||||
await expect(page.getByLabel('QR code or admin email')).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 or admin email');
|
||||
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 or admin email').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 or admin email').fill('CVV-TEST-1234');
|
||||
await page.getByLabel('QR code or admin email').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 or admin email').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 or admin email').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 or admin email').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 or admin email').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 or admin email')).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 or admin email').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([]);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
import { test, expect, type Page } from '@playwright/test';
|
||||
|
||||
const adminUrl = process.env.CONVIVO_ADMIN_URL || 'http://localhost:3001';
|
||||
const eventId = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';
|
||||
const sourceId = '11111111-1111-4111-8111-111111111111';
|
||||
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 } = {}) {
|
||||
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' };
|
||||
const event = { id: eventId, name: 'Merge Conference', is_active: true, start_date: '2026-11-01', end_date: '2026-11-01', num_registrations: 2, num_checked_in_registrations: 0, num_sessions: 1, num_speakers: 1 };
|
||||
const contacts = [
|
||||
{ email: user.email, full_name: 'Admin', is_admin: true },
|
||||
{ email: '[email protected]', full_name: 'Alex Smith', is_admin: false },
|
||||
{ email: '[email protected]', full_name: 'Alex Smith', is_admin: false },
|
||||
{ email: '[email protected]', full_name: 'Robin Jones', is_admin: false },
|
||||
{ email: '[email protected]', full_name: 'Manual Person', is_admin: false },
|
||||
];
|
||||
let registrations = [
|
||||
{ id: sourceId, event_id: eventId, contact_email: contacts[1].email, type: 'speaker', qr_token: null, external_id: null, import_source: 'sessionize', checked_in: false, points: 0 },
|
||||
{ id: targetId, event_id: eventId, contact_email: contacts[2].email, type: 'attendee', qr_token: 'real-qr-one', external_id: 'pretix-one', import_source: null, checked_in: false, points: 0 },
|
||||
{ id: otherId, event_id: eventId, contact_email: contacts[3].email, type: 'attendee', qr_token: 'real-qr-two', external_id: 'pretix-two', import_source: null, checked_in: false, points: 0 },
|
||||
{ id: manualId, event_id: eventId, contact_email: contacts[4].email, type: 'attendee', qr_token: ' ', external_id: null, import_source: null, checked_in: true, points: 0 },
|
||||
];
|
||||
const merges: Array<{ p_source_id: string; p_target_id: string }> = [];
|
||||
await page.route('**/auth/v1/**', async route => {
|
||||
const path = new URL(route.request().url()).pathname;
|
||||
await route.fulfill({ json: path.endsWith('/user') ? user : path.endsWith('/token') ? session : {} });
|
||||
});
|
||||
await page.route('**/rest/v1/**', async route => {
|
||||
const url = new URL(route.request().url());
|
||||
const table = url.pathname.split('/').pop();
|
||||
if (table === 'merge_tickets') {
|
||||
const body = route.request().postDataJSON();
|
||||
merges.push(body);
|
||||
if (options.mergeFailure) return route.fulfill({ status: 400, json: { message: 'Ticket no longer exists' } });
|
||||
const target = registrations.find(row => row.id === body.p_target_id)!;
|
||||
registrations = registrations.filter(row => row.id !== body.p_source_id).map(row => row.id === target.id ? { ...row, type: 'speaker' } : row);
|
||||
return route.fulfill({ json: { source_id: body.p_source_id, target_id: target.id, target_email: target.contact_email, type: 'speaker', sessions_transferred: 2 } });
|
||||
}
|
||||
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] });
|
||||
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: [] });
|
||||
});
|
||||
await page.goto(`${adminUrl}/auth/callback#access_token=${session.access_token}&refresh_token=${session.refresh_token}&type=magiclink`);
|
||||
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
|
||||
await page.locator('.nav').getByRole('button', { name: /Registrations/ }).click();
|
||||
await expect(page.getByRole('button', { name: 'Merge tickets', exact: true })).toBeVisible();
|
||||
return { merges };
|
||||
}
|
||||
|
||||
test('counts only QR tickets and check-in slides without refresh', async ({ page }) => {
|
||||
await openRegistrations(page);
|
||||
await expect(page.getByText('2 tickets · 0 checked in · 2 without tickets.', { exact: false })).toBeVisible();
|
||||
const row = page.getByRole('row').filter({ hasText: '[email protected]' });
|
||||
await row.locator('label.toggle').click();
|
||||
await expect(row.getByRole('checkbox')).toBeChecked();
|
||||
await expect(page.getByText('2 tickets · 1 checked in · 2 without tickets.', { exact: false })).toBeVisible();
|
||||
});
|
||||
|
||||
test('failed check-in rolls the toggle back', async ({ page }) => {
|
||||
await openRegistrations(page, { patchFailure: 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();
|
||||
await expect(row.getByRole('checkbox')).not.toBeChecked();
|
||||
});
|
||||
|
||||
test('merge is imported-only, suggests names, cancels safely, and permits any purchased ticket', async ({ page }) => {
|
||||
const state = await openRegistrations(page);
|
||||
await expect(page.getByRole('button', { name: 'Merge tickets', exact: true })).toHaveCount(1);
|
||||
await page.getByRole('button', { name: 'Merge tickets', exact: true }).click();
|
||||
const choices = page.getByRole('radiogroup', { name: 'Destination ticket' });
|
||||
await expect(choices.getByRole('radio').first()).toHaveAccessibleName(/Alex Smith/);
|
||||
await expect(page.getByRole('button', { name: 'Confirm merge' })).toBeDisabled();
|
||||
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
expect(state.merges).toHaveLength(0);
|
||||
await page.getByRole('button', { name: 'Merge tickets', exact: true }).click();
|
||||
await page.getByPlaceholder('Search name or email').fill('Robin');
|
||||
await page.getByRole('radio', { name: /Robin Jones/ }).check();
|
||||
await page.getByRole('button', { name: 'Confirm merge' }).click();
|
||||
await expect(page.getByText('Merged into [email protected]; 2 session assignment(s) transferred.', { exact: true })).toBeVisible();
|
||||
expect(state.merges).toEqual([{ p_source_id: sourceId, p_target_id: otherId }]);
|
||||
await expect(page.getByRole('row').filter({ hasText: '[email protected]' })).toHaveCount(0);
|
||||
await expect(page.getByRole('row').filter({ hasText: '[email protected]' }).locator('select')).toHaveValue('speaker');
|
||||
});
|
||||
|
||||
test('failed merge keeps source row and allows retry', async ({ page }) => {
|
||||
await openRegistrations(page, { mergeFailure: true });
|
||||
await page.getByRole('button', { name: 'Merge tickets', exact: true }).click();
|
||||
await page.getByRole('radio', { name: /Alex Smith/ }).check();
|
||||
await page.getByRole('button', { name: 'Confirm merge' }).click();
|
||||
await expect(page.getByRole('alert')).toHaveText('Ticket no longer exists');
|
||||
await expect(page.getByRole('button', { name: 'Confirm merge' })).toBeEnabled();
|
||||
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
|
||||
await expect(page.getByRole('row').filter({ hasText: '[email protected]' })).toBeVisible();
|
||||
});
|
||||
Reference in new issue
Block a user