End-to-end testing: honorarium flow and accounting export
epic-travel-expense-registration-org-extensions-task-008 — Write integration and widget tests covering the full driver honorarium flow: feature-flag guard renders form only for Blindeforbundet, rate guidance is displayed, submission is blocked until declaration is acknowledged, honorarium record is persisted with correct timestamps. Write integration tests for the AccountingIntegrationClient covering field mapping correctness for both Xledger and Dynamics adapters, retry behaviour on 5xx responses, double-export guard prevents duplicate submissions, and audit records are created for every attempt. Use mock HTTP adapters to simulate accounting system responses.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
For widget tests, set up a BlocProvider
For the double-export guard test, pre-insert a successful export_runs record in the local Supabase test database before running the guard assertion. Use Supabase local dev (supabase start) for database integration tests. Document any test data setup/teardown in a dedicated test README section.
Testing Requirements
Test types: Flutter widget tests (flutter_test), Flutter integration tests (integration_test package), Deno unit/integration tests. Use mocktail for mocking DriverHonorariumService and Supabase client in Flutter tests. Use Deno's built-in fetch mock (or a lightweight mock HTTP server) for Edge Function tests. Organise tests into: /test/widget/driver_honorarium_form_test.dart, /test/integration/driver_honorarium_flow_test.dart, /edge_functions/test/accounting_integration_test.ts.
All tests must be deterministic (no flakiness from real network or time-dependent behaviour — mock DateTime.now() and HTTP). Run via flutter test and deno test in CI.
The Dynamics portal (HLF) and Xledger (Blindeforbundet) APIs have organisation-managed API contracts that may change without notice. Field mapping requirements, authentication flows, and export formats are not fully documented and may only be clarified during integration testing.
Mitigation & Contingency
Mitigation: Engage HLF and Blindeforbundet technical contacts early to obtain API documentation, sandbox credentials, and example payloads before implementation starts. Design the accounting integration client as a thin adapter layer with organisation-specific mappers so that field mapping changes require only mapper updates, not core client changes.
Contingency: If API documentation is unavailable or the API is unstable during Phase 3, implement a CSV/JSON file export as an interim deliverable. Coordinators can manually upload the file to their respective accounting systems until the live API integration is completed.
The confidentiality declaration for Blindeforbundet drivers may have specific legal requirements around content, format, wording, and record-keeping that are not yet specified. Implementing the wrong declaration flow could expose Blindeforbundet to compliance risk.
Mitigation & Contingency
Mitigation: Treat the declaration content and acknowledgement flow as a Blindeforbundet-controlled configuration, not hardcoded text. Implement the declaration as a templated document fetched from Supabase and reviewed by Blindeforbundet before any production deployment. Obtain written sign-off on the declaration text and acknowledgement mechanism before the epic is considered complete.
Contingency: If legal requirements cannot be confirmed in time for the sprint, deliver the driver honorarium form without the confidentiality declaration and gate the entire driver feature behind its feature flag. The declaration can be added in a follow-up sprint once requirements are confirmed, without blocking other feature delivery.
If the accounting export can be triggered multiple times for the same approved claims batch, duplicate records may be created in Dynamics or Xledger, causing accounting reconciliation problems that are difficult to reverse.
Mitigation & Contingency
Mitigation: Implement idempotent export runs: each export batch is assigned a unique run ID stored in the database. The accounting integration client checks for an existing successful export run for the same claim IDs before submitting. Approved claims that have been exported are marked with exported_at timestamp to prevent re-export.
Contingency: If duplicate exports occur despite idempotency checks (e.g. network failure after API success but before local confirmation), provide coordinators with an export history panel showing run IDs and timestamps. Implement a reconciliation endpoint that can query the accounting system for existing records before re-submitting flagged claims.