Unit tests for ScenarioConfigurationManager
epic-scenario-based-follow-up-prompts-core-logic-task-010 — Write unit tests for ScenarioConfigurationManager covering: loading rules for a chapter with and without existing data, JSON schema validation accepting valid rules and rejecting malformed inputs, default template seeding when chapter has no rules, saveRule persisting via repository, and deleteRule removing the correct record. Use mock ScenarioRuleRepository. Test at least 15 distinct scenarios.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
ScenarioConfigurationManager should be instantiated with a mock ScenarioRuleRepository injected via constructor (not Riverpod provider) to keep unit tests isolated from the provider graph. Use mocktail's when().thenAnswer() pattern for async stubs. For JSON schema validation tests, define inline fixture maps directly in the test file — do not read from files to keep tests self-contained. Default template seeding logic should be tested by verifying repository.save() is called N times (one per default template) when loadRulesForChapter returns an empty list.
Use verify() to assert interaction counts. Avoid testing private methods directly — only test the public API surface.
Testing Requirements
Unit tests only using flutter_test. Use mocktail or mockito to mock ScenarioRuleRepository. Structure tests in a single file (scenario_configuration_manager_test.dart) with group() blocks per method under test. Cover: (1) loadRulesForChapter — empty state, populated state, multi-chapter isolation; (2) JSON schema validation — valid input, missing required field, wrong type, extra unknown field; (3) default template seeding — triggers on empty, does not re-seed when rules exist; (4) saveRule — delegates to repository with correct args, returns persisted rule; (5) deleteRule — correct ID forwarded, idempotent on non-existent ID.
All 15+ scenarios must be deterministic and not depend on execution order.
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.