298 lines
8.0 KiB
TypeScript
298 lines
8.0 KiB
TypeScript
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: [],
|
|
});
|
|
|
|
const expectedManifests = [
|
|
{
|
|
id: "operations",
|
|
iconId: "inbox",
|
|
previewHref: "/admin-next/operations",
|
|
labelKey: "pages.housekeeping.domains.operations.title",
|
|
descriptionKey: "pages.housekeeping.domains.operations.description",
|
|
slugs: [PERMS.ADMIN_DASHBOARD],
|
|
},
|
|
{
|
|
id: "people",
|
|
iconId: "users",
|
|
previewHref: "/admin-next/people",
|
|
labelKey: "pages.housekeeping.domains.people.title",
|
|
descriptionKey: "pages.housekeeping.domains.people.description",
|
|
slugs: [
|
|
PERMS.USERS_VIEW,
|
|
PERMS.MODERATION_VIEW,
|
|
PERMS.TICKETS_VIEW,
|
|
PERMS.BANS_VIEW,
|
|
PERMS.MOD_DASHBOARD,
|
|
PERMS.MOD_CFH_VIEW,
|
|
PERMS.MOD_TEAM_VIEW,
|
|
PERMS.MOD_TICKETS_VIEW,
|
|
PERMS.MOD_USERS_VIEW,
|
|
PERMS.MOD_BANS_VIEW,
|
|
],
|
|
},
|
|
{
|
|
id: "content",
|
|
iconId: "file-text",
|
|
previewHref: "/admin-next/content",
|
|
labelKey: "pages.housekeeping.domains.content.title",
|
|
descriptionKey: "pages.housekeeping.domains.content.description",
|
|
slugs: [
|
|
PERMS.NEWS_VIEW,
|
|
PERMS.PAGES_VIEW,
|
|
PERMS.BANNERS_VIEW,
|
|
PERMS.EVENTS_VIEW,
|
|
PERMS.POLLS_VIEW,
|
|
PERMS.PREFIXES_VIEW,
|
|
],
|
|
},
|
|
{
|
|
id: "economy",
|
|
iconId: "gem",
|
|
previewHref: "/admin-next/economy",
|
|
labelKey: "pages.housekeeping.domains.economy.title",
|
|
descriptionKey: "pages.housekeeping.domains.economy.description",
|
|
slugs: [PERMS.CATALOG_VIEW, PERMS.SHOP_VIEW],
|
|
},
|
|
{
|
|
id: "hotel",
|
|
iconId: "hotel",
|
|
previewHref: "/admin-next/hotel",
|
|
labelKey: "pages.housekeeping.domains.hotel.title",
|
|
descriptionKey: "pages.housekeeping.domains.hotel.description",
|
|
slugs: [PERMS.ROOMS_VIEW, PERMS.RADIO_VIEW, PERMS.ASSETS_IMPORT],
|
|
},
|
|
{
|
|
id: "system",
|
|
iconId: "settings",
|
|
previewHref: "/admin-next/system",
|
|
labelKey: "pages.housekeeping.domains.system.title",
|
|
descriptionKey: "pages.housekeeping.domains.system.description",
|
|
slugs: [
|
|
PERMS.SETTINGS_VIEW,
|
|
PERMS.LOGS_VIEW,
|
|
PERMS.ANALYTICS_VIEW,
|
|
PERMS.DEVOPS_VIEW,
|
|
PERMS.NOTIFICATIONS_VIEW,
|
|
PERMS.PERMISSIONS_MANAGE,
|
|
PERMS.RCON_EXECUTE,
|
|
],
|
|
},
|
|
] as const;
|
|
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");
|
|
});
|
|
it("locks every real manifest to its approved presentation and capability group", () => {
|
|
expect(HOUSEKEEPING_MANIFESTS).toHaveLength(6);
|
|
|
|
for (const [index, expected] of expectedManifests.entries()) {
|
|
const actual = HOUSEKEEPING_MANIFESTS[index];
|
|
|
|
expect(actual).toMatchObject({
|
|
id: expected.id,
|
|
iconId: expected.iconId,
|
|
previewHref: expected.previewHref,
|
|
labelKey: expected.labelKey,
|
|
descriptionKey: expected.descriptionKey,
|
|
});
|
|
expect(actual.routes).toEqual([]);
|
|
expect(actual.capability).toEqual({ mode: "any", slugs: expected.slugs });
|
|
}
|
|
});
|
|
|
|
it("rejects empty domain and route capability requirements", () => {
|
|
expect(() =>
|
|
createHousekeepingRegistry([
|
|
{ ...manifest("operations"), capability: { mode: "any", slugs: [] } },
|
|
]),
|
|
).toThrow("empty capability requirement");
|
|
expect(() =>
|
|
createHousekeepingRegistry([
|
|
{
|
|
...manifest("people"),
|
|
routes: [
|
|
{
|
|
id: "users",
|
|
labelKey: "pages.housekeeping.domains.people.title",
|
|
href: "/admin-next/people/users",
|
|
capability: { mode: "any", slugs: [] },
|
|
},
|
|
],
|
|
},
|
|
]),
|
|
).toThrow("empty capability requirement");
|
|
});
|
|
|
|
it("rejects duplicate route identities and hrefs across domains", () => {
|
|
const route = {
|
|
id: "shared",
|
|
labelKey: "pages.housekeeping.domains.people.title",
|
|
href: "/admin-next/shared",
|
|
capability: anyCapability(PERMS.USERS_VIEW),
|
|
};
|
|
|
|
expect(() =>
|
|
createHousekeepingRegistry([
|
|
{ ...manifest("people"), routes: [route] },
|
|
{
|
|
...manifest("content"),
|
|
routes: [{ ...route, href: "/admin-next/content/shared" }],
|
|
},
|
|
]),
|
|
).toThrow("duplicate route id");
|
|
expect(() =>
|
|
createHousekeepingRegistry([
|
|
{ ...manifest("people"), routes: [route] },
|
|
{
|
|
...manifest("content"),
|
|
routes: [{ ...route, id: "content-shared" }],
|
|
},
|
|
]),
|
|
).toThrow("duplicate route href");
|
|
});
|
|
});
|