Unit tests for ScenarioDeepLinkHandler URI building
epic-scenario-based-follow-up-prompts-core-logic-task-011 — Write unit tests for ScenarioDeepLinkHandler covering: valid context produces correct go_router URI with all query parameters, prefill values are properly URL-encoded, cold-start path resolves correctly, warm-start path resolves correctly, validation failure for non-existent activityId routes to fallback, validation failure for inaccessible contactId routes to fallback. Use mock router and repository.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
go_router's GoRouter cannot be easily instantiated in unit tests — use a mock class that implements or wraps the router interface, or extract navigation logic behind a NavigationService interface that can be mocked. If go_router version does not support easy mocking, consider defining a thin RouterDelegate abstraction in ScenarioDeepLinkHandler that the tests can replace. URI building should use Dart's Uri class (Uri(path: ..., queryParameters: {...})) rather than string interpolation to guarantee correct encoding. For cold-start vs warm-start distinction, the handler likely checks whether GoRouter.of(context) is available or uses a platform channel callback — mock accordingly.
Testing Requirements
Unit tests only using flutter_test and mocktail. Create scenario_deep_link_handler_test.dart. Mock both the go_router GoRouter instance and PromptHistoryRepository. For URI correctness tests: parse the resulting URI string using Uri.parse() and assert scheme, path, and queryParameters individually — do not do string equality on the full URI (fragile).
For URL-encoding tests: include at least one Norwegian character (ø, æ, å) and one ampersand in prefill values and assert the encoded form. For cold/warm-start: mock the router state (null vs active) and assert the correct navigation method (push vs go) is called. For validation failures: stub the repository to return null or throw an access-denied exception and assert fallback URI is used.
The Rule Engine must support a flexible JSON rule schema that can express compound conditions (e.g., contact_type AND wellbeing_flag AND delay_days). Underestimating schema expressiveness may require breaking changes to the rule format after coordinators have already configured rules.
Mitigation & Contingency
Mitigation: Define and freeze the rule JSON schema (trigger_type enum, metadata_conditions structure, delay logic) before any implementation begins; validate schema against all known HLF scenarios documented in the feature spec.
Contingency: If schema changes are needed after deployment, implement a schema version field and a migration utility that upgrades stored rules to the new format without coordinator intervention.
Deep-link navigation to the activity wizard with pre-filled arguments may fail if the user's session has expired or if the wizard route is not yet mounted in the navigator stack, causing unhandled navigation exceptions.
Mitigation & Contingency
Mitigation: Implement session state check before navigation; if session is expired, redirect to biometric/login screen and store the pending deep-link URI for post-auth redirect using go_router's redirect mechanism.
Contingency: If post-auth redirect proves unreliable, fall back to navigating to the home screen with a visible action banner that re-triggers the wizard with pre-filled arguments.