feat: add housekeeping capability context
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { getAdminContext } = vi.hoisted(() => ({ getAdminContext: vi.fn() }));
|
||||
|
||||
vi.mock("react", () => ({
|
||||
cache: <T extends (...args: never[]) => unknown>(callback: T) => callback,
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/permissions", () => ({ getAdminContext }));
|
||||
|
||||
import { getHousekeepingCapabilityContext } from "./server-capability-context";
|
||||
|
||||
describe("getHousekeepingCapabilityContext", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
getAdminContext.mockResolvedValue({
|
||||
session: {
|
||||
user: {
|
||||
id: 42,
|
||||
username: "operator",
|
||||
rank: 7,
|
||||
},
|
||||
},
|
||||
permissions: {
|
||||
isSuperAdmin: false,
|
||||
has: (slug: string) => slug === "admin.users.view",
|
||||
hasAny: (...slugs: string[]) => slugs.includes("admin.users.view"),
|
||||
hasAll: (...slugs: string[]) =>
|
||||
slugs.every((slug) => slug === "admin.users.view"),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the refreshed administrator actor and forwarded permissions", async () => {
|
||||
const context = await getHousekeepingCapabilityContext();
|
||||
|
||||
expect(context).toMatchObject({
|
||||
actor: { id: 42, username: "operator", rank: 7 },
|
||||
isSuperAdmin: false,
|
||||
});
|
||||
expect(context.has("admin.users.view")).toBe(true);
|
||||
expect(context.has("admin.logs.view")).toBe(false);
|
||||
expect(getAdminContext).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user