87dec03d3c
Adds end-to-end integration test for the WebSocket live broadcast pipeline: Redis + TimescaleDB containers + Directus stub → full pipeline boot → real WS client assertions. Mirrors pipeline.integration.test.ts pattern with the skip-on-no-Docker guard. Key additions: - test/live.integration.test.ts: 6 test scenarios — happy path (subscribe → snapshot → live position), auth rejection (401), forbidden subscription (error/forbidden), multi-client fan-out (both receive position), orphan position (no WS frame), faulty snapshot exclusion (next-best non-faulty) - test/helpers/directus-stub.ts: bare http.createServer stub for /users/me and /items/events/:id endpoints with cookie-based user lookup - test/fixtures/test-schema.sql: minimal schema subset (events, entries, entry_devices with IMEI-as-device_id for Phase 1 join semantics) The integration test runs via `pnpm test:integration`, not `pnpm test`. Docker required; the suite skips cleanly when Docker is unavailable.
40 lines
1.9 KiB
SQL
40 lines
1.9 KiB
SQL
-- test/fixtures/test-schema.sql
|
|
--
|
|
-- Minimum subset of the production schema required by live.integration.test.ts.
|
|
-- This is intentionally a simplified version — NOT the full Directus-managed schema.
|
|
--
|
|
-- Maintenance note: keep in sync with the real schema when column types change on
|
|
-- these tables. Specifically: entries.event_id, entry_devices.device_id (Phase 1
|
|
-- uses IMEI text; Phase 2 introduces UUID-based devices table).
|
|
--
|
|
-- Phase 1 deviation: entry_devices.device_id is TEXT (IMEI) here, matching
|
|
-- positions.device_id. The real Directus schema uses a UUID FK to devices.id.
|
|
-- The integration test uses the real queries from device-event-map.ts and
|
|
-- snapshot.ts, so this simplified schema must satisfy those joins.
|
|
|
|
-- events — the container for entries
|
|
-- The Processor reads events.id (used in snapshot WHERE e.event_id = $1).
|
|
CREATE TABLE IF NOT EXISTS events (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid()
|
|
-- Real schema also has: organization_id FK, name, slug, discipline, starts_at, ends_at.
|
|
-- Only columns the Processor queries are included here.
|
|
);
|
|
|
|
-- entries — race entries belonging to an event
|
|
-- The Processor reads entries.id and entries.event_id.
|
|
CREATE TABLE IF NOT EXISTS entries (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
event_id uuid NOT NULL REFERENCES events (id) ON DELETE CASCADE
|
|
-- Real schema also has: vehicle_id, class_id, number, etc.
|
|
);
|
|
|
|
-- entry_devices — maps a device (IMEI) to an entry.
|
|
-- Phase 1: device_id is IMEI text, matching positions.device_id.
|
|
-- Real schema: device_id is UUID FK to devices.id, joined via devices.imei.
|
|
-- This simplified form is intentional for the integration test fixture.
|
|
CREATE TABLE IF NOT EXISTS entry_devices (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
entry_id uuid NOT NULL REFERENCES entries (id) ON DELETE CASCADE,
|
|
device_id text NOT NULL -- IMEI in Phase 1
|
|
);
|