Integration test: end-to-end dispatch and deep-link resolution
epic-scenario-push-engagement-foundation-task-014 — Write an integration test that exercises the full foundation stack: load config from ScenarioEvaluationConfig, build a localised message via ScenarioNotificationContentBuilder, dispatch via PushNotificationDispatcher against a test FCM endpoint, verify delivery status is written to the scenario_notification_records table via ScenarioNotificationRepository, and confirm ScenarioDeepLinkRouter resolves the returned payload to the correct screen. Run against a local Supabase instance using Docker.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
Use supabase_flutter with a custom Supabase URL pointing to localhost:54321 (default local Supabase port). Load the local anon key from a .env.test file that is committed to the repo without secrets (use the well-known local dev anon key). For the FCM stub, the simplest approach is a Dart shelf server started in setUpAll() that returns 200 OK for success tests and 500 for failure tests, then torn down in tearDownAll(). Configure PushNotificationDispatcher to accept an injectable base URL for the FCM endpoint so it can be redirected to the local stub.
The integration test is the authoritative proof that all five foundation components (Config, Builder, Dispatcher, Repository, Router) compose correctly — design it to catch contract mismatches (e.g., the repository expecting a different status enum value than the dispatcher produces).
Testing Requirements
Integration tests using flutter_test with a real local Supabase instance (Docker). Tests are not widget tests — they exercise the Dart business logic and repository layers directly. Organise into a single group('End-to-end notification dispatch') with setUp() starting Docker and connecting Supabase client, and tearDown() cleaning seeded records. Run at least 3 scenario types through the full pipeline.
Use a WireMock or local HTTP stub for FCM to avoid real Firebase calls. Assert database state by querying Supabase directly in the test (not via the repository abstraction) to catch any repository mapping bugs. These tests must run in CI with Docker available — add a GitHub Actions job or Makefile target that starts Supabase before running the test suite.
FCM service account key and APNs certificate configuration may be missing or misconfigured in the Supabase Edge Function secrets store, blocking end-to-end push delivery testing until resolved by the infrastructure owner.
Mitigation & Contingency
Mitigation: Raise a credentials-setup task in the project board at epic start; document the exact secret names required in scenario-evaluation-config so the infrastructure owner can provision them independently of development work.
Contingency: Implement a mock push-notification-dispatcher stub that records payloads to the database for local testing, allowing the rest of the feature to proceed while credentials are obtained.
Incorrect RLS policies on the scenario_notifications or notification_preferences tables could allow one user to read or modify another user's notification records, constituting a data privacy breach.
Mitigation & Contingency
Mitigation: Write dedicated RLS policy tests using Supabase's built-in test framework before any application code touches the tables; require a peer security review of all policy definitions before merging.
Contingency: If a policy gap is discovered post-merge, immediately disable the affected table's read policy, notify the security lead, and deploy a hotfix with corrected policies before re-enabling access.
Norwegian Bokmål ARB localisation strings for all scenario message templates may not be available at implementation time, causing content-builder tests to fail and delaying integration.
Mitigation & Contingency
Mitigation: Define all required ARB message keys in a tracked document shared with the content owner at epic kickoff; use English placeholder strings that follow the final format so template injection logic can be tested independently.
Contingency: Ship with English-only strings in the first release and gate Norwegian strings behind a feature flag that is enabled once translations are reviewed and approved.