Files
Nexus/packages/api/src/__tests__/assistant-tools-dispo-import-batch-delegation.test.ts
T
Hartmut b41c1d2501
CI / Architecture Guardrails (push) Successful in 2m38s
CI / Assistant Split Regression (push) Successful in 3m33s
CI / Typecheck (push) Successful in 3m51s
CI / Lint (push) Successful in 5m2s
CI / E2E Tests (push) Has been cancelled
CI / Fresh-Linux Docker Deploy (push) Has been cancelled
CI / Release Images (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
rename(phase 1): CapaKraken → Nexus across code, UI, docs, CI (#61)
rename(phase 1): CapaKraken → Nexus across code, UI, docs, CI (#61)

Co-authored-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
Co-committed-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
2026-05-21 16:28:40 +02:00

150 lines
4.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { ImportBatchStatus } from "@nexus/db";
import { SystemRole } from "@nexus/shared";
vi.mock("@nexus/application", async (importOriginal) => {
const actual = await importOriginal<typeof import("@nexus/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 {
assessDispoImportReadiness,
commitDispoImportBatch,
stageDispoImportBatch,
} from "@nexus/application";
import { executeTool } from "../router/assistant-tools.js";
import { createToolContext } from "./assistant-tools-dispo-test-helpers.js";
describe("assistant dispo import batch delegation tools", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("delegates dispo import batch staging through the real router path", async () => {
vi.mocked(stageDispoImportBatch).mockResolvedValue({
id: "batch_1",
status: ImportBatchStatus.STAGED,
} as never);
const ctx = createToolContext({}, { userRole: SystemRole.ADMIN });
const result = await executeTool(
"stage_dispo_import_batch",
JSON.stringify({
chargeabilityWorkbookPath: "chargeability.xlsx",
planningWorkbookPath: "planning.xlsx",
referenceWorkbookPath: "reference.xlsx",
costWorkbookPath: "cost.xlsx",
rosterWorkbookPath: "roster.xlsx",
notes: "March import",
}),
ctx,
);
expect(stageDispoImportBatch).toHaveBeenCalledWith(ctx.db, {
chargeabilityWorkbookPath: "chargeability.xlsx",
planningWorkbookPath: "planning.xlsx",
referenceWorkbookPath: "reference.xlsx",
costWorkbookPath: "cost.xlsx",
rosterWorkbookPath: "roster.xlsx",
notes: "March import",
});
expect(JSON.parse(result.content)).toEqual({
id: "batch_1",
status: ImportBatchStatus.STAGED,
});
});
it("delegates dispo import batch validation through the real router path", async () => {
vi.mocked(assessDispoImportReadiness).mockResolvedValue({
ready: false,
checks: [{ key: "stagedResources", status: "warning" }],
} as never);
const ctx = createToolContext({}, { userRole: SystemRole.ADMIN });
const result = await executeTool(
"validate_dispo_import_batch",
JSON.stringify({
chargeabilityWorkbookPath: "chargeability.xlsx",
planningWorkbookPath: "planning.xlsx",
referenceWorkbookPath: "reference.xlsx",
importBatchId: "batch_1",
}),
ctx,
);
expect(assessDispoImportReadiness).toHaveBeenCalledWith({
chargeabilityWorkbookPath: "chargeability.xlsx",
planningWorkbookPath: "planning.xlsx",
referenceWorkbookPath: "reference.xlsx",
importBatchId: "batch_1",
});
expect(JSON.parse(result.content)).toEqual({
ready: false,
checks: [{ key: "stagedResources", status: "warning" }],
});
});
it("delegates dispo import batch commits through the real router path", async () => {
vi.mocked(commitDispoImportBatch).mockResolvedValue({
importedAssignments: 7,
importedProjects: 3,
} as never);
const ctx = createToolContext(
{
auditLog: {
create: vi.fn().mockResolvedValue(undefined),
},
},
{ userRole: SystemRole.ADMIN },
);
const result = await executeTool(
"commit_dispo_import_batch",
JSON.stringify({
importBatchId: "batch_1",
allowTbdUnresolved: true,
importTbdProjects: false,
}),
ctx,
);
expect(commitDispoImportBatch).toHaveBeenCalledWith(ctx.db, {
importBatchId: "batch_1",
allowTbdUnresolved: true,
importTbdProjects: false,
});
expect(JSON.parse(result.content)).toEqual({
importedAssignments: 7,
importedProjects: 3,
});
});
});