feat: add housekeeping domain registry
This commit is contained in:
1 parent
7edca410fa
commit
2d5f03048a
14 files changed
+694
No files matched your search
@@ -0,0 +1,153 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { PERMS } from "@/lib/permission-slugs";
|
||||
import { HOUSEKEEPING_MANIFESTS } from "../manifests";
|
||||
import {
|
||||
HOUSEKEEPING_DOMAIN_IDS,
|
||||
type HousekeepingDomainId,
|
||||
} from "../migration/types";
|
||||
import { anyCapability, type HousekeepingDomainManifest } from "./contracts";
|
||||
import { createHousekeepingRegistry } from "./registry";
|
||||
|
||||
const manifest = (
|
||||
id: HousekeepingDomainId,
|
||||
capabilitySlug = PERMS.ADMIN_DASHBOARD,
|
||||
): HousekeepingDomainManifest => ({
|
||||
id,
|
||||
labelKey: `pages.housekeeping.domains.${id}.title`,
|
||||
descriptionKey: `pages.housekeeping.domains.${id}.description`,
|
||||
iconId: "settings",
|
||||
previewHref: `/admin-next/${id}`,
|
||||
capability: anyCapability(capabilitySlug),
|
||||
routes: [],
|
||||
});
|
||||
|
||||
describe("housekeeping registry", () => {
|
||||
it("registers the six approved domains in their locked order", () => {
|
||||
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
||||
|
||||
expect(registry.domains.map((domain) => domain.id)).toEqual(
|
||||
HOUSEKEEPING_DOMAIN_IDS,
|
||||
);
|
||||
expect(Object.isFrozen(registry.domains)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects duplicate and unknown domain identifiers", () => {
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
manifest("operations"),
|
||||
manifest("operations"),
|
||||
]),
|
||||
).toThrow("duplicate domain id");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{ ...manifest("operations"), id: "future" as HousekeepingDomainId },
|
||||
]),
|
||||
).toThrow("unknown domain id");
|
||||
});
|
||||
|
||||
it("rejects invalid preview and empty translation keys", () => {
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{ ...manifest("people"), previewHref: "/admin-next/operations" },
|
||||
]),
|
||||
).toThrow("invalid preview href");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([{ ...manifest("people"), labelKey: " " }]),
|
||||
).toThrow("empty label key");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{ ...manifest("people"), descriptionKey: "\t" },
|
||||
]),
|
||||
).toThrow("empty description key");
|
||||
});
|
||||
|
||||
it("rejects duplicate route identities and hrefs", () => {
|
||||
const base = manifest("people");
|
||||
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{
|
||||
...base,
|
||||
routes: [
|
||||
{
|
||||
id: "users",
|
||||
labelKey: "pages.housekeeping.domains.people.title",
|
||||
href: "/admin-next/people/users",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
},
|
||||
{
|
||||
id: "users",
|
||||
labelKey: "pages.housekeeping.domains.people.title",
|
||||
href: "/admin-next/people/staff",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
).toThrow("duplicate route id");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{
|
||||
...base,
|
||||
routes: [
|
||||
{
|
||||
id: "users",
|
||||
labelKey: "pages.housekeeping.domains.people.title",
|
||||
href: "/admin-next/people/users",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
},
|
||||
{
|
||||
id: "staff",
|
||||
labelKey: "pages.housekeeping.domains.people.title",
|
||||
href: "/admin-next/people/users",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
).toThrow("duplicate route href");
|
||||
});
|
||||
|
||||
it("rejects empty route fields and unknown capability slugs", () => {
|
||||
const route = {
|
||||
id: "users",
|
||||
labelKey: "pages.housekeeping.domains.people.title",
|
||||
href: "/admin-next/people/users",
|
||||
capability: anyCapability(PERMS.USERS_VIEW),
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{ ...manifest("people"), routes: [{ ...route, id: " " }] },
|
||||
]),
|
||||
).toThrow("empty route id");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{ ...manifest("people"), routes: [{ ...route, href: " " }] },
|
||||
]),
|
||||
).toThrow("empty route href");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{ ...manifest("people"), routes: [{ ...route, labelKey: " " }] },
|
||||
]),
|
||||
).toThrow("empty route label key");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{
|
||||
...manifest("system"),
|
||||
capability: anyCapability("admin.ghost.view"),
|
||||
},
|
||||
]),
|
||||
).toThrow("unknown capability slug: admin.ghost.view");
|
||||
expect(() =>
|
||||
createHousekeepingRegistry([
|
||||
{
|
||||
...manifest("people"),
|
||||
routes: [
|
||||
{ ...route, capability: anyCapability("admin.ghost.route") },
|
||||
],
|
||||
},
|
||||
]),
|
||||
).toThrow("unknown capability slug: admin.ghost.route");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user