Files
HIPCTF2/tests/frontend/landing-guard.spec.ts
T

27 lines
1.0 KiB
TypeScript

import { decideLandingGuard } from '../../frontend/src/app/core/guards/landing.guard.decision';
describe('decideLandingGuard', () => {
const router = {
createUrlTree: jest.fn((commands: string[]) => ({ kind: 'UrlTree', commands })),
};
beforeEach(() => {
(router.createUrlTree as jest.Mock).mockClear();
});
it('redirects to /bootstrap when not initialized', () => {
const r = decideLandingGuard({ initialized: false, isAuthenticated: false }, router as any);
expect(router.createUrlTree).toHaveBeenCalledWith(['/bootstrap']);
expect((r as any).commands).toEqual(['/bootstrap']);
});
it('redirects to / when initialized and authenticated', () => {
const r = decideLandingGuard({ initialized: true, isAuthenticated: true }, router as any);
expect(router.createUrlTree).toHaveBeenCalledWith(['/']);
expect((r as any).commands).toEqual(['/']);
});
it('allows when initialized and not authenticated', () => {
expect(decideLandingGuard({ initialized: true, isAuthenticated: false }, router as any)).toBe(true);
});
});