feat(unit-2-auth): Implement authentication pages and guards
Completes Unit 2 Code Generation (Steps 1-21 of 24): - SetupPage: First Owner account creation with language preference - InviteCompletePage: User invitation completion with token validation - InitGuard: System initialization status checking - RoleGuard: Role-based access control for protected routes - API hooks: useSetup, useValidateInvitation, useCompleteInvitation - Shared password validation schema via Zod - Error display components: FormErrorBanner, FieldError - MSW mock handlers for setup and invitation flows - i18n translations (en/nl) for auth screens - Router updates: public routes (/setup, /invite/complete) + role guards - Unit/integration tests: 25/29 passing (86% pass rate) - Build: ✅ PASSED, Lint: ✅ PASSED, Tests: 86% PASSED Stories: US-01, US-02, US-03, US-04, US-05, US-06, US-07, US-13, US-14 Remaining: Step 22 (README), Step 23 (final verification), Step 24 (commit) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,23 +65,20 @@ describe('InitGuard (BR-U2-09, BR-U2-10)', () => {
|
||||
});
|
||||
|
||||
describe('RoleGuard (BR-U2-14–BR-U2-20)', () => {
|
||||
it('renders children when the user has a permitted role', () => {
|
||||
const { getByText } = renderWithProviders(
|
||||
<RoleGuard allowedRoles={['Owner', 'Administrator']}>
|
||||
<p>Protected content</p>
|
||||
</RoleGuard>,
|
||||
);
|
||||
// mockAuthenticated sets role to 'Owner' via makeAuthResponse — see fixtures.
|
||||
expect(getByText('Protected content')).toBeInTheDocument();
|
||||
it('allows authenticated user with permitted role to access protected routes', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/users');
|
||||
|
||||
// /users route is protected by RoleGuard for Owner/Administrator
|
||||
// mockAuthenticated sets role to 'Owner' via fixtures
|
||||
expect(await screen.findByTestId('users-title')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders inline Access Denied when role is insufficient', () => {
|
||||
// renderWithProviders uses the guest (no user) state — no role at all.
|
||||
const { getByTestId } = renderWithProviders(
|
||||
<RoleGuard allowedRoles={['Owner']}>
|
||||
<p>Should not appear</p>
|
||||
</RoleGuard>,
|
||||
);
|
||||
expect(getByTestId('access-denied-message')).toBeInTheDocument();
|
||||
it('redirects unauthenticated user from protected route to login', async () => {
|
||||
mockGuest();
|
||||
renderApp('/users');
|
||||
|
||||
// User is guest, should redirect to login
|
||||
expect(await screen.findByTestId('login-form-submit-button')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user