Unit test FCM notification dispatcher
epic-pause-status-notifications-foundation-task-009 — Write unit tests for the FCM dispatcher covering: successful push delivery, in-app record creation, retry exhaustion path, token validation rejection, and atomic failure scenarios. Use mocked FCM HTTP client and mocked Supabase adapter.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
Build MockFcmHttpClient as a class with a Queue
Use expect() with typed matchers: expect(result, isA
Testing Requirements
This task IS the testing task. All tests are unit tests using flutter_test. Use FakeAsync for retry delay simulation. Structure tests in group() blocks by scenario category: 'FCM dispatch channel', 'In-app channel', 'Retry logic', 'Integration (coordinator)'.
Each test uses setUp() to construct a fresh dispatcher instance with injected mocks. Assert on both the returned DispatchResult and side effects (mock call counts, captured arguments). Generate coverage report with flutter test --coverage and verify thresholds before marking task complete.
The org membership table structure used to resolve coordinator relationships may differ from what the repository assumes, causing incorrect coordinator lookup or missing rows for mentors in multi-chapter scenarios.
Mitigation & Contingency
Mitigation: Review the existing org membership table schema and RLS policies before writing repository queries. Align query logic with the patterns already used by peer-mentor-status-repository and multi-chapter-membership-service.
Contingency: If schema differs, add an adapter layer in the repository that normalises the membership resolution and document the discrepancy for the data team. Fall back to coordinator lookup via the feature's own stored coordinator_id field if org membership join fails.
Device tokens stored in the database may be stale or unregistered, causing FCM dispatch failures that silently drop coordinator notifications — the primary coordination safeguard of this feature.
Mitigation & Contingency
Mitigation: Implement token validation on every dispatch call and handle FCM's NOT_REGISTERED error by flagging the token as invalid in the database. Reuse the token refresh pattern already established by fcm-token-manager.
Contingency: If push delivery fails after retry, ensure the in-app notification record is always written regardless of push outcome so coordinators can still see the event in the notification centre.
The optional reason field may contain special characters, emoji, or non-Latin scripts that exceed the 200-character byte limit when FCM encodes the payload, causing delivery failures.
Mitigation & Contingency
Mitigation: Enforce the 200-character limit on Unicode code point count, not byte count, in the payload builder. Add a unit test with multi-byte input strings.
Contingency: If an oversized payload is detected at dispatch time, strip the reason field from the push notification body and note 'See in-app notification for full reason' to preserve delivery.