Write unit tests for ScenarioDeepLinkRouter cold-start and foreground navigation
epic-scenario-push-engagement-foundation-task-013 — Write unit tests for ScenarioDeepLinkRouter covering: cold-start payload resolves correct route with full back-stack, foreground payload navigates without duplicate back-stack entries, unknown scenario_type falls back to notification centre, malformed payload does not crash the router, and each known scenario_type maps to the expected route. Use flutter_test and mock the navigator.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
ScenarioDeepLinkRouter must separate route resolution (pure function: payload → route name + args) from navigation execution (side-effecting: navigator calls) to enable pure unit testing of the resolution logic. If the router currently reads Navigator.of(context) directly, refactor to accept an abstract NavigatorFacade interface injected via constructor. Cold-start vs. foreground is best modelled as an enum parameter (LaunchMode.coldStart / LaunchMode.foreground) passed to the handlePayload() method.
Back-stack construction for cold-start should use a builder pattern that accumulates route names before pushing them all at once. Test the fallback for unknown scenario_type first — this is the safety net for future scenario additions that miss router registration.
Testing Requirements
Unit tests using flutter_test. Mock the Flutter navigator using a MockNavigatorObserver or a custom MockNavigator interface that captures push/pop calls. Create parameterised test cases iterating over all ScenarioType enum values to assert route mapping. Separate group() blocks for: 'cold-start routing', 'foreground routing', 'fallback behaviour', 'malformed payload handling'.
Use ArgumentCaptor or verify() with argument matchers to assert both the route name and the arguments passed. Do not use real widgets or pumpWidget — the router should be testable as a plain Dart class. Back-stack assertions should check the sequence of navigator calls (e.g., [push('/home'), push('/notifications'), push('/certification-expiry')]) not just the last call.
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.