high priority medium complexity testing pending testing specialist Tier 7

Acceptance Criteria

Unit test coverage ≥ 90% for: payload validator, transition detector, coordinator resolver, payload builder, and FCM dispatcher modules.
Unit tests run in Deno test runner (`deno test`) and complete in under 10 seconds.
Integration test: PAUSE transition end-to-end — seed mentor with assigned coordinator, fire webhook, assert both FCM dispatch mock called and in-app records inserted with correct fields.
Integration test: RESUME transition end-to-end — same setup, assert correct title/body strings and transition_direction='resumed' in records.
Integration test: missing coordinator scenario — seed mentor with no coordinator assignment, fire webhook, assert only mentor in-app record inserted, coordinator FCM skipped, no HTTP 500 returned.
Integration test: stale FCM token — seed device_token with a token, mock FCM to return UNREGISTERED, assert token deleted from device_token table after dispatch.
SLA test: measure end-to-end handler duration under simulated FCM latency of 800ms per recipient — assert total duration under 5000ms.
No silent failure test: mock coordinator resolution to throw a DB error, assert orchestrator returns an error result and webhook responds HTTP 500 (not 200).
All integration tests use a dedicated test Supabase project (not production) with seeded fixture data.
Test suite is executable via a single command and produces structured pass/fail output suitable for CI.

Technical Requirements

frameworks
Supabase Edge Functions (Deno)
Deno test runner
Supabase PostgreSQL 15
apis
Firebase Cloud Messaging (FCM) API v1 (mocked)
Supabase PostgREST REST API
data models
assignment
device_token
contact
performance requirements
Unit test suite completes in under 10 seconds.
Integration test suite completes in under 60 seconds.
SLA test must assert P95 duration under 5000ms across 10 simulated invocations.
security requirements
Test Supabase project uses separate credentials — never share service role key with production environment.
Test fixture data must not contain real personnummer, real phone numbers, or real email addresses.
FCM test dispatches must be mocked (not sent to real FCM) to prevent pollution of production devices.

Execution Context

Execution Tier
Tier 7

Tier 7 - 84 tasks

Can start after Tier 6 completes

Implementation Notes

Start by writing the integration test fixtures (SQL seed scripts) for the three key scenarios: (1) mentor with coordinator and FCM tokens for both, (2) mentor with no coordinator assignment, (3) mentor with stale FCM token. These fixtures drive the integration tests and also serve as documentation of expected database state. For unit tests, the pure function architecture (tasks 006-009 all recommend stateless functions) means most units can be tested without any mocking — just call with typed inputs and assert typed outputs. The only mocking needed is for the Supabase client (in resolver and dispatcher) and the FCM HTTP client.

For the SLA test, use `performance.now()` around the full orchestrator.run() call with mocked dependencies that introduce 800ms artificial delays to simulate realistic FCM latency. Document test execution instructions in a README.md in the Edge Function directory.

Testing Requirements

Test architecture: unit tests using Deno's built-in mock/stub utilities (std/testing/mock) for all external dependencies. Integration tests using a test Supabase project with seeded data via SQL fixture scripts. FCM calls intercepted with a local mock HTTP server (e.g., Deno's std/http/server in test setup). Coverage measured via `deno test --coverage` and reported as lcov.

CI integration: tests run on every PR via GitHub Actions with Deno setup action. Test file naming: `*.test.ts` co-located with source files. Required test files: `payload-validator.test.ts`, `transition-detector.test.ts`, `coordinator-resolver.test.ts`, `payload-builder.test.ts`, `fcm-dispatcher.test.ts`, `in-app-dispatcher.test.ts`, `orchestrator.integration.test.ts`, `webhook-handler.integration.test.ts`.

Component
Pause Status Webhook Handler
infrastructure low
Epic Risks (3)
medium impact medium prob technical

Supabase Edge Functions have cold start latency that may push coordinator notification delivery beyond the 5-second SLA, particularly during low-traffic periods when the function is not warm.

Mitigation & Contingency

Mitigation: Keep the Edge Function lightweight — delegate all heavy logic to the orchestrator layer and avoid large dependency bundles. Measure p95 end-to-end latency in staging and document actual SLA achievable.

Contingency: If cold start latency consistently breaches 5 seconds, introduce a keep-warm ping from the nightly-scheduler or document the actual p95 latency in the feature spec and adjust the acceptance criterion to reflect the realistic bound.

medium impact medium prob technical

Supabase database webhooks may fire duplicate events for a single status change under retry conditions, causing coordinators to receive multiple identical notifications for one pause event.

Mitigation & Contingency

Mitigation: Add idempotency checking in the webhook handler using the event timestamp and peer mentor ID. Store a notification dispatch record in the pause-status-record-repository and skip dispatch if a record for the same event already exists.

Contingency: If duplicates slip through in production, add a de-duplication filter in the notification centre UI layer so the coordinator sees at most one card per event, and implement a cleanup job for the notifications table.

medium impact low prob scope

A peer mentor with multi-chapter membership may have more than one responsible coordinator. The orchestrator design currently targets a single coordinator, and resolving multiple recipients may require schema changes to the org membership query.

Mitigation & Contingency

Mitigation: Review the multi-chapter-membership-service patterns before implementing the orchestrator's coordinator resolution. Design the dispatcher call to accept an array of coordinator IDs from the outset so adding multiple recipients is non-breaking.

Contingency: If multi-coordinator dispatch is out of scope for this epic, document the limitation and create a follow-up task. Default to the primary coordinator (lowest chapter hierarchy level) as the single recipient in the interim.