Tapping a session in the red-clip popup only did go('agenda'), leaving the
speaker to hunt for the talk the popup had just named. It now opens the same
SessionDetail sheet "My picks today" uses -- the upload form is inside it, so
one tap reaches the action.
CONV-MATERIAL-005 provisions its own speaker fixture (the old demo speaker died
with the pretix-import reseed), drives the real QR login, and asserts the
upload notice is visible with the home tab still active; mutation-checked by
restoring go('agenda') -- the test fails on the old behavior.
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]>
230 lines
11 KiB
TypeScript
230 lines
11 KiB
TypeScript
import path from 'node:path';
|
||
import { test, expect } from './base';
|
||
import { APP_URL, ID, SPEAKER_SESSION, EVENT_ID, type Identity } from '../src/helpers/config';
|
||
import { login } from '../src/helpers/auth';
|
||
import { createUser } from '../src/helpers/multi';
|
||
import { signInJwt, userRpcResult } from '../src/helpers/api';
|
||
import { db, psql, psqlScalar, sqlQuote } from '../src/helpers/db';
|
||
import { AppPage } from '../src/pages/AppPage';
|
||
import { AgendaPage } from '../src/pages/AgendaPage';
|
||
import { HomePage } from '../src/pages/HomePage';
|
||
|
||
/**
|
||
* §27 Speaker role + §28 Speaker session material upload.
|
||
*
|
||
* SPEAKER_01 (Duncan Boyne) is a `session_speakers` row for SESSION_A (slot 1,
|
||
* "From Vision to Reality – A Live Launch Moment"). The seed leaves the
|
||
* speaker's `qr_token` NULL (a real gap — see findings), so the reset helper
|
||
* assigns a token + re-hashes the auth password.
|
||
*
|
||
* Material upload is a two-step backend operation: a Supabase Storage write to
|
||
* the `materials` bucket (RLS: `is_speaker_or_admin()`) + the `set_session_material`
|
||
* RPC (security definer; raises unless the caller is admin or a speaker of the
|
||
* session). We verify both the UI and the backend authorization.
|
||
*/
|
||
|
||
/** The speaker's session title (slot 1). */
|
||
const SPEAKER_SESSION_TITLE = 'From Vision to Reality';
|
||
|
||
/** A small, valid test file for the material upload. */
|
||
const MATERIAL_FILE = path.join(__dirname, '..', 'fixtures', 'material.txt');
|
||
|
||
/** Poll until a session has material (robust against commit timing). */
|
||
async function waitForMaterial(sessionId: string, timeoutMs = 5000): Promise<boolean> {
|
||
const deadline = Date.now() + timeoutMs;
|
||
for (;;) {
|
||
if (db.sessionHasMaterial(sessionId)) return true;
|
||
if (Date.now() > deadline) return db.sessionHasMaterial(sessionId);
|
||
await new Promise((r) => setTimeout(r, 200));
|
||
}
|
||
}
|
||
|
||
test.describe('Speaker + material upload', () => {
|
||
test('CONV-SPEAKER-001 session assignment grants the Speaker role automatically', async ({ page }) => {
|
||
const app = new AppPage(page, APP_URL);
|
||
|
||
// SPEAKER_01 is a session_speakers row for SESSION_A (slot 1).
|
||
await login(page, APP_URL, ID.speaker);
|
||
await app.waitForAdmitted();
|
||
|
||
// The registration type is 'speaker' (auto-promoted by the trigger).
|
||
expect(db.registration(ID.speaker.email)?.type).toBe('speaker');
|
||
|
||
// Speaker-specific functionality is available: the Agenda marks the session
|
||
// with the "🎤 you" speaker tag.
|
||
await app.gotoTab('agenda');
|
||
const agenda = new AgendaPage(page);
|
||
await agenda.openSession(SPEAKER_SESSION_TITLE);
|
||
await expect(agenda.speakerTag()).toBeVisible();
|
||
});
|
||
|
||
test('CONV-MATERIAL-001 speaker sees the pending material request (red attachment)', async ({ page }) => {
|
||
const app = new AppPage(page, APP_URL);
|
||
const home = new HomePage(page);
|
||
|
||
await login(page, APP_URL, ID.speaker);
|
||
await app.waitForAdmitted();
|
||
|
||
// Home displays the pending-material area (the red 📎 attachment pill).
|
||
await expect(home.materialPill()).toBeVisible();
|
||
|
||
// The material request references the relevant session (the Agenda shows the
|
||
// upload notice for the speaker's session).
|
||
await app.gotoTab('agenda');
|
||
const agenda = new AgendaPage(page);
|
||
await agenda.openSession(SPEAKER_SESSION_TITLE);
|
||
await expect(page.getByTestId('material-upload-notice')).toBeVisible();
|
||
});
|
||
|
||
test('CONV-MATERIAL-005 the pending-material pill opens the session directly', async ({ page }) => {
|
||
// Self-contained fixture: the demo speaker of §27/§28 belongs to the old
|
||
// seed and no longer exists since the pretix import, so this test provisions
|
||
// its own speaker on a real session that has no material.
|
||
const email = '[email protected]';
|
||
const token = 'CVV-PENDING-PILL-01';
|
||
const session = psqlScalar(`select s.id || '|' || s.title from public.sessions s
|
||
join public.slots sl on sl.id = s.slot_id
|
||
join public.session_speakers sp on sp.session_id = s.id
|
||
where (s.material_path is null or s.material_path = '')
|
||
and sl.type <> 'service_session'
|
||
order by sl.id limit 1`).split('|')[0];
|
||
const title = psqlScalar(`select title from public.sessions where id = ${sqlQuote(session)}`);
|
||
|
||
psql(`insert into public.contacts (email, full_name, is_admin)
|
||
values (${sqlQuote(email)}, 'Pending Pill Speaker', 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)}, 'speaker', true, 0, ${sqlQuote(token)})
|
||
on conflict (event_id, contact_email)
|
||
do update set type = 'speaker', checked_in = true, qr_token = excluded.qr_token`);
|
||
psql(`insert into public.session_speakers (session_id, contact_email)
|
||
values (${sqlQuote(session)}, ${sqlQuote(email)}) on conflict do nothing`);
|
||
// Auth user, password = QR token (same trick ensureSponsor uses).
|
||
psql(`insert into auth.users (instance_id, id, aud, role, email, encrypted_password, email_confirmed_at,
|
||
confirmation_token, email_change_token_new, email_change, recovery_token, reauthentication_token,
|
||
phone_change_token, raw_app_meta_data, raw_user_meta_data, created_at, updated_at)
|
||
values ('00000000-0000-0000-0000-000000000000', gen_random_uuid(), 'authenticated', 'authenticated',
|
||
${sqlQuote(email)}, extensions.crypt(${sqlQuote(token)}, extensions.gen_salt('bf')), now(),
|
||
'', '', '', '', '', '', '{\"provider\":\"email\",\"providers\":[\"email\"]}', '{}', now(), now())
|
||
on conflict (email) where is_sso_user = false do update
|
||
set encrypted_password = extensions.crypt(${sqlQuote(token)}, extensions.gen_salt('bf'))`);
|
||
|
||
try {
|
||
const app = new AppPage(page, APP_URL);
|
||
const home = new HomePage(page);
|
||
await login(page, APP_URL, { email, qrToken: token, type: 'speaker' } as Identity);
|
||
await app.waitForAdmitted();
|
||
|
||
// Red clip -> the pending-material sheet, listing this session.
|
||
await expect(home.materialPill()).toBeVisible();
|
||
await home.materialPill().click();
|
||
await expect(page.getByText('Pending material')).toBeVisible();
|
||
|
||
// Clicking the session opens THAT session's detail sheet with the upload
|
||
// form in place — not the Agenda tab, which used to drop the speaker there
|
||
// and make them hunt for the talk they were just told about.
|
||
await page.locator('.pick-chip').filter({ hasText: title }).click();
|
||
await expect(page.getByTestId('material-upload-notice')).toBeVisible();
|
||
await expect(page.getByTestId('material-upload')).toBeVisible();
|
||
// Still on Home: the sheet opened over it, the tab bar never moved.
|
||
await expect(page.getByTestId('tab-home')).toHaveClass(/active/);
|
||
} finally {
|
||
psql(`delete from public.session_speakers 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(`delete from auth.users where email = ${sqlQuote(email)}`);
|
||
}
|
||
});
|
||
|
||
test('CONV-MATERIAL-002 speaker uploads material and it persists across reload', async ({ page }) => {
|
||
const app = new AppPage(page, APP_URL);
|
||
const agenda = new AgendaPage(page);
|
||
|
||
await login(page, APP_URL, ID.speaker);
|
||
await app.waitForAdmitted();
|
||
const home = new HomePage(page);
|
||
|
||
// The pending-material pill count before the upload (this session is one of
|
||
// the pending ones; the speaker may have other pending sessions too).
|
||
const beforeCount = Number(((await home.materialPill().textContent()) ?? '').replace(/\D/g, ''));
|
||
|
||
await app.gotoTab('agenda');
|
||
|
||
// Open the speaker's session and upload a valid test file.
|
||
await agenda.openSession(SPEAKER_SESSION_TITLE);
|
||
await agenda.uploadMaterial(MATERIAL_FILE);
|
||
|
||
// The upload is persisted (material_path set on the session).
|
||
expect(await waitForMaterial(SPEAKER_SESSION)).toBe(true);
|
||
|
||
// The upload state survives a reload: the session shows the material (📎) +
|
||
// a download link, and the pending-material pill no longer counts this
|
||
// session (the speaker's other session may still be pending, so the pill
|
||
// count decreases rather than reaching 0).
|
||
await page.reload();
|
||
await app.waitForAdmitted();
|
||
const afterCount = Number(((await home.materialPill().textContent()) ?? '').replace(/\D/g, ''));
|
||
expect(afterCount).toBe(beforeCount - 1);
|
||
await app.gotoTab('agenda');
|
||
await agenda.openSession(SPEAKER_SESSION_TITLE);
|
||
await expect(page.getByText(/Download material/)).toBeVisible();
|
||
});
|
||
|
||
test('CONV-MATERIAL-003 material upload is available whenever it is still relevant', async ({ page }) => {
|
||
const app = new AppPage(page, APP_URL);
|
||
const agenda = new AgendaPage(page);
|
||
|
||
// The speaker's session (slot 1) is a "done" slot at the simulated clock,
|
||
// but the upload control is not time-gated (selNeedsMaterial has no time
|
||
// check) — it is available as long as the session is the user's and has no
|
||
// material yet.
|
||
await login(page, APP_URL, ID.speaker);
|
||
await app.waitForAdmitted();
|
||
await app.gotoTab('agenda');
|
||
|
||
await agenda.openSession(SPEAKER_SESSION_TITLE);
|
||
|
||
// The upload control is present (the session is the speaker's + no material).
|
||
await expect(agenda.materialUploadInput()).toBeVisible();
|
||
|
||
// The upload notice is shown (non-dismissible until uploaded).
|
||
await expect(page.getByTestId('material-upload-notice')).toBeVisible();
|
||
});
|
||
|
||
test('CONV-MATERIAL-004 material upload authorization (backend + frontend)', async ({ browser }) => {
|
||
// Authorized: the speaker can upload (storage write allowed for speakers).
|
||
const spk = await createUser(browser, 'speaker');
|
||
// Unauthorized: a plain attendee (no session/material assignment).
|
||
const att = await createUser(browser, 'attendeeA');
|
||
try {
|
||
// Backend: the speaker's JWT can call set_session_material.
|
||
const spkJwt = await signInJwt(ID.speaker.email, ID.speaker.qrToken);
|
||
const spkRes = await userRpcResult(spkJwt, 'set_session_material', {
|
||
p_session_id: SPEAKER_SESSION,
|
||
p_material_path: 'sessions/test/speaker.txt',
|
||
});
|
||
expect(spkRes.ok, `speaker set_session_material should succeed: ${spkRes.message}`).toBe(true);
|
||
|
||
// Backend: a plain attendee's JWT is rejected (not a speaker/admin).
|
||
const attJwt = await signInJwt(ID.attendeeA.email, ID.attendeeA.qrToken);
|
||
const attRes = await userRpcResult(attJwt, 'set_session_material', {
|
||
p_session_id: SPEAKER_SESSION,
|
||
p_material_path: 'sessions/test/attendee.txt',
|
||
});
|
||
expect(attRes.ok, `attendee set_session_material should be rejected`).toBe(false);
|
||
|
||
// Frontend: the plain attendee does not see the material upload control.
|
||
await login(att.page, APP_URL, ID.attendeeA);
|
||
const app = new AppPage(att.page, APP_URL);
|
||
await app.waitForAdmitted();
|
||
await app.gotoTab('agenda');
|
||
const agenda = new AgendaPage(att.page);
|
||
await agenda.openSession(SPEAKER_SESSION_TITLE);
|
||
await expect(att.page.getByTestId('material-upload')).toHaveCount(0);
|
||
} finally {
|
||
await spk.close();
|
||
await att.close();
|
||
}
|
||
});
|
||
});
|