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) Co-authored-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com> Co-committed-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
111 lines
3.6 KiB
TypeScript
111 lines
3.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
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 {
|
|
createHappyPathDb,
|
|
createToolContext,
|
|
executeTool,
|
|
} from "./assistant-tools-vacation-mutation-test-helpers.js";
|
|
|
|
describe("assistant vacation mutation tools", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("approves and rejects vacation through the real vacation router path", async () => {
|
|
const db = createHappyPathDb();
|
|
const ctx = createToolContext(db, { userRole: SystemRole.ADMIN });
|
|
|
|
const approveResult = await executeTool(
|
|
"approve_vacation",
|
|
JSON.stringify({ vacationId: "vac_cancelled" }),
|
|
ctx,
|
|
);
|
|
const rejectResult = await executeTool(
|
|
"reject_vacation",
|
|
JSON.stringify({ vacationId: "vac_pending", reason: "Capacity freeze" }),
|
|
ctx,
|
|
);
|
|
|
|
expect(JSON.parse(approveResult.content)).toEqual(
|
|
expect.objectContaining({
|
|
success: true,
|
|
message: "Approved vacation for Alice Example",
|
|
}),
|
|
);
|
|
expect(JSON.parse(rejectResult.content)).toEqual(
|
|
expect.objectContaining({
|
|
success: true,
|
|
message: "Rejected vacation for Alice Example: Capacity freeze",
|
|
}),
|
|
);
|
|
expect(db.vacation.update).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
where: expect.objectContaining({ id: "vac_cancelled" }),
|
|
data: expect.objectContaining({ status: "APPROVED" }),
|
|
}),
|
|
);
|
|
expect(db.vacation.update).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
where: expect.objectContaining({ id: "vac_pending" }),
|
|
data: expect.objectContaining({ status: "REJECTED", rejectionReason: "Capacity freeze" }),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("allows self-service vacation cancellation through the real vacation router path", async () => {
|
|
const db = createHappyPathDb();
|
|
const ctx = createToolContext(db, { userRole: SystemRole.USER, permissions: [] });
|
|
|
|
const result = await executeTool(
|
|
"cancel_vacation",
|
|
JSON.stringify({ vacationId: "vac_self" }),
|
|
ctx,
|
|
);
|
|
|
|
expect(JSON.parse(result.content)).toEqual(
|
|
expect.objectContaining({
|
|
success: true,
|
|
message: "Cancelled vacation for Alice Example",
|
|
}),
|
|
);
|
|
expect(db.vacation.update).toHaveBeenCalledWith({
|
|
where: { id: "vac_self" },
|
|
data: { status: "CANCELLED" },
|
|
});
|
|
});
|
|
});
|