59 lines
1.9 KiB
TypeScript
59 lines
1.9 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, searchMock } = vi.hoisted(() => ({
|
|
getContextMock: vi.fn(),
|
|
searchMock: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@/features/housekeeping/commands", () => ({
|
|
housekeepingCommandRegistryReady: true,
|
|
}));
|
|
|
|
vi.mock("@/features/housekeeping/foundation/server-capability-context", () => ({
|
|
getHousekeepingCapabilityContext: getContextMock,
|
|
}));
|
|
|
|
vi.mock("@/features/housekeeping/foundation/search/search-service", () => ({
|
|
searchHousekeeping: searchMock,
|
|
}));
|
|
|
|
import { executeHousekeepingSearch } from "./housekeeping-search";
|
|
|
|
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 search action", () => {
|
|
beforeEach(() => {
|
|
getContextMock.mockReset().mockResolvedValue(context);
|
|
searchMock.mockReset().mockResolvedValue({
|
|
navigation: [],
|
|
commands: [],
|
|
entities: [],
|
|
errors: [],
|
|
correlationId: "action-search",
|
|
});
|
|
});
|
|
|
|
it("binds search to the fresh server capability context", async () => {
|
|
const result = await executeHousekeepingSearch(" users ");
|
|
expect(searchMock).toHaveBeenCalledWith(" users ", context);
|
|
expect(result.correlationId).toBe("action-search");
|
|
});
|
|
|
|
it("rejects forged non-string terms without invoking dependencies", async () => {
|
|
const result = await executeHousekeepingSearch({ term: "users" });
|
|
expect(getContextMock).not.toHaveBeenCalled();
|
|
expect(searchMock).not.toHaveBeenCalled();
|
|
expect(result).toMatchObject({
|
|
errors: [{ providerId: "search", code: "VALIDATION" }],
|
|
});
|
|
});
|
|
});
|