- Migration 20261020120000: staff (type staff / Admin / @appe.at) are auto-connected to every participant of the event via connections.auto rows inserted directly as accepted - never through accept_connection, so zero points by construction; backfill + idempotent helper + trigger. - Migration 20261020130000: submit_event_feedback awards +5 on the first submission per participant x event (edits earn 0), gated by _points_eligible; response gains earned column; ACL restored. - Admin: points move from Contacts to Registrations (active-event rows only, in-place save); Dashboard Top points drops emails; Dashboard and Activity hide auto connections. - Attendee: leaderboard masks surnames (Max M.); EventFeedback toast shows +5 pts on paid submissions. - Tests: staff_auto_connections_tests.sql (14 assertions), rpc_tests section 11 (4 assertions). Docs + release record 2026-10-20. - README: document the git-ignored .env provisioning step (missing key = white screen). 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]>
373 lines
16 KiB
TypeScript
373 lines
16 KiB
TypeScript
import { test, expect } from './base';
|
|
import { APP_URL, ID } from '../src/helpers/config';
|
|
import { login } from '../src/helpers/auth';
|
|
import { createUser } from '../src/helpers/multi';
|
|
import { signInJwt, userRpc } from '../src/helpers/api';
|
|
import { db, psql, sqlQuote } from '../src/helpers/db';
|
|
import { AppPage } from '../src/pages/AppPage';
|
|
import { ScanPage } from '../src/pages/ScanPage';
|
|
import { ConnectionsPage } from '../src/pages/ConnectionsPage';
|
|
|
|
/**
|
|
* §13–§20 Connections.
|
|
*
|
|
* The connection flow: a user scans a peer's lanyard (manual code = the QR
|
|
* payload) → the connect sheet → "Connect" → `create_connection_request`. The
|
|
* recipient sees it under Requests → Incoming and Accepts/Declines.
|
|
*/
|
|
|
|
test.describe('Connections', () => {
|
|
test('CONV-CONN-001 connection request by scanning a peer (QR)', async ({ page }) => {
|
|
const app = new AppPage(page, APP_URL);
|
|
const scan = new ScanPage(page);
|
|
const conns = new ConnectionsPage(page);
|
|
|
|
await login(page, APP_URL, ID.attendeeA);
|
|
await app.waitForAdmitted();
|
|
|
|
// Scan ATTENDEE_B's lanyard (manual code = the QR payload) and request.
|
|
await app.gotoTab('scan');
|
|
await scan.setAttendeeMode();
|
|
await scan.scanCode(ID.attendeeB.qrToken);
|
|
await scan.sendConnection();
|
|
|
|
// A sees B as a pending (outgoing) request.
|
|
await conns.gotoRequests();
|
|
expect(await conns.outgoingContains('Jonas Unger')).toBe(true);
|
|
|
|
// B must NOT yet appear as an established connection.
|
|
await conns.gotoMine();
|
|
expect(await conns.mineContains('Jonas Unger')).toBe(false);
|
|
|
|
// Backend: a pending connection row exists (A → B).
|
|
const rows = db.connections(ID.attendeeA.email);
|
|
expect(rows.some((r) => r.status === 'pending' && r.to === ID.attendeeB.email)).toBe(true);
|
|
});
|
|
|
|
test('CONV-CONN-002 connection request by manual code is equivalent to QR', async ({ page }) => {
|
|
const app = new AppPage(page, APP_URL);
|
|
const scan = new ScanPage(page);
|
|
const conns = new ConnectionsPage(page);
|
|
|
|
await login(page, APP_URL, ID.attendeeA);
|
|
await app.waitForAdmitted();
|
|
await app.gotoTab('scan');
|
|
await scan.setAttendeeMode();
|
|
|
|
// Manual code input (the same token the QR would carry).
|
|
await scan.scanCode(ID.attendeeB.qrToken);
|
|
await scan.sendConnection();
|
|
|
|
// Pending state behaves exactly as with QR scanning.
|
|
await conns.gotoRequests();
|
|
expect(await conns.outgoingContains('Jonas Unger')).toBe(true);
|
|
await conns.gotoMine();
|
|
expect(await conns.mineContains('Jonas Unger')).toBe(false);
|
|
|
|
// Backend: pending A → B.
|
|
const rows = db.connections(ID.attendeeA.email);
|
|
expect(rows.some((r) => r.status === 'pending' && r.to === ID.attendeeB.email)).toBe(true);
|
|
});
|
|
|
|
test('CONV-CONN-003 recipient sees the incoming request with Accept/Decline', async ({ browser }) => {
|
|
const a = await createUser(browser, 'attendeeA');
|
|
const b = await createUser(browser, 'attendeeB');
|
|
try {
|
|
const aApp = new AppPage(a.page, APP_URL);
|
|
const aScan = new ScanPage(a.page);
|
|
const bApp = new AppPage(b.page, APP_URL);
|
|
const bConns = new ConnectionsPage(b.page);
|
|
|
|
// A sends a request to B.
|
|
await login(a.page, APP_URL, ID.attendeeA);
|
|
await aApp.waitForAdmitted();
|
|
await aApp.gotoTab('scan');
|
|
await aScan.setAttendeeMode();
|
|
await aScan.scanCode(ID.attendeeB.qrToken);
|
|
await aScan.sendConnection();
|
|
|
|
// B sees A as an incoming request with Accept + Decline actions.
|
|
await login(b.page, APP_URL, ID.attendeeB);
|
|
await bApp.waitForAdmitted();
|
|
await bConns.gotoRequests();
|
|
await expect(b.page.getByText('Mia Moser', { exact: true })).toBeVisible();
|
|
await expect(b.page.getByTestId('connection-accept')).toBeVisible();
|
|
await expect(b.page.getByTestId('connection-decline')).toBeVisible();
|
|
|
|
// A still sees the request as pending (outgoing) until B responds.
|
|
const aConns = new ConnectionsPage(a.page);
|
|
await aConns.gotoRequests();
|
|
expect(await aConns.outgoingContains('Jonas Unger')).toBe(true);
|
|
} finally {
|
|
await a.close();
|
|
await b.close();
|
|
}
|
|
});
|
|
|
|
test('CONV-CONN-004 recipient accepts → established connection both ways', async ({ browser }) => {
|
|
const a = await createUser(browser, 'attendeeA');
|
|
const b = await createUser(browser, 'attendeeB');
|
|
try {
|
|
const aApp = new AppPage(a.page, APP_URL);
|
|
const aScan = new ScanPage(a.page);
|
|
const aConns = new ConnectionsPage(a.page);
|
|
const bApp = new AppPage(b.page, APP_URL);
|
|
const bConns = new ConnectionsPage(b.page);
|
|
|
|
// A sends to B.
|
|
await login(a.page, APP_URL, ID.attendeeA);
|
|
await aApp.waitForAdmitted();
|
|
await aApp.gotoTab('scan');
|
|
await aScan.setAttendeeMode();
|
|
await aScan.scanCode(ID.attendeeB.qrToken);
|
|
await aScan.sendConnection();
|
|
|
|
// B accepts.
|
|
await login(b.page, APP_URL, ID.attendeeB);
|
|
await bApp.waitForAdmitted();
|
|
await bConns.gotoRequests();
|
|
await bConns.accept();
|
|
|
|
// Both see each other in "My connections".
|
|
await bConns.gotoMine();
|
|
expect(await bConns.mineContains('Mia Moser')).toBe(true);
|
|
await aConns.gotoMine();
|
|
expect(await aConns.mineContains('Jonas Unger')).toBe(true);
|
|
|
|
// The pending request is no longer actionable.
|
|
await bConns.gotoRequests();
|
|
expect(await bConns.incomingContains('Mia Moser')).toBe(false);
|
|
|
|
// Backend: an accepted connection row exists.
|
|
const rows = db.connections(ID.attendeeA.email);
|
|
expect(rows.some((r) => r.status === 'accepted' && r.to === ID.attendeeB.email)).toBe(true);
|
|
} finally {
|
|
await a.close();
|
|
await b.close();
|
|
}
|
|
});
|
|
|
|
test('CONV-CONN-005 recipient declines → no connection is created', async ({ browser }) => {
|
|
const a = await createUser(browser, 'attendeeA');
|
|
const b = await createUser(browser, 'attendeeB');
|
|
try {
|
|
const aApp = new AppPage(a.page, APP_URL);
|
|
const aScan = new ScanPage(a.page);
|
|
const aConns = new ConnectionsPage(a.page);
|
|
const bApp = new AppPage(b.page, APP_URL);
|
|
const bConns = new ConnectionsPage(b.page);
|
|
|
|
// A sends to B.
|
|
await login(a.page, APP_URL, ID.attendeeA);
|
|
await aApp.waitForAdmitted();
|
|
await aApp.gotoTab('scan');
|
|
await aScan.setAttendeeMode();
|
|
await aScan.scanCode(ID.attendeeB.qrToken);
|
|
await aScan.sendConnection();
|
|
|
|
// B declines.
|
|
await login(b.page, APP_URL, ID.attendeeB);
|
|
await bApp.waitForAdmitted();
|
|
await bConns.gotoRequests();
|
|
await bConns.decline();
|
|
|
|
// No connection is created; the request is removed from actionable incoming.
|
|
await bConns.gotoRequests();
|
|
expect(await bConns.incomingContains('Mia Moser')).toBe(false);
|
|
// A must not see B as an established connection.
|
|
await aConns.gotoMine();
|
|
expect(await aConns.mineContains('Jonas Unger')).toBe(false);
|
|
|
|
// Backend: no accepted connection row.
|
|
const rows = db.connections(ID.attendeeA.email);
|
|
expect(rows.some((r) => r.status === 'accepted')).toBe(false);
|
|
} finally {
|
|
await a.close();
|
|
await b.close();
|
|
}
|
|
});
|
|
|
|
test('CONV-CONN-006 the Connections area correctly distinguishes the three states', async ({ page }) => {
|
|
const conns = new ConnectionsPage(page);
|
|
|
|
// Set up A's three states via the backend (as the relevant users):
|
|
// A ↔ B accepted (established), A → C pending (outgoing), D → A pending (incoming).
|
|
const aJwt = await signInJwt(ID.attendeeA.email, ID.attendeeA.qrToken);
|
|
const bJwt = await signInJwt(ID.attendeeB.email, ID.attendeeB.qrToken);
|
|
const cJwt = await signInJwt(ID.attendeeC.email, ID.attendeeC.qrToken);
|
|
const dJwt = await signInJwt(ID.attendeeD.email, ID.attendeeD.qrToken);
|
|
|
|
// A → B (then B accepts).
|
|
await userRpc(aJwt, 'create_connection_request', { p_target_qr: ID.attendeeB.qrToken });
|
|
// accept_connection needs the connection id; fetch it.
|
|
const abId = psql(
|
|
`select id from public.connections where from_email = ${sqlQuote(ID.attendeeA.email)} and to_email = ${sqlQuote(ID.attendeeB.email)} limit 1`,
|
|
);
|
|
await userRpc(bJwt, 'accept_connection', { p_connection_id: abId });
|
|
|
|
// A → C (pending, outgoing).
|
|
await userRpc(aJwt, 'create_connection_request', { p_target_qr: ID.attendeeC.qrToken });
|
|
// D → A (pending, incoming to A).
|
|
await userRpc(dJwt, 'create_connection_request', { p_target_qr: ID.attendeeA.qrToken });
|
|
|
|
// Now verify the UI separates the three states for A.
|
|
await login(page, APP_URL, ID.attendeeA);
|
|
await conns.gotoMine();
|
|
// Established: B (Jonas) is in My connections.
|
|
expect(await conns.mineContains('Jonas Unger')).toBe(true);
|
|
// Outgoing + incoming are NOT in My connections.
|
|
expect(await conns.mineContains('Emma Dorfer')).toBe(false);
|
|
expect(await conns.mineContains('Paul Klein')).toBe(false);
|
|
|
|
await conns.gotoRequests();
|
|
// Outgoing (Sent): C (Emma).
|
|
expect(await conns.outgoingContains('Emma Dorfer')).toBe(true);
|
|
// Incoming: D (Paul).
|
|
expect(await conns.incomingContains('Paul Klein')).toBe(true);
|
|
// The established B is NOT in Requests.
|
|
expect(await conns.incomingContains('Jonas Unger')).toBe(false);
|
|
expect(await conns.outgoingContains('Jonas Unger')).toBe(false);
|
|
});
|
|
|
|
|
|
test('CONV-CONN-007 staff are auto-connected to everyone and never for points', async ({ browser }) => {
|
|
// Staff ↔ people connections are created by the registrations trigger
|
|
// (migration 20261020120000_staff_auto_connections) with auto = true:
|
|
// no request, no accept step — and never any points. This replaces the
|
|
// old manual staff networking flow, which the feature made impossible:
|
|
// scanning a staff lanyard now lands on an already-accepted pair.
|
|
const staff = await createUser(browser, 'staff');
|
|
const mia = await createUser(browser, 'attendeeA');
|
|
const jonas = await createUser(browser, 'attendeeB');
|
|
try {
|
|
const sApp = new AppPage(staff.page, APP_URL);
|
|
const sConns = new ConnectionsPage(staff.page);
|
|
const mApp = new AppPage(mia.page, APP_URL);
|
|
const mConns = new ConnectionsPage(mia.page);
|
|
const mScan = new ScanPage(mia.page);
|
|
const jApp = new AppPage(jonas.page, APP_URL);
|
|
const jConns = new ConnectionsPage(jonas.page);
|
|
|
|
const pair = (a: string, b: string) => psql(
|
|
`select c.status || '|' || c.auto::text from public.connections c
|
|
where c.event_id = (select id from public.events where is_active limit 1)
|
|
and least(c.from_email, c.to_email) = least(${sqlQuote(a)}, ${sqlQuote(b)})
|
|
and greatest(c.from_email, c.to_email) = greatest(${sqlQuote(a)}, ${sqlQuote(b)});`,
|
|
);
|
|
const score = (email: string) => psql(
|
|
`select coalesce(sum(points), 0) from public.registrations
|
|
where event_id = (select id from public.events where is_active limit 1)
|
|
and contact_email = ${sqlQuote(email)};`,
|
|
);
|
|
|
|
// 1. No manual flow needed: the staff member already has everyone.
|
|
await login(staff.page, APP_URL, ID.staff);
|
|
await sApp.waitForAdmitted();
|
|
expect(await sConns.mineContains('Mia Moser')).toBe(true);
|
|
expect(await sConns.mineContains('Jonas Unger')).toBe(true);
|
|
|
|
// 2. Mia sees the staff in her own connections without ever asking,
|
|
// and the backend row is an auto-created accepted pair.
|
|
await login(mia.page, APP_URL, ID.attendeeA);
|
|
await mApp.waitForAdmitted();
|
|
expect(await mConns.mineContains('Jose Lago')).toBe(true);
|
|
expect(pair(ID.staff.email, ID.attendeeA.email)).toBe('accepted|true');
|
|
|
|
// 3. Scanning a staff lanyard connects instantly — no request is born.
|
|
const miaScore = score(ID.attendeeA.email);
|
|
const staffScore = score(ID.staff.email);
|
|
await mApp.gotoTab('scan');
|
|
await mScan.setAttendeeMode();
|
|
await mScan.scanCode(ID.staff.qrToken);
|
|
await mScan.sendConnection();
|
|
await expect(mia.page.getByText(/You.re connected/)).toBeVisible();
|
|
|
|
// 4. Neither side earns a point for connecting with staff.
|
|
expect(score(ID.attendeeA.email)).toBe(miaScore);
|
|
expect(score(ID.staff.email)).toBe(staffScore);
|
|
expect(psql(
|
|
`select count(*) from public.points_log
|
|
where created_at > now() - interval '2 minutes'
|
|
and contact_email in (${sqlQuote(ID.staff.email)}, ${sqlQuote(ID.attendeeA.email)});`,
|
|
)).toBe('0');
|
|
|
|
// 5. Jonas is connected to the staff the same instant, both directions.
|
|
await login(jonas.page, APP_URL, ID.attendeeB);
|
|
await jApp.waitForAdmitted();
|
|
expect(await jConns.mineContains('Jose Lago')).toBe(true);
|
|
await sApp.gotoTab('home');
|
|
expect(await sConns.mineContains('Jonas Unger')).toBe(true);
|
|
} finally {
|
|
await staff.close();
|
|
await mia.close();
|
|
await jonas.close();
|
|
}
|
|
});
|
|
|
|
test('CONV-CONN-008 networking works across roles (staff, attendee, speaker, sponsor)', async ({ browser }) => {
|
|
// Representative cross-role pairs covering all four roles:
|
|
// speaker → attendee, and sponsor → attendee.
|
|
// (Staff networking is covered by CONV-CONN-007.)
|
|
const spk = await createUser(browser, 'speaker');
|
|
const spo = await createUser(browser, 'sponsor');
|
|
const att = await createUser(browser, 'attendeeB');
|
|
try {
|
|
const sApp = new AppPage(spk.page, APP_URL);
|
|
const sScan = new ScanPage(spk.page);
|
|
const sConns = new ConnectionsPage(spk.page);
|
|
const oApp = new AppPage(spo.page, APP_URL);
|
|
const oScan = new ScanPage(spo.page);
|
|
const oConns = new ConnectionsPage(spo.page);
|
|
const aApp = new AppPage(att.page, APP_URL);
|
|
const aConns = new ConnectionsPage(att.page);
|
|
|
|
// Speaker sends to attendee.
|
|
await login(spk.page, APP_URL, ID.speaker);
|
|
await sApp.waitForAdmitted();
|
|
await sApp.gotoTab('scan');
|
|
await sScan.setAttendeeMode();
|
|
await sScan.scanCode(ID.attendeeB.qrToken);
|
|
await sScan.sendConnection();
|
|
|
|
// Sponsor sends to the same attendee.
|
|
await login(spo.page, APP_URL, ID.sponsor);
|
|
await oApp.waitForAdmitted();
|
|
await oApp.gotoTab('scan');
|
|
await oScan.setAttendeeMode();
|
|
await oScan.scanCode(ID.attendeeB.qrToken);
|
|
await oScan.sendConnection();
|
|
|
|
// Attendee accepts both (two incoming requests → accept one at a time).
|
|
await login(att.page, APP_URL, ID.attendeeB);
|
|
await aApp.waitForAdmitted();
|
|
await aConns.gotoRequests();
|
|
await att.page.getByTestId('connection-accept').first().click();
|
|
await aConns.gotoRequests();
|
|
await att.page.getByTestId('connection-accept').first().click();
|
|
|
|
// Both see the established connections.
|
|
await aConns.gotoMine();
|
|
expect(await aConns.mineContains('Duncan Boyne')).toBe(true);
|
|
expect(await aConns.mineContains('Demo Sponsor')).toBe(true);
|
|
// Force the speaker's + sponsor's Connections screens to re-fetch (they
|
|
// were already mounted, so navigate away + back to trigger a fresh load).
|
|
await sApp.gotoTab('home');
|
|
await sConns.gotoMine();
|
|
expect(await sConns.mineContains('Jonas Unger')).toBe(true);
|
|
await oApp.gotoTab('home');
|
|
await oConns.gotoMine();
|
|
expect(await oConns.mineContains('Jonas Unger')).toBe(true);
|
|
|
|
// Backend: accepted cross-role connections exist (speaker + sponsor).
|
|
const spkRows = db.connections(ID.speaker.email);
|
|
expect(spkRows.some((r) => r.status === 'accepted' && r.to === ID.attendeeB.email)).toBe(true);
|
|
const spoRows = db.connections(ID.sponsor.email);
|
|
expect(spoRows.some((r) => r.status === 'accepted' && r.to === ID.attendeeB.email)).toBe(true);
|
|
} finally {
|
|
await spk.close();
|
|
await spo.close();
|
|
await att.close();
|
|
}
|
|
});
|
|
});
|