Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+70
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { ADMIN_PERMISSIONS } from "@hivegrid/db/admin-permissions";
|
||||
import { AdminSidebar } from "~/application/sidebar/AdminSidebar";
|
||||
import { getSidebarCommandActions } from "~/services/command-registry/commandRegistry";
|
||||
import { readRepoFile } from "~/utils/testing/repoPaths";
|
||||
import {
|
||||
ADMIN_AREA_ACCESS,
|
||||
ADMIN_ROUTE_ACCESS,
|
||||
adminAreaAllows,
|
||||
} from "./admin-access-contract";
|
||||
|
||||
const t = vi.fn((key: string) => key) as never;
|
||||
|
||||
describe("admin access contract", () => {
|
||||
it("uses catalog permissions and exposes one breadcrumb contract per route", () => {
|
||||
const catalog = new Set<string>(ADMIN_PERMISSIONS);
|
||||
expect(new Set(ADMIN_ROUTE_ACCESS.map((entry) => entry.path)).size).toBe(
|
||||
ADMIN_ROUTE_ACCESS.length
|
||||
);
|
||||
for (const route of ADMIN_ROUTE_ACCESS) {
|
||||
expect(catalog.has(route.permission)).toBe(true);
|
||||
expect(route.breadcrumbKey).toMatch(/^[a-z]/);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps sidebar and command-search source routes on the same permission", () => {
|
||||
const commands = getSidebarCommandActions(
|
||||
AdminSidebar({
|
||||
t,
|
||||
appConfiguration: {
|
||||
app: { features: { tenantApiKeys: true } },
|
||||
} as never,
|
||||
}),
|
||||
"admin"
|
||||
);
|
||||
for (const route of ADMIN_ROUTE_ACCESS) {
|
||||
const command = commands.find((candidate) => candidate.id === route.path);
|
||||
expect(command?.scope.permission, route.path).toBe(route.permission);
|
||||
}
|
||||
});
|
||||
|
||||
it("uses the contract constants in sensitive direct route guards", () => {
|
||||
const directRouteContracts = {
|
||||
dashboard:
|
||||
"apps/web/app/utils/data/.server/adminDashboardRouteData.ts",
|
||||
support: "apps/web/app/routes/admin/support.tsx",
|
||||
health: "apps/web/app/routes/admin/system/index.tsx",
|
||||
jobs: "apps/web/app/routes/admin/system/jobs.tsx",
|
||||
system: "apps/web/app/routes/admin/system/health.tsx",
|
||||
deploys: "apps/web/app/routes/admin/system/deploys.tsx",
|
||||
} as const;
|
||||
|
||||
for (const [area, path] of Object.entries(directRouteContracts)) {
|
||||
expect(readRepoFile(path)).toContain(`ADMIN_AREA_ACCESS.${area}`);
|
||||
}
|
||||
});
|
||||
|
||||
it("unions array requirements and denies unrelated roles", () => {
|
||||
expect(
|
||||
adminAreaAllows(["admin_sales.phone.call"], "salesCommunication")
|
||||
).toBe(true);
|
||||
expect(adminAreaAllows(["admin.dashboard.view"], "support")).toBe(false);
|
||||
expect(
|
||||
adminAreaAllows(
|
||||
[ADMIN_AREA_ACCESS.support],
|
||||
"support"
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user