import { describe, expect, it, vi } from "vitest"; import { getRoute } from "../../src/features/installed-feature-contracts.ts"; import { decideRouteAccess } from "../../src/presentation/routes/navigation-policy.ts"; /** * 1105/10-01. The route access rule on the platform's own test feature * (`tests/helpers/fixture-feature.tsx`), not on the removable sample. The * sample owns every session-required route the template installs, so with it * removed navigation-policy.test.ts loops over no protected route at all. * `scripts/test-sample-removal.ts` keeps this file. */ vi.mock("../../src/.generated/product-feature-index.ts", async () => ({ DECLARED_PRODUCT_FEATURE_IDS: ["fixture-feature"], PRODUCT_FEATURE_MODULES: [ (await import("../helpers/fixture-feature.tsx")).FIXTURE_FEATURE_MODULE, ], })); vi.mock("../../src/.generated/product-context-index.ts", async () => ({ PRODUCT_CONTEXT_MODULES: [ (await import("../helpers/fixture-feature.tsx")).FIXTURE_CONTEXT_MODULE, ], })); const SESSION_ROUTE = "FIXTURE_ITEMS"; describe("route access on an installed session-required route", () => { it("installs the fixture route as session-required", () => { expect(getRoute(SESSION_ROUTE).access).toBe("session-required"); }); it.each([ ["authenticated", { allowed: true, action: "none" }], ["unauthenticated", { allowed: false, action: "show-sign-in" }], // 1101/10-03. A session still being recovered waits; showing sign-in // there would bounce a returning user out of a page they may enter. ["recovery-pending", { allowed: false, action: "wait-for-session" }], ["integration-failed", { allowed: false, action: "show-sign-in" }], ] as const)("answers a %s session with %o", (sessionState, decision) => { expect(decideRouteAccess(SESSION_ROUTE, sessionState)).toEqual(decision); }); it("lets every session state through a public route", () => { expect(getRoute("FIXTURE_FIRST_PAGE").access).toBe("public"); for (const sessionState of [ "authenticated", "unauthenticated", "recovery-pending", "integration-failed", ] as const) { expect(decideRouteAccess("FIXTURE_FIRST_PAGE", sessionState)).toEqual({ allowed: true, action: "none", }); } }); });