test(api): cover assistant project admin mutations
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { PermissionKey, SystemRole } from "@capakraken/shared";
|
||||
import {
|
||||
createToolContext,
|
||||
executeTool,
|
||||
} from "./assistant-tools-project-admin-create-test-helpers.js";
|
||||
|
||||
describe("assistant project admin create tools - success", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("routes project creation through the real project, blueprint, and client router paths", async () => {
|
||||
const auditCreate = vi.fn().mockResolvedValue({ id: "audit_1" });
|
||||
const projectCreate = vi.fn().mockResolvedValue({
|
||||
id: "project_1",
|
||||
shortCode: "PROJ-1",
|
||||
name: "Project One",
|
||||
status: "DRAFT",
|
||||
});
|
||||
const ctx = createToolContext(
|
||||
{
|
||||
resource: {
|
||||
findFirst: vi.fn().mockResolvedValue({
|
||||
displayName: "Peter Parker",
|
||||
}),
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
project: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
create: projectCreate,
|
||||
},
|
||||
blueprint: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "bp_1",
|
||||
name: "Consulting Blueprint",
|
||||
target: "PROJECT",
|
||||
fieldDefs: [],
|
||||
}),
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
client: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "client_1",
|
||||
name: "Acme",
|
||||
code: "ACME",
|
||||
_count: { projects: 0, children: 0 },
|
||||
}),
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
webhook: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
auditLog: {
|
||||
create: auditCreate,
|
||||
},
|
||||
},
|
||||
{
|
||||
userRole: SystemRole.ADMIN,
|
||||
permissions: [PermissionKey.MANAGE_PROJECTS],
|
||||
},
|
||||
);
|
||||
|
||||
const result = await executeTool(
|
||||
"create_project",
|
||||
JSON.stringify({
|
||||
shortCode: "PROJ-1",
|
||||
name: "Project One",
|
||||
orderType: "CHARGEABLE",
|
||||
budgetCents: 150000,
|
||||
startDate: "2026-05-01",
|
||||
endDate: "2026-06-30",
|
||||
responsiblePerson: "Peter Parker",
|
||||
blueprintName: "Consulting Blueprint",
|
||||
clientName: "ACME",
|
||||
}),
|
||||
ctx,
|
||||
);
|
||||
|
||||
expect(JSON.parse(result.content)).toEqual(
|
||||
expect.objectContaining({
|
||||
success: true,
|
||||
message: expect.stringContaining("Created project: Project One (PROJ-1), budget "),
|
||||
projectId: "project_1",
|
||||
}),
|
||||
);
|
||||
expect(projectCreate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
shortCode: "PROJ-1",
|
||||
blueprintId: "bp_1",
|
||||
clientId: "client_1",
|
||||
responsiblePerson: "Peter Parker",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(auditCreate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user