- Convivo: not-checked-in gate for non-staff (see-a-staff screen with QR code + logout); lifts automatically once staff checks them in - Convivo: fix check-in 'pick a session first' race (synchronous default session fallback) - Add RPC test suite (npm run test:rpc): points idempotency, role guards, service-session guard, speaker auto-promote, leaderboard staff exclusion - Fix db:types script (create packages/shared/src); gitignore generated types - Docs: README/roadmap drift fixes, tests.md, backend README link 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]>
51 lines
1.9 KiB
Markdown
51 lines
1.9 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
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 what
|
|
[`public.current_email()`](./rpcs.md) and `public.is_admin()` read.
|
|
- **Every test always runs.** Each test is a `DO` block 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 |
|
|
|
|
## Files
|
|
|
|
- [`supabase/tests/rpc_tests.sql`](../../supabase/tests/rpc_tests.sql) — the test
|
|
script (fixtures + assertions + summary).
|
|
- [`supabase/tests/run-rpc-tests.js`](../../supabase/tests/run-rpc-tests.js) — the
|
|
runner (executes the script, parses the summary, sets the exit code).
|