4a49ec4f05
- G-01: ProjectWizard renders blueprint fieldDefs with DynamicFieldInput component - G-02: Blueprint rolePresets validated via RolePresetsSchema in wizard; API keeps loose schema - G-03: ProjectWizard step 2/3 validation (role, hoursPerDay, headcount required) - G-04: EstimateWizard validates baseCurrency and demand line cost rates - G-05: Project lifecycle transition guards with ALLOWED_TRANSITIONS map - G-06: Blueprint validator extended for minLength/maxLength/pattern and DATE range checks - G-07: assertBlueprintDynamicFields merges global blueprint fieldDefs into validation - G-08: (tracked — chapter managed dropdown; deferred to backend ticket) - G-09: JSDoc added to lcrCents/ucrCents clarifying LCR/UCR terminology - G-10: Dispo route redirect already in place — closed as done - G-11: packages/ui empty by design — closed as documented - G-12: @deprecated JSDoc added to CreateAllocationSchema and UpdateAllocationSchema - G-13: ProjectWizard review step enhanced with blueprint name, field values, skills, assignments - G-14: ProjectWizard handleSubmit collects per-item warnings instead of silent swallowing - G-15: Vacation cancel reverses usedDays entitlement for APPROVED ANNUAL/OTHER vacations Tests: all 1575 passing (1 pre-existing failure in insights-summary unrelated to these changes) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
165 lines
4.5 KiB
TypeScript
165 lines
4.5 KiB
TypeScript
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),
|
|
findMany: vi.fn().mockResolvedValue([]),
|
|
},
|
|
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);
|
|
});
|
|
|
|
it("applies assistant-side default project fields when optional create inputs are omitted", async () => {
|
|
const projectCreate = vi.fn().mockResolvedValue({
|
|
id: "project_2",
|
|
shortCode: "PROJ-DEFAULTS",
|
|
name: "Project Defaults",
|
|
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,
|
|
},
|
|
auditLog: {
|
|
create: vi.fn().mockResolvedValue({ id: "audit_2" }),
|
|
},
|
|
},
|
|
{
|
|
userRole: SystemRole.ADMIN,
|
|
permissions: [PermissionKey.MANAGE_PROJECTS],
|
|
},
|
|
);
|
|
|
|
const result = await executeTool(
|
|
"create_project",
|
|
JSON.stringify({
|
|
shortCode: "PROJ-DEFAULTS",
|
|
name: "Project Defaults",
|
|
orderType: "CHARGEABLE",
|
|
budgetCents: 250000,
|
|
startDate: "2026-07-01",
|
|
endDate: "2026-07-31",
|
|
responsiblePerson: "Peter Parker",
|
|
}),
|
|
ctx,
|
|
);
|
|
|
|
expect(JSON.parse(result.content)).toEqual(
|
|
expect.objectContaining({
|
|
success: true,
|
|
projectId: "project_2",
|
|
shortCode: "PROJ-DEFAULTS",
|
|
}),
|
|
);
|
|
expect(projectCreate).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
data: expect.objectContaining({
|
|
allocationType: "INT",
|
|
winProbability: 100,
|
|
status: "DRAFT",
|
|
staffingReqs: [],
|
|
dynamicFields: {},
|
|
responsiblePerson: "Peter Parker",
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
});
|