Files
Convivo/e2e/tests/connections.spec.ts
T
Lago 692df23149 Add Playwright E2E suite (46 tests) + app testids + test_cases.md
- e2e/: full Playwright suite covering every spec case (staff auth/UI,
  welcome + session check-in, attendee access/gating, connections,
  profile visibility, speaker material, sponsor, feedback, E2E journeys,
  role security matrix). 46/46 passing.
- apps/convivo: add data-testid attributes (gate, tabs, scanner, toggles)
  to support the E2E suite.
- test_cases.md: spec-case-to-test coverage map (all cases fully covered).
- .gitignore: ignore e2e node_modules/reports/test-results.
2026-09-09 10:13:26 +02:00

373 lines
15 KiB
TypeScript
Raw 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 } 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 can send, receive, accept, and decline connection requests', async ({ browser }) => {
const staff = await createUser(browser, 'staff');
const mia = await createUser(browser, 'attendeeA');
const jonas = await createUser(browser, 'attendeeB');
const emma = await createUser(browser, 'attendeeC');
try {
const sApp = new AppPage(staff.page, APP_URL);
const sScan = new ScanPage(staff.page);
const sConns = new ConnectionsPage(staff.page);
const mApp = new AppPage(mia.page, APP_URL);
const mConns = new ConnectionsPage(mia.page);
const jApp = new AppPage(jonas.page, APP_URL);
const jScan = new ScanPage(jonas.page);
const eApp = new AppPage(emma.page, APP_URL);
const eScan = new ScanPage(emma.page);
// 1. Staff sends a connection request to Mia.
await login(staff.page, APP_URL, ID.staff);
await sApp.waitForAdmitted();
await sApp.gotoTab('scan');
await sScan.setAttendeeMode();
await sScan.scanCode(ID.attendeeA.qrToken);
await sScan.sendConnection();
// 2. Mia accepts.
await login(mia.page, APP_URL, ID.attendeeA);
await mApp.waitForAdmitted();
await mConns.gotoRequests();
await mConns.accept();
// 3. Verify the connection both ways.
await mConns.gotoMine();
expect(await mConns.mineContains('Jose Lago')).toBe(true);
await sConns.gotoMine();
expect(await sConns.mineContains('Mia Moser')).toBe(true);
// 4. Jonas (a different attendee) sends the staff a request; the staff accepts.
await login(jonas.page, APP_URL, ID.attendeeB);
await jApp.waitForAdmitted();
await jApp.gotoTab('scan');
await jScan.setAttendeeMode();
await jScan.scanCode(ID.staff.qrToken);
await jScan.sendConnection();
await sConns.gotoRequests();
await sConns.accept();
// 5. The staff–Jonas connection is established both ways.
await sConns.gotoMine();
expect(await sConns.mineContains('Jonas Unger')).toBe(true);
await jApp.gotoTab('connections');
const jConns = new ConnectionsPage(jonas.page);
await jConns.gotoMine();
expect(await jConns.mineContains('Jose Lago')).toBe(true);
// 6. Emma sends the staff a request; the staff declines → no connection.
await login(emma.page, APP_URL, ID.attendeeC);
await eApp.waitForAdmitted();
await eApp.gotoTab('scan');
await eScan.setAttendeeMode();
await eScan.scanCode(ID.staff.qrToken);
await eScan.sendConnection();
await sConns.gotoRequests();
await sConns.decline();
// 7. Emma is NOT in the staff's established connections.
await sConns.gotoMine();
expect(await sConns.mineContains('Emma Dorfer')).toBe(false);
} finally {
await staff.close();
await mia.close();
await jonas.close();
await emma.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();
}
});
});