feat(housekeeping): validate preview route runtime
This commit is contained in:
1 parent
d868c990bf
commit
543607a80e
17 files changed
+466
-6
No files matched your search
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { PERMS } from "@/lib/permission-slugs";
|
||||
import { anyCapability, type HousekeepingDomainManifest } from "../contracts";
|
||||
import { createHousekeepingRegistry } from "../registry";
|
||||
import type { HousekeepingRouteHandler } from "./route-handler";
|
||||
import { createHousekeepingRouteRuntime } from "./runtime";
|
||||
|
||||
const peopleManifest = {
|
||||
id: "people",
|
||||
labelKey: "pages.housekeeping.domains.people.title",
|
||||
descriptionKey: "pages.housekeeping.domains.people.description",
|
||||
iconId: "users",
|
||||
previewHref: "/ase-next/people",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
landingRouteId: "people.users",
|
||||
routes: [
|
||||
{
|
||||
id: "people.users",
|
||||
labelKey: "pages.housekeeping.people.users.title",
|
||||
href: "/ase-next/people/users",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
},
|
||||
{
|
||||
id: "people.user-detail",
|
||||
labelKey: "pages.housekeeping.people.userDetail.title",
|
||||
href: "/ase-next/people/users/:id",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
},
|
||||
],
|
||||
searchProviders: [],
|
||||
inboxSources: [],
|
||||
widgets: [],
|
||||
} satisfies HousekeepingDomainManifest;
|
||||
|
||||
const registry = createHousekeepingRegistry([peopleManifest]);
|
||||
|
||||
const handler = (routeId: string): HousekeepingRouteHandler => ({
|
||||
routeId,
|
||||
render: async () => `Rendered ${routeId}`,
|
||||
});
|
||||
|
||||
describe("createHousekeepingRouteRuntime", () => {
|
||||
it("indexes handlers and delegates canonical route matching", () => {
|
||||
const runtime = createHousekeepingRouteRuntime(registry, [
|
||||
handler("people.users"),
|
||||
handler("people.user-detail"),
|
||||
]);
|
||||
|
||||
expect([...runtime.handlers]).toHaveLength(2);
|
||||
expect(runtime.match("/ase-next/people/users/42")).toMatchObject({
|
||||
routeId: "people.user-detail",
|
||||
params: { id: "42" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a route without a handler", () => {
|
||||
expect(() => createHousekeepingRouteRuntime(registry, [])).toThrow(
|
||||
"missing route handler: people.users",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects duplicate handlers", () => {
|
||||
expect(() =>
|
||||
createHousekeepingRouteRuntime(registry, [
|
||||
handler("people.users"),
|
||||
handler("people.users"),
|
||||
]),
|
||||
).toThrow("duplicate route handler: people.users");
|
||||
});
|
||||
|
||||
it("rejects a handler without a route", () => {
|
||||
expect(() =>
|
||||
createHousekeepingRouteRuntime(registry, [handler("people.unknown")]),
|
||||
).toThrow("handler without route: people.unknown");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user