Unit test BufdirFieldValidationService
epic-bufdir-report-preview-core-logic-task-006 — Write comprehensive unit tests for all three rule classes and the orchestration method using flutter_test. Cover: empty required field triggers completeness error, populated field passes, value at threshold passes, value below threshold triggers warning, null prior period skips anomaly check, value within anomaly tolerance passes, value outside tolerance triggers warning, multiple issues returned in correct severity order, and empty report returns no issues.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Create a test helper file test/validation/validation_test_helpers.dart with factory functions: buildSection({Map
Use expect(result.issues, isEmpty) rather than expect(result.issues.length, 0) for readable failure messages. Avoid any async test patterns — all methods under test are synchronous.
Testing Requirements
Test file structure: test/validation/completeness_rule_evaluator_test.dart, test/validation/threshold_compliance_rule_evaluator_test.dart, test/validation/anomaly_detection_rule_evaluator_test.dart, test/validation/bufdir_field_validation_service_test.dart. Each file uses group() to organise related scenarios. Each test uses expect() with typed matchers (e.g., isA
No mocking frameworks required — use simple in-memory fakes or direct model construction. Run with: flutter test test/validation/. Aim for 100% scenario coverage as listed in the task description; 90% line coverage is the minimum gate.
The exact minimum threshold values required by Bufdir guidelines (e.g., minimum participant counts per section) may not be formally documented in machine-readable form. If thresholds must be researched or negotiated during implementation, the validation service will be delayed and may launch with incomplete rules, reducing its effectiveness.
Mitigation & Contingency
Mitigation: Compile threshold rules from the Bufdir reporting guidelines PDF before sprint start. Store rules in a separate configuration file (not hardcoded in the service class) so they can be updated without a service rewrite. Treat unknown thresholds as 'no minimum' to avoid false errors.
Contingency: Launch with completeness and anomaly validation only, shipping threshold compliance rules as a follow-on config update once rules are confirmed with Bufdir. Flag this as a known limitation in the coordinator help text.
BufdirPreviewService coordinates three async operations (fetch aggregated data, map structure, run validation). Race conditions or partial failures in this chain could produce an inconsistent preview model — e.g., a model with field values but no validation results — which would silently mislead coordinators into thinking the report is clean.
Mitigation & Contingency
Mitigation: Model the orchestration as a single BLoC/Cubit state machine with explicit states (Loading, Loaded, Error) and ensure validation is always run atomically after mapping, never in parallel. Write integration tests that simulate network failure at each step of the chain.
Contingency: If a partial failure state reaches production, detect it via the missing validation summary field in the preview model and show a full-screen error state rather than an incomplete preview, prompting the coordinator to retry.