high priority low complexity testing pending testing specialist Tier 3

Acceptance Criteria

All PeerMentorRepository public methods have at least one passing unit test
fetchMentorProfile(mentorId) happy path: mocked Supabase returns one row → returns correct PeerMentorProfile model with all fields populated
fetchMentorProfile with no matching row: mocked Supabase returns empty list → throws MentorNotFoundException (not null, not generic exception)
updateMentorStatus with a return date: mocked Supabase update called with both status and return_date fields set
updateMentorStatus without a return date: mocked Supabase update called with status field set and return_date explicitly set to null
fetchMentorsByOrg with status filter active: Supabase query receives .eq('status', 'active') and returns mapped list
fetchMentorsByOrg with status filter paused: Supabase query receives .eq('status', 'paused')
fetchMentorsByOrg with null status filter: no status .eq() call is made, all org mentors returned
fetchMentorsByOrg with org that has no mentors: returns empty list
No test attempts to verify RLS enforcement (no tests that pass a cross-org mentorId and expect rejection — that is Supabase's concern)
All tests are independent and can run in any order with no shared mutable state
Test file is located at test/repositories/peer_mentor_repository_test.dart

Technical Requirements

frameworks
Flutter
Dart
flutter_test
mockito (or mocktail)
apis
Mocked Supabase PostgREST builder chain
data models
PeerMentorProfile
MentorStatus enum
MentorNotFoundException
performance requirements
All unit tests must complete in under 5 seconds total — no real network calls permitted
security requirements
Tests must not use real Supabase credentials or connect to any live environment
Mock setup must not accidentally expose real API keys in test fixtures

Execution Context

Execution Tier
Tier 3

Tier 3 - 413 tasks

Can start after Tier 2 completes

Implementation Notes

Mocking the Supabase Flutter client's fluent builder chain (from(), select(), eq(), single(), execute()) requires either a custom fake or mocktail's when().thenAnswer() chaining. Consider creating a shared MockSupabaseBuilder helper in test/helpers/ that other repository test files can reuse — this avoids duplicating the mock chain setup across the three test files in this epic. Do not use @visibleForTesting to expose internal repository state for testing; test only through the public interface. If the repository depends on a SupabaseClient injected via constructor, ensure tests inject the mock via the constructor — do not rely on a global singleton.

Testing Requirements

Pure unit tests using flutter_test. Use mockito's @GenerateMocks or mocktail's registerFallbackValue pattern to mock the Supabase client and PostgREST builder chain. Each test uses setUp() to create a fresh mock instance. Verify mock interactions with verify()/verifyNever() where the absence of a call is the assertion (e.g., no status filter when null is passed).

Use throwsA(isA()) matcher for exception cases. All test descriptions should be written in English and follow the pattern: 'given [context], when [action], then [outcome]'.

Component
Peer Mentor Repository
data low
Epic Risks (3)
high impact medium prob security

Supabase RLS policies for peer mentor data may block coordinator queries if the RLS rules are written for peer-mentor-self access only, requiring policy updates that affect other features sharing the same tables.

Mitigation & Contingency

Mitigation: Review existing RLS policies on peer_mentors, certification_records, and activity_log tables before writing repository queries. Coordinate with the database team to add coordinator-role predicates without weakening existing mentor-self policies.

Contingency: If policy changes are blocked, implement a Supabase Edge Function as a secure query proxy that enforces authorization server-side, avoiding direct RLS policy modification.

medium impact medium prob technical

The activity log table schema may not have a mentor_id foreign key column or may require a JOIN through an intermediate table, making the aggregation query significantly more complex than anticipated.

Mitigation & Contingency

Mitigation: Inspect the actual Supabase activity_log table schema before starting the MentorActivityLogRepository implementation. Document the exact JOIN path needed and validate it returns correct results for a known mentor.

Contingency: If schema requires complex multi-table aggregation, implement a Supabase database function (RPC) and expose it via the repository's fetchSummary method to keep Dart code clean.

high impact low prob dependency

The Blindeforbundet assignment table may not yet exist in the shared Supabase schema or may have a different structure than assumed, blocking the AssignmentHistoryRepository implementation.

Mitigation & Contingency

Mitigation: Verify the assignments table exists and confirm its column structure with the Contact Detail & Edit Screen team which also depends on assignment data (assignment-repository in that feature).

Contingency: If the assignments table is not yet available, implement the AssignmentHistoryRepository with a stub returning empty list and a TODO marker, unblocking the aggregation service while the schema is finalized.