Unit Test Certification Status Service All Edge Cases
epic-peer-mentor-detail-screen-foundation-task-007 — Write exhaustive unit tests for CertificationStatusService covering: expiry date exactly today (expired), expiry exactly 30 days out (expiring_soon boundary), expiry 31 days out (active), expiry 1 day in the past (expired), pause flag true with valid cert (paused overrides active), pause flag true with expired cert (paused takes precedence), days_remaining value correctness, and custom warning threshold override. All tests must use flutter_test and run without network or database access.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
CertificationStatusService must accept an injectable `DateTime now` parameter (or a clock abstraction) rather than calling `DateTime.now()` internally — this is the key design prerequisite for testability. If the service under test does not already support clock injection, add it before writing tests. Use `setUp()` to define a fixed 'today' reference date shared across all test cases. Boundary conditions (exactly 30 days, exactly today) are the highest-value cases; test these with off-by-one variants (29, 30, 31 days).
For the pause flag, confirm the enum precedence in the service implementation matches what the tests assert — if the service checks `isPaused` before evaluating the expiry date, the tests must reflect that order.
Testing Requirements
Unit tests only (flutter_test). No mocking of external services required. Use `DateTime` injection (pass clock as parameter or use a ClockProvider) to make date-dependent logic deterministic. Organise tests with `group()` blocks per scenario category: boundary dates, pause flag precedence, days_remaining arithmetic, threshold override.
Assert both the returned CertificationStatus enum value AND the days_remaining integer in each relevant case. Aim for 100% branch coverage of CertificationStatusService.
The design token theme extension may conflict with existing ThemeData extensions already registered in the app, causing runtime assertion errors or token resolution failures across all screens that consume the tokens.
Mitigation & Contingency
Mitigation: Audit all existing ThemeData extensions before implementation. Use a unique extension key namespace and add integration tests that instantiate the combined theme in a test app harness.
Contingency: If conflicts arise, isolate design tokens behind a dedicated provider singleton (Riverpod) rather than a ThemeData extension, updating all consuming widgets to read from the provider instead.
The 30-day warning threshold for expiring_soon status may differ between HLF's stated requirement in workshops (60 days mentioned in user stories) and the 30-day value in component documentation, causing disagreement during acceptance testing.
Mitigation & Contingency
Mitigation: Explicitly confirm the threshold value with HLF stakeholder before implementation. Make the threshold a named constant (kCertificationWarnDays) so it can be updated without logic changes.
Contingency: If stakeholder confirms 60 days post-implementation, update the constant and re-run the unit test suite — no architectural change required.