Write unit tests for NoAccessRouteGuard redirect logic
epic-no-access-screen-access-control-task-009 — Write unit tests for the route guard covering: blocked role navigating to /home is redirected to /no-access, blocked role navigating to /logout is allowed through, blocked role navigating to /auth/login is allowed through, unblocked role navigating to /home is allowed through, and unauthenticated user is not affected by the no-access guard. Use flutter_test and GoRouter test utilities.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 7 - 84 tasks
Can start after Tier 6 completes
Implementation Notes
GoRouter guards are typically implemented as a `redirect` callback on `GoRouter` or as a class implementing a `redirect(context, state)` method. Extract the pure logic into a testable function that accepts `isBlocked` (bool) and `location` (String) and returns `String?` — this makes the guard trivially unit-testable without GoRouter internals. The whitelist check should use an explicit `const Set
Testing Requirements
Unit tests using `flutter_test`. The GoRouter `redirect` callback is a plain function — test it by calling the guard's `redirect` method directly with a mocked `GoRouterState` (or a simple data class holding the `location` string) rather than pumping a full widget. Use `mocktail` to stub `AccessDenialService.isBlocked`. Cover all whitelist paths (`/logout`, `/auth/login`) as individual test cases.
Group by scenario: `group('blocked role', ...)` and `group('unblocked role', ...)`. Aim for 100% branch coverage on the guard's redirect logic.
If the GoRouter redirect callback evaluates the no-access route itself as a blocked destination, it will trigger an infinite redirect loop, crashing the navigator.
Mitigation & Contingency
Mitigation: Add an explicit guard condition in the redirect callback: return null (no redirect) when the current location is already the no-access route or the logout route. Write a dedicated unit test covering this exact scenario.
Contingency: If the redirect loop is detected in production, deploy a hotfix that adds the null-return guard; the feature can be toggled off via the existing feature-flag infrastructure while the fix is prepared.
The access-denial-service may read role state before authentication completes (e.g. during app resume), causing a temporary false-positive block that redirects valid peer-mentor users to the no-access screen.
Mitigation & Contingency
Mitigation: Subscribe to the role-state-manager's loading/ready lifecycle and only evaluate role-based access once the RBAC state is confirmed as loaded. Return a 'pending' state that causes the guard to defer rather than redirect.
Contingency: Add a retry mechanism: if a user lands on the no-access screen but their role subsequently resolves as non-blocked, automatically navigate them to the role-based home screen.