Write unit tests for Notification domain model and payloads
epic-in-app-notification-centre-foundation-task-009 — Write comprehensive unit tests covering: correct JSONB deserialization for all five NotificationPayload subtypes (reminder, expiry, scenario, pause, system), roundtrip serialization fidelity (fromJson → toJson produces identical maps), handling of missing or null optional payload fields, NotificationType enum parsing from string values, and copyWith correctness. Use flutter_test. Achieve at minimum 90% branch coverage for the model and payload classes.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Write inline JSON fixture maps as `const Map
If the model uses a factory constructor with a type discriminator field (e.g., `'type': 'reminder'`), ensure the discriminator logic is exercised for each branch. Coverage gaps are most common in error/fallback branches — make sure unknown enum values and malformed optional fields are explicitly tested.
Testing Requirements
Pure unit tests using flutter_test (no WidgetTester needed). Organize tests in `test/features/notifications/domain/notification_model_test.dart`. Use a `fixtures/` map or inline factory helpers for JSON construction — do not rely on file I/O. Group tests by: (1) NotificationType enum parsing, (2) each payload subtype deserialization, (3) roundtrip fidelity per subtype, (4) null/missing field handling, (5) copyWith correctness.
Run `flutter test --coverage` and verify ≥ 90% branch coverage on the model files. No mocking frameworks needed — these are pure data class tests.
Supabase Realtime channels on mobile networks can drop silently. If reconnection logic is flawed, users miss notifications without knowing it, undermining the audit-trail guarantee.
Mitigation & Contingency
Mitigation: Implement exponential-backoff reconnection with a maximum of 5 retries; expose a channel-status stream to the BLoC so it can trigger a full-fetch fallback when the channel reconnects after a gap.
Contingency: If Realtime reliability proves insufficient in production, fall back to polling the repository every 60 seconds as a background supplement to the Realtime channel.
Coordinator and org-admin RLS expansions require joining user_roles and org_memberships tables. An incorrect policy could expose notifications to wrong users or block legitimate access entirely.
Mitigation & Contingency
Mitigation: Write dedicated RLS integration tests for each role (peer mentor, coordinator, org admin) using separate Supabase test projects. Review policies with the security checklist before merging.
Contingency: If an RLS defect is discovered post-deployment, disable the expanded-scope policy and revert to user-scoped-only access while a corrected migration is prepared and tested.
JSONB payload structure may vary across notification types created by different Edge Functions (reminder, expiry, scenario, pause). Missing or renamed fields will cause runtime parse failures.
Mitigation & Contingency
Mitigation: Define a canonical NotificationPayload union type in a shared schema document. Each Edge Function must validate its payload against this schema before inserting. Add fallback parsing with default values in the domain model.
Contingency: Wrap all payload parsing in try/catch and log malformed payloads to a monitoring channel; render a generic notification item rather than crashing when the payload cannot be parsed.