high priority medium complexity testing pending testing specialist Tier 3

Acceptance Criteria

getNotifications: mock returns a list of JSON maps; test asserts the method returns a correctly typed `List<Notification>` with all fields mapped
getNotifications: mock returns an empty list; test asserts method returns an empty list without throwing
getUnreadCount: mock returns an integer count; test asserts method returns the correct `int`
markAsRead: test asserts the correct Supabase update or RPC endpoint is called with the correct notification ID parameter
markAllAsRead: test asserts the correct Supabase update or RPC endpoint is called for the current user's unread notifications
deleteNotification: test asserts the correct Supabase delete is called with the correct notification ID
Role-scoped queries: three separate tests verify that coordinator, peer_mentor, and org_admin roles each produce distinct query filters (e.g., different `.eq()` or `.in_()` calls on the mock)
Network failure: when the mock throws a network exception, getNotifications propagates a typed domain exception (not a raw Supabase exception)
All 8+ test cases pass with `flutter test`
No real Supabase network calls are made during test execution

Technical Requirements

frameworks
flutter_test
mockito or mocktail
apis
Supabase PostgREST query builder API
Supabase RPC API
data models
Notification
UserRole
NotificationRepository
performance requirements
All repository unit tests complete within 10 seconds total
security requirements
Mock setup must not expose real Supabase credentials
Test fixtures must not contain real user IDs or PII

Execution Context

Execution Tier
Tier 3

Tier 3 - 413 tasks

Can start after Tier 2 completes

Implementation Notes

The most complex part is mocking the Supabase query builder chain (`.from().select().eq().order()` etc.). Use mocktail's `when(...).thenAnswer(...)` to stub the terminal call (`.execute()` or equivalent) rather than each intermediate builder step — or use a fake implementation of the SupabaseClient interface if the builder chain is hard to mock. For role-scoped filter verification, capture the query parameters passed to the mock and assert their values rather than asserting on intermediate builder calls, which are brittle. Define a `NotificationRepositoryException` hierarchy in the domain layer so error propagation tests have a concrete type to assert against.

Keep fixture data minimal — one or two notification objects per test is sufficient.

Testing Requirements

Unit tests using flutter_test with a mock Supabase client (use mocktail or mockito — align with project convention). Place tests in `test/features/notifications/data/notification_repository_test.dart`. Structure test groups by method: getNotifications, getUnreadCount, markAsRead, markAllAsRead, deleteNotification, role-scoped filtering, error propagation. For role-scoped tests, instantiate the repository with each of the three role values and capture the query builder calls to verify correct filter application.

For error tests, configure the mock to throw a `PostgrestException` or similar and verify the repository wraps it in a domain-level exception. Do not test Supabase internals — test only the repository's public contract.

Component
Notification Repository
data medium
Epic Risks (3)
high impact medium prob technical

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.

high impact medium prob security

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.

medium impact medium prob integration

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.