Unit test all three service layer components
epic-bufdir-report-period-selection-services-task-008 — Write flutter_test unit tests for PeriodPresetService (preset resolution and DateTimeRange mapping for standard and custom grant cycles), PeriodRecordCountService (async count retrieval and isFuturePeriod logic), and ReportPeriodValidator (all three rules: boundary alignment, empty range, overlap detection). Use Riverpod ProviderContainer with mock repository overrides. Target 100% branch coverage for validation rule paths.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
ProviderContainer usage: `final container = ProviderContainer(overrides: [periodConfigurationRepositoryProvider.overrideWithValue(mockRepo)]); addTearDown(container.dispose);`. For `isFuturePeriod` tests that depend on `DateTime.now()`, inject a `Clock` abstraction or use a fixed reference date passed as a parameter — do not let tests depend on wall clock time, as they will become flaky. For overlap boundary tests, construct DateTimeRanges that are exactly adjacent (end of one == start of next) to verify the inclusive/exclusive semantics are correct. Aim for one `expect` per test case for clear failure messages.
Testing Requirements
Use `flutter_test` with `ProviderContainer` for Riverpod integration. Create mock classes manually (or with `package:mocktail` if already in pubspec) for `PeriodConfigurationRepository`. Organise test files as: `period_preset_service_test.dart`, `period_record_count_service_test.dart`, `report_period_validator_impl_test.dart`. Each file should use `group()` blocks per rule/scenario.
Use `setUp()` to construct a fresh `ProviderContainer` for each test to avoid state leakage between tests. Run `flutter test --coverage` and inspect `lcov.info` to verify branch coverage on the validator implementation.
Detecting overlap with previously submitted reports requires querying a report history table that may not yet exist or may not have a reliable submitted_at / period_end field, making the validator dependent on an incomplete upstream feature (Bufdir Report History & Audit Log).
Mitigation & Contingency
Mitigation: Define the minimum interface (a single repository method: getSubmittedPeriods(orgId) → List<DateTimeRange>) as an abstract class in this epic. Implement a stub that returns an empty list until the history feature is available, so the validator compiles and passes tests without a real data source.
Contingency: If the history feature is delayed beyond this feature's delivery window, ship the validator with the stub returning an empty list (overlap check disabled) and surface a feature-flag-controlled warning banner explaining that overlap detection will be enabled in a future update.
Bufdir's structural requirements for reporting periods (complete calendar months, grant-year span restrictions) may be ambiguous or subject to change, causing the validator to enforce rules that are incorrect or overly restrictive for some organisations.
Mitigation & Contingency
Mitigation: Document the specific Bufdir rules being enforced in the validator's source code as named constants with references to the relevant Bufdir guidelines. Review the rules with at least one coordinator representative before implementation is finalised.
Contingency: Expose a per-org configuration flag (strict_bufdir_validation: bool) in the period configuration repository so that rule enforcement can be relaxed for specific organisations without a code deployment.