test(api): close assistant split regression gaps
This commit is contained in:
+143
@@ -0,0 +1,143 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { PermissionKey } from "@capakraken/shared";
|
||||
|
||||
vi.mock("@capakraken/application", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@capakraken/application")>();
|
||||
return {
|
||||
...actual,
|
||||
getDashboardBudgetForecast: vi.fn().mockResolvedValue([]),
|
||||
getDashboardPeakTimes: vi.fn().mockResolvedValue([]),
|
||||
listAssignmentBookings: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../sse/event-bus.js", () => ({
|
||||
emitAllocationCreated: vi.fn(),
|
||||
emitAllocationDeleted: vi.fn(),
|
||||
emitAllocationUpdated: vi.fn(),
|
||||
emitProjectShifted: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../lib/budget-alerts.js", () => ({
|
||||
checkBudgetThresholds: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../lib/cache.js", () => ({
|
||||
invalidateDashboardCache: vi.fn(),
|
||||
}));
|
||||
|
||||
import { executeTool } from "../router/assistant-tools.js";
|
||||
import { createToolContext } from "./assistant-tools-advanced-timeline-test-helpers.js";
|
||||
|
||||
describe("assistant advanced timeline holiday overlay tool", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns holiday overlays through the real timeline detail path", async () => {
|
||||
const ctx = createToolContext(
|
||||
{
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "asg_by",
|
||||
projectId: "project_1",
|
||||
resourceId: "res_by",
|
||||
startDate: new Date("2026-01-05T00:00:00.000Z"),
|
||||
endDate: new Date("2026-01-09T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
status: "CONFIRMED",
|
||||
metadata: null,
|
||||
project: {
|
||||
id: "project_1",
|
||||
name: "Gelddruckmaschine",
|
||||
shortCode: "GDM",
|
||||
orderType: "CHARGEABLE",
|
||||
clientId: "client_1",
|
||||
budgetCents: 0,
|
||||
winProbability: 100,
|
||||
status: "ACTIVE",
|
||||
startDate: new Date("2026-01-05T00:00:00.000Z"),
|
||||
endDate: new Date("2026-01-16T00:00:00.000Z"),
|
||||
},
|
||||
resource: {
|
||||
id: "res_by",
|
||||
displayName: "Bayern User",
|
||||
eid: "EMP-BY",
|
||||
chapter: "Delivery",
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
resource: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "res_by",
|
||||
countryId: "country_de",
|
||||
federalState: "BY",
|
||||
metroCityId: null,
|
||||
country: { code: "DE" },
|
||||
metroCity: null,
|
||||
},
|
||||
]),
|
||||
},
|
||||
project: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
holidayCalendar: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
country: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
metroCity: {
|
||||
findUnique: vi.fn(),
|
||||
},
|
||||
},
|
||||
[PermissionKey.USE_ASSISTANT_ADVANCED_TOOLS],
|
||||
);
|
||||
|
||||
const result = await executeTool(
|
||||
"get_timeline_holiday_overlays",
|
||||
JSON.stringify({
|
||||
startDate: "2026-01-05",
|
||||
endDate: "2026-01-09",
|
||||
projectIds: ["project_1"],
|
||||
}),
|
||||
ctx,
|
||||
);
|
||||
|
||||
const parsed = JSON.parse(result.content) as {
|
||||
period: { startDate: string; endDate: string };
|
||||
filters: { projectIds: string[] };
|
||||
summary: {
|
||||
overlayCount: number;
|
||||
holidayResourceCount: number;
|
||||
byScope: Array<{ scope: string; count: number }>;
|
||||
};
|
||||
overlays: Array<{ resourceId: string; startDate: string; note: string; scope: string }>;
|
||||
};
|
||||
|
||||
expect(parsed.period).toEqual({
|
||||
startDate: "2026-01-05",
|
||||
endDate: "2026-01-09",
|
||||
});
|
||||
expect(parsed.filters).toEqual({ projectIds: ["project_1"] });
|
||||
expect(parsed.summary).toEqual({
|
||||
overlayCount: 1,
|
||||
holidayResourceCount: 1,
|
||||
byScope: [{ scope: "STATE", count: 1 }],
|
||||
});
|
||||
expect(parsed.overlays).toEqual([
|
||||
expect.objectContaining({
|
||||
resourceId: "res_by",
|
||||
startDate: "2026-01-06",
|
||||
note: "Heilige Drei Könige",
|
||||
scope: "STATE",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { SystemRole } from "@capakraken/shared";
|
||||
import {
|
||||
createToolContext,
|
||||
executeTool,
|
||||
resetAssistantImportToolTestState,
|
||||
} from "./assistant-tools-import-dispo-webhooks-test-helpers.js";
|
||||
|
||||
describe("assistant project export tools", () => {
|
||||
beforeEach(async () => {
|
||||
await resetAssistantImportToolTestState();
|
||||
});
|
||||
|
||||
it("exports projects CSV through the real import/export router path", async () => {
|
||||
const ctx = createToolContext(
|
||||
{
|
||||
project: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
shortCode: "APO",
|
||||
name: "Apollo",
|
||||
orderType: "CHARGEABLE",
|
||||
status: "ACTIVE",
|
||||
budgetCents: 125000,
|
||||
startDate: new Date("2026-02-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-02-28T00:00:00.000Z"),
|
||||
winProbability: 80,
|
||||
dynamicFields: {},
|
||||
},
|
||||
]),
|
||||
},
|
||||
blueprint: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
},
|
||||
{ userRole: SystemRole.CONTROLLER },
|
||||
);
|
||||
|
||||
const result = await executeTool("export_projects_csv", "{}", ctx);
|
||||
|
||||
expect(JSON.parse(result.content)).toEqual({
|
||||
format: "csv",
|
||||
lineCount: 2,
|
||||
csv: "shortCode,name,orderType,status,budgetCents,startDate,endDate,winProbability\nAPO,Apollo,CHARGEABLE,ACTIVE,125000,2026-02-01,2026-02-28,80",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
createToolContext,
|
||||
executeTool,
|
||||
} from "./assistant-tools-holiday-read-test-helpers.js";
|
||||
|
||||
describe("assistant holiday resolution error paths", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns a stable assistant error when a regional holiday range is incomplete", async () => {
|
||||
const ctx = createToolContext({});
|
||||
|
||||
const result = await executeTool(
|
||||
"list_holidays_by_region",
|
||||
JSON.stringify({ countryCode: "DE", periodStart: "2026-01-01" }),
|
||||
ctx,
|
||||
);
|
||||
|
||||
expect(JSON.parse(result.content)).toEqual({
|
||||
error: "periodStart and periodEnd must both be provided when using a custom holiday range.",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a stable assistant error when resource holidays are requested for an unknown resource", async () => {
|
||||
const ctx = createToolContext({
|
||||
resource: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await executeTool(
|
||||
"get_resource_holidays",
|
||||
JSON.stringify({ identifier: "missing-resource", year: 2026 }),
|
||||
ctx,
|
||||
);
|
||||
|
||||
expect(JSON.parse(result.content)).toEqual({
|
||||
error: "Resource not found: missing-resource",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a stable assistant error when a holiday preview references an unknown country", async () => {
|
||||
const ctx = createToolContext({
|
||||
country: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await executeTool(
|
||||
"preview_resolved_holiday_calendar",
|
||||
JSON.stringify({ countryId: "missing-country", year: 2026 }),
|
||||
ctx,
|
||||
);
|
||||
|
||||
expect(JSON.parse(result.content)).toEqual({
|
||||
error: "Country not found with the given criteria.",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user