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]>
7.0 KiB
Backend — RPC Test Suite
A self-contained, idempotent test suite for the transactional points RPCs, role guards, and the speaker auto-promote trigger. It runs directly against the local Supabase Postgres container.
Run it
npm run db:start # the Supabase core must be running
npm run test:rpc # runs supabase/tests/rpc_tests.sql, exits non-zero on failure
Or manually:
docker exec -i supabase_db_Convivo psql -U postgres < supabase/tests/rpc_tests.sql
How it works
- No seed mutation. Everything runs in a single transaction that rolls back at the end, so the seed data is never changed. Safe to run repeatedly.
- Current user = PostgREST-style JWT claim. Each test sets the user the same
way PostgREST does:
set_config('request.jwt.claims', '{"email":"..."}', false), which is whatpublic.current_email()andpublic.is_admin()read. - Every test always runs. Each test is a
DOblock that catches its own exceptions and records a pass/fail row into a temp table, so one failure never aborts the rest. A summary is printed before the rollback. - The runner fails the process (
npm run test:rpc) if any test failed, so it can be wired into CI.
What it covers
| Area | Tests |
|---|---|
checkin_attendee |
awards +10, marks checked_in, idempotent re-check-in, service-session guard, non-admin role guard |
submit_feedback |
+5 rating-only, idempotent re-submit, requires check-in |
accept_connection |
+5 to both parties |
adjust_points |
admin-only role guard |
| Speaker auto-promote trigger | attendee → speaker, never overrides staff |
| Leaderboard | excludes staff |
Speaker Portal
speaker_portal_tests.sql is an
independent fail-fast suite (ON_ERROR_STOP) with generated contacts/events/talks,
temporary snapshots and a single transaction ending in ROLLBACK. It needs the
speaker portal migration
and staff overlap migration
on the local database. Apply without resetting existing data:
docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1 --single-transaction < supabase/migrations/20261006175631_speaker_portal.sql
docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1 --single-transaction < supabase/migrations/20261007153957_speaker_portal_staff_overlap.sql
docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1 < supabase/tests/speaker_portal_tests.sql
This direct migration application reloads the local API schema but does not write CLI migration history. It is not a production deployment command. No database reset is needed; fixture sequence state is not advanced.
The suite checks assigned speaker, non-admin staff and Admin staff access,
unassigned staff, mismatched same-event registrations, attendee assignments,
unregistered assignments, automatic service-session exclusion, active/inactive past/future
events, malformed and cross-session paths, required uploaded objects, Storage
INSERT/UPDATE/DELETE (including UPDATE WITH CHECK) and unchanged registration,
points-log, check-in and leaderboard state. Storage policy checks use the
authenticated database role, not a superuser that bypasses RLS. A failed
assertion exits non-zero and connection closure rolls back the transaction.
speaker-portal.spec.ts uses mocked Auth, REST and Storage responses, without real credentials or mail delivery:
cd e2e
CONVIVO_BASE_URL=http://127.0.0.1:3000 npx playwright test tests/speaker-portal.spec.ts --project=chromium --reporter=list --output=/tmp/convivo-speaker-results
Start Convivo's dev server first. Coverage includes both routes, existing-users-only link requests, URL scrubbing, callback errors/rejections, StrictMode single-use implicit/PKCE callbacks, local logout, empty access, upload/replace/remove across desktop/mobile, failed attachment cleanup and the normal app's check-in gate after portal login. Mocked tests do not validate live mail delivery, deployment redirect allowlists or real Storage behavior; the SQL suite validates database authorization separately. See screen contract, API client, RLS and RPCs.
Sessionize Date Guard
sessionize_date_guard_tests.sql
is an independent fail-fast rollback-only suite for the Sessionize API and Excel
RPC date guard. It creates generated event/contact/auth fixtures, precreates
explicit negative slot IDs so successful imports do not allocate sequence values,
and ends with ROLLBACK.
To verify the migration and suite together on the local database without persisting either change:
{ printf 'BEGIN;\n'; cat supabase/migrations/20261009225632_guard_sessionize_dates.sql supabase/tests/sessionize_date_guard_tests.sql; printf '\nROLLBACK;\n'; } | docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1
The nested BEGIN warning from the suite is harmless in this rollback-only
check. This command is local validation only; it does not write CLI migration
history and is not a production deployment. Historical rows outside the newly
configured event range are retained by successful imports and need a separately
approved reconciliation if they should be removed or changed.
Delete Event Schedule
delete_event_schedule_tests.sql
is an independent fail-fast rollback-only suite for the admin schedule-clear RPC.
It creates generated contacts/events/auth fixtures, uses explicit negative slot
IDs so fixture setup does not advance slots_id_seq, and ends with ROLLBACK.
To verify the migration and suite together on the local database without persisting either change:
{ printf 'BEGIN;\n'; cat supabase/migrations/20261009231817_delete_event_schedule.sql supabase/tests/delete_event_schedule_tests.sql; printf '\nROLLBACK;\n'; } | docker exec -i supabase_db_Convivo psql -U postgres -d postgres -v ON_ERROR_STOP=1
The suite checks authenticated admin execution, non-admin rejection, anon execute denial, missing-event rejection, exact delete counts, unchanged event selection, registrations, contacts, auth users, sponsors, connections, points, event feedback, leaderboard and other-event schedule rows. It also proves cross-event slot/dependent mismatches fail atomically instead of cascading foreign-event rows. This is local validation only; it does not write migration history or deploy anything.
Files
supabase/tests/rpc_tests.sql— the test script (fixtures + assertions + summary).supabase/tests/run-rpc-tests.js— the runner (executes the script, parses the summary, sets the exit code).