Write integration tests for ProxyRegistrationService
epic-coordinator-proxy-registration-core-task-011 — Write integration tests using a Supabase local emulator for ProxyRegistrationService covering: full happy-path creation with valid dual attribution, validator rejection propagation (self-attribution, out-of-scope, duplicate), optimistic rollback on network failure, and correct domain event emission with all attribution fields populated.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Spin up the Supabase local emulator in CI via 'supabase start' in a pre-test step (add to CI workflow yaml). For the optimistic rollback test, inject a fake event publisher that throws on publish and assert no committed row remains after the exception (requires the service to use a Supabase transaction or a compensating delete). Use a dedicated test Supabase project (local) with the full schema migration applied. Structure tests in a test/integration/ directory separate from unit tests.
For duplicate detection, insert a seed proxy_activity row for the same mentor with overlapping date/time before the test call. Ensure the test coordinator and mentor are seeded in the users table with appropriate roles before each relevant test.
Testing Requirements
Integration tests using flutter_test with the Supabase local emulator. Use setUp/tearDown to insert and clean fixture data. Each scenario must be a separate test() block with a descriptive name. Use expect() with typed matchers (isA
For the rollback test, use a Supabase client wrapper that throws after insert to simulate partial failure. Verify database state directly via Supabase client queries inside the test — do not rely solely on return values. All tests tagged 'integration' to allow selective CI execution.
The 2-hour window duplicate detection logic requires querying existing proxy records with compound key matching (mentor + date + activity type within time range). If the query is too broad it produces false positives that frustrate coordinators; if too narrow it misses genuine duplicates that corrupt Bufdir data.
Mitigation & Contingency
Mitigation: Define the duplicate detection window as a configurable parameter from the start. Prototype the Supabase query with representative data covering edge cases (midnight boundaries, different activity types same day, same activity type different mentors) before finalising the implementation.
Contingency: If the detection produces excessive false positives in UAT, allow coordinators to explicitly acknowledge and bypass the duplicate warning with a reason field, preserving safety while reducing friction.
If the proxy registration form does not clearly distinguish between the acting coordinator and the attributed mentor, coordinators may submit records attributing activities to themselves, causing inaccurate Bufdir reporting and potential funding issues.
Mitigation & Contingency
Mitigation: Conduct UAT with at least one real coordinator via TestFlight before release. Use distinct visual treatment (different card colours, explicit 'Registering on behalf of:' label) and require the confirmation screen to show both identities prominently.
Contingency: Add a mandatory confirmation checkbox on the confirmation screen that explicitly names the attributed mentor, preventing accidental self-attribution from slipping through.
Coordinators with multi-chapter access must select an active chapter context before the mentor list is filtered correctly. If chapter scope resolution fails or is bypassed, cross-org proxy registrations could occur, violating data isolation between chapters.
Mitigation & Contingency
Mitigation: Reuse the existing active-chapter-state and hierarchy-service components established by the org hierarchy feature. Add a guard that blocks entry to the proxy flow if no chapter context is active, prompting chapter selection first.
Contingency: If the chapter resolution service is unavailable, default to the most restrictive scope (no mentors visible) and surface a clear error message rather than showing an unfiltered mentor list.