53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { HousekeepingCapabilityContext } from "@/features/housekeeping/foundation/contracts";
|
|
import { PERMS } from "@/lib/permission-slugs";
|
|
|
|
const { getContextMock, loadInboxMock } = vi.hoisted(() => ({
|
|
getContextMock: vi.fn(),
|
|
loadInboxMock: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/features/housekeeping/foundation/server-capability-context", () => ({
|
|
getHousekeepingCapabilityContext: getContextMock,
|
|
}));
|
|
|
|
vi.mock("@/features/housekeeping/foundation/inbox/inbox-service", () => ({
|
|
loadHousekeepingInbox: loadInboxMock,
|
|
}));
|
|
|
|
import { executeHousekeepingInbox } from "./housekeeping-inbox";
|
|
|
|
const context: HousekeepingCapabilityContext = {
|
|
actor: { id: 42, username: "operator", rank: 7 },
|
|
isSuperAdmin: false,
|
|
has: (slug) => slug === PERMS.USERS_VIEW,
|
|
hasAny: (...slugs) => slugs.includes(PERMS.USERS_VIEW),
|
|
hasAll: (...slugs) => slugs.every((slug) => slug === PERMS.USERS_VIEW),
|
|
};
|
|
|
|
describe("housekeeping inbox action", () => {
|
|
beforeEach(() => {
|
|
getContextMock.mockReset().mockResolvedValue(context);
|
|
loadInboxMock.mockReset().mockResolvedValue({
|
|
items: [],
|
|
errors: [],
|
|
correlationId: "inbox-action",
|
|
});
|
|
});
|
|
|
|
it("binds inbox composition to a fresh server capability context", async () => {
|
|
const response = await executeHousekeepingInbox();
|
|
expect(getContextMock).toHaveBeenCalledOnce();
|
|
expect(loadInboxMock).toHaveBeenCalledWith(context);
|
|
expect(response.correlationId).toBe("inbox-action");
|
|
});
|
|
|
|
it("returns a typed partial envelope when the boundary throws", async () => {
|
|
loadInboxMock.mockRejectedValueOnce(new Error("inbox unavailable"));
|
|
const response = await executeHousekeepingInbox();
|
|
expect(response.items).toEqual([]);
|
|
expect(response.errors).toEqual([{ sourceId: "inbox", code: "INTERNAL" }]);
|
|
expect(response.correlationId).toEqual(expect.any(String));
|
|
});
|
|
});
|