39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { decideAuthRedirect } from '../../frontend/src/app/core/guards/auth.guard.decision';
|
|
|
|
function makeRouter() {
|
|
return {
|
|
createUrlTree: jest.fn((cmds: string[]) => ({ __urlTree: true, cmds })),
|
|
};
|
|
}
|
|
|
|
describe('decideAuthRedirect (race-fix core)', () => {
|
|
it('redirects to /bootstrap while bootstrap is uninitialized', () => {
|
|
const router = makeRouter();
|
|
const result = decideAuthRedirect(
|
|
{ initialized: false, isAuthenticated: false },
|
|
router as any,
|
|
);
|
|
expect(router.createUrlTree).toHaveBeenCalledWith(['/bootstrap']);
|
|
expect((result as any).__urlTree).toBe(true);
|
|
});
|
|
|
|
it('redirects to /login when initialized but not authenticated', () => {
|
|
const router = makeRouter();
|
|
const result = decideAuthRedirect(
|
|
{ initialized: true, isAuthenticated: false },
|
|
router as any,
|
|
);
|
|
expect(router.createUrlTree).toHaveBeenCalledWith(['/login']);
|
|
expect((result as any).__urlTree).toBe(true);
|
|
});
|
|
|
|
it('allows navigation when initialized AND authenticated (no /bootstrap redirect)', () => {
|
|
const router = makeRouter();
|
|
const result = decideAuthRedirect(
|
|
{ initialized: true, isAuthenticated: true },
|
|
router as any,
|
|
);
|
|
expect(result).toBe(true);
|
|
expect(router.createUrlTree).not.toHaveBeenCalled();
|
|
});
|
|
}); |