feat(housekeeping): compose operational inbox
This commit is contained in:
1 parent
bcb0ca977f
commit
300ac0ef95
13 files changed
+1594
-7
No files matched your search
@@ -0,0 +1,52 @@
|
||||
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));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
"use server";
|
||||
|
||||
import { createCorrelationId } from "@/features/housekeeping/foundation/correlation";
|
||||
import {
|
||||
type HousekeepingInboxResponse,
|
||||
loadHousekeepingInbox,
|
||||
} from "@/features/housekeeping/foundation/inbox/inbox-service";
|
||||
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
||||
|
||||
function failedInbox(): HousekeepingInboxResponse {
|
||||
return {
|
||||
items: [],
|
||||
errors: [{ sourceId: "inbox", code: "INTERNAL" }],
|
||||
correlationId: createCorrelationId(),
|
||||
};
|
||||
}
|
||||
|
||||
export async function executeHousekeepingInbox(): Promise<HousekeepingInboxResponse> {
|
||||
try {
|
||||
const context = await getHousekeepingCapabilityContext();
|
||||
return await loadHousekeepingInbox(context);
|
||||
} catch {
|
||||
return failedInbox();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user