42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
NAVIGATION_ROUTES,
|
|
ROUTE_REGISTRY,
|
|
} from "../../src/features/installed-feature-contracts.js";
|
|
import {
|
|
createRedirectLoopGuard,
|
|
decideRouteAccess,
|
|
} from "../../src/presentation/routes/navigation-policy.js";
|
|
|
|
describe("installed route registry", () => {
|
|
it("derives visible navigation in explicit order", () => {
|
|
const expected = Object.values(ROUTE_REGISTRY)
|
|
.filter((route) => route.navigationOrder !== null)
|
|
.sort(
|
|
(left, right) =>
|
|
/** @type {number} */ (left.navigationOrder) -
|
|
/** @type {number} */ (right.navigationOrder),
|
|
)
|
|
.map((route) => route.routeId);
|
|
expect(NAVIGATION_ROUTES.map(({ routeId }) => routeId)).toEqual(expected);
|
|
});
|
|
|
|
it("allows public routes without consulting a product permission", () => {
|
|
expect(decideRouteAccess("APP_HOME", "unauthenticated")).toEqual({
|
|
allowed: true,
|
|
action: "none",
|
|
});
|
|
});
|
|
|
|
it("bounds automatic redirects by pair and maximum hops", () => {
|
|
const guard = createRedirectLoopGuard(2);
|
|
expect(guard.allow("/private", "/signin")).toBe(true);
|
|
expect(guard.allow("/private", "/signin")).toBe(false);
|
|
expect(guard.allow("/signin", "/signin")).toBe(false);
|
|
expect(guard.allow("/signin", "/continue")).toBe(true);
|
|
expect(guard.allow("/continue", "/final")).toBe(false);
|
|
expect(guard.hopCount).toBe(2);
|
|
});
|
|
});
|