d2caba8d7c
Hardcoded dates (2026-03-20 / 2026-04-05) were now in the past, causing the demand window filter (endDate >= now) to exclude the mock demand requirement and miss the expected staffing anomaly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
144 lines
4.4 KiB
TypeScript
144 lines
4.4 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("@capakraken/application", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("@capakraken/application")>();
|
|
return {
|
|
...actual,
|
|
approveEstimateVersion: vi.fn(),
|
|
cloneEstimate: vi.fn(),
|
|
commitDispoImportBatch: vi.fn(),
|
|
countPlanningEntries: vi.fn().mockResolvedValue({ countsByRoleId: new Map() }),
|
|
createEstimateExport: vi.fn(),
|
|
createEstimatePlanningHandoff: vi.fn(),
|
|
createEstimateRevision: vi.fn(),
|
|
assessDispoImportReadiness: vi.fn(),
|
|
loadResourceDailyAvailabilityContexts: vi.fn().mockResolvedValue(new Map()),
|
|
getDashboardDemand: vi.fn().mockResolvedValue([]),
|
|
getDashboardBudgetForecast: vi.fn().mockResolvedValue([]),
|
|
getDashboardOverview: vi.fn(),
|
|
getDashboardSkillGapSummary: vi.fn().mockResolvedValue({
|
|
roleGaps: [],
|
|
totalOpenPositions: 0,
|
|
skillSupplyTop10: [],
|
|
resourcesByRole: [],
|
|
}),
|
|
getDashboardProjectHealth: vi.fn().mockResolvedValue([]),
|
|
getDashboardPeakTimes: vi.fn().mockResolvedValue([]),
|
|
getDashboardTopValueResources: vi.fn().mockResolvedValue([]),
|
|
getEstimateById: vi.fn(),
|
|
listAssignmentBookings: vi.fn().mockResolvedValue([]),
|
|
stageDispoImportBatch: vi.fn(),
|
|
submitEstimateVersion: vi.fn(),
|
|
updateEstimateDraft: vi.fn(),
|
|
};
|
|
});
|
|
|
|
import { executeTool } from "../router/assistant-tools.js";
|
|
import { SystemRole } from "@capakraken/shared";
|
|
import { createToolContext } from "./assistant-tools-insights-scenarios-test-helpers.js";
|
|
|
|
describe("assistant insights summary tools", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("routes insights summary reads through the insights router path", async () => {
|
|
const now = new Date();
|
|
const daysAgo = (n: number) => new Date(now.getTime() - n * 24 * 60 * 60 * 1000);
|
|
const daysFromNow = (n: number) => new Date(now.getTime() + n * 24 * 60 * 60 * 1000);
|
|
|
|
const db = {
|
|
project: {
|
|
findMany: vi.fn().mockResolvedValue([
|
|
{
|
|
budgetCents: 100_000,
|
|
startDate: daysAgo(30),
|
|
endDate: daysFromNow(30),
|
|
demandRequirements: [
|
|
{
|
|
headcount: 3,
|
|
startDate: daysAgo(5),
|
|
endDate: daysFromNow(10),
|
|
_count: { assignments: 1 },
|
|
},
|
|
],
|
|
assignments: [
|
|
{
|
|
resourceId: "res_1",
|
|
startDate: daysAgo(30),
|
|
endDate: daysFromNow(30),
|
|
hoursPerDay: 8,
|
|
dailyCostCents: 10_000,
|
|
status: "ACTIVE",
|
|
},
|
|
],
|
|
},
|
|
]),
|
|
},
|
|
resource: {
|
|
findMany: vi.fn().mockResolvedValue([
|
|
{
|
|
id: "res_1",
|
|
availability: { monday: 8, tuesday: 8, wednesday: 8, thursday: 8, friday: 8 },
|
|
},
|
|
]),
|
|
},
|
|
assignment: {
|
|
findMany: vi.fn().mockResolvedValue([
|
|
{
|
|
resourceId: "res_1",
|
|
hoursPerDay: 2,
|
|
},
|
|
]),
|
|
},
|
|
};
|
|
const ctx = createToolContext(db, { userRole: SystemRole.CONTROLLER });
|
|
|
|
const result = await executeTool("get_insights_summary", "{}", ctx);
|
|
|
|
expect(db.project.findMany).toHaveBeenCalledWith({
|
|
where: { status: { in: ["ACTIVE", "DRAFT"] } },
|
|
include: {
|
|
demandRequirements: {
|
|
select: {
|
|
headcount: true,
|
|
startDate: true,
|
|
endDate: true,
|
|
_count: { select: { assignments: true } },
|
|
},
|
|
},
|
|
assignments: {
|
|
select: {
|
|
resourceId: true,
|
|
startDate: true,
|
|
endDate: true,
|
|
hoursPerDay: true,
|
|
dailyCostCents: true,
|
|
status: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(db.resource.findMany).toHaveBeenCalledWith({
|
|
where: { isActive: true },
|
|
select: { id: true, displayName: true, availability: true },
|
|
});
|
|
expect(db.assignment.findMany).toHaveBeenCalledWith({
|
|
where: {
|
|
status: { in: ["ACTIVE", "CONFIRMED"] },
|
|
startDate: { lte: expect.any(Date) },
|
|
endDate: { gte: expect.any(Date) },
|
|
},
|
|
select: { resourceId: true, hoursPerDay: true },
|
|
});
|
|
expect(JSON.parse(result.content)).toEqual({
|
|
total: 3,
|
|
criticalCount: 2,
|
|
budget: 1,
|
|
staffing: 1,
|
|
timeline: 0,
|
|
utilization: 1,
|
|
});
|
|
});
|
|
});
|