Integration smoke test: services wired to real repositories
epic-bufdir-report-period-selection-services-task-009 — Write integration-level smoke tests that wire PeriodPresetService, PeriodRecordCountService, and ReportPeriodValidator against in-memory or local Supabase test instances (not mocks). Verify end-to-end: a preset resolves to a valid DateTimeRange, the record count query returns a non-negative integer, and the validator correctly rejects an overlapping range fetched from the test database. Confirm all three Riverpod providers initialise without errors.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 6 - 158 tasks
Can start after Tier 5 completes
Implementation Notes
Supabase initialisation in integration tests: call `await Supabase.initialize(url: env['SUPABASE_TEST_URL']!, anonKey: env['SUPABASE_TEST_ANON_KEY']!)` in `setUpAll`. Use `Supabase.instance.client` as the client — do not create a second client. Seed data pattern: in `setUp`, insert a submitted period row for `orgId = 'integration-test-org'` with a fixed past range (e.g., January 2025). In `tearDown`, delete all rows where `org_id = 'integration-test-org'`.
If the local Supabase Docker setup is used in CI, add a `supabase start` step in the GitHub Actions workflow before running integration tests. These are smoke tests — they verify wiring, not exhaustive business logic. Exhaustive logic is covered by unit tests in task-008.
Testing Requirements
Use the `integration_test` package for Flutter integration tests. Configure a dedicated Supabase project for CI (separate from staging/production). Use a test helper `SupabaseTestFixtures` class to seed and clean data via the Supabase admin API or direct SQL. Tag all tests with `@Tags(['integration'])` and add a `dart_test.yaml` exclusion so they do not run during `flutter test` (unit test only).
In CI, add a separate job `integration-tests` that sets the required environment variables and runs `flutter test integration_test/`. Document the required Supabase table setup (which rows to seed) in a comment at the top of the test file.
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.