Files
Nexus/packages/api/src/__tests__/assistant-tools-master-data-management-utilization-read.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

88 lines
2.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { countPlanningEntries } from "@nexus/application";
import { PermissionKey, SystemRole } from "@nexus/shared";
vi.mock("@nexus/application", async (importOriginal) => {
const actual = await importOriginal<typeof import("@nexus/application")>();
return {
...actual,
countPlanningEntries: vi.fn().mockResolvedValue({ countsByRoleId: new Map() }),
getDashboardBudgetForecast: vi.fn().mockResolvedValue([]),
getDashboardPeakTimes: vi.fn().mockResolvedValue([]),
listAssignmentBookings: vi.fn().mockResolvedValue([]),
};
});
import { executeTool } from "../router/assistant-tools.js";
import { createToolContext } from "./assistant-tools-master-data-read-test-helpers.js";
describe("assistant master data management and utilization read tools", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(countPlanningEntries).mockResolvedValue({ countsByRoleId: new Map() });
});
it("routes management level and utilization category reads through their backing routers", async () => {
const db = {
managementLevelGroup: {
findMany: vi.fn().mockResolvedValue([
{
id: "mlg_exec",
name: "Executive",
targetPercentage: 75,
levels: [{ id: "ml_partner", name: "Partner" }],
},
]),
},
utilizationCategory: {
findMany: vi.fn().mockResolvedValue([
{
id: "util_billable",
code: "BILLABLE",
name: "Billable",
description: "Client work",
isActive: true,
sortOrder: 1,
_count: { projects: 3 },
},
]),
},
};
const ctx = createToolContext(db, {
userRole: SystemRole.CONTROLLER,
permissions: [PermissionKey.VIEW_PLANNING],
});
const managementLevelsResult = await executeTool("list_management_levels", "{}", ctx);
const utilizationCategoriesResult = await executeTool("list_utilization_categories", "{}", ctx);
expect(db.managementLevelGroup.findMany).toHaveBeenCalledWith({
include: { levels: { orderBy: { name: "asc" } } },
orderBy: { sortOrder: "asc" },
});
expect(db.utilizationCategory.findMany).toHaveBeenCalledWith({
where: {},
orderBy: { sortOrder: "asc" },
include: { _count: { select: { projects: true } } },
});
expect(JSON.parse(managementLevelsResult.content)).toEqual([
{
id: "mlg_exec",
name: "Executive",
target: "75%",
levels: [{ id: "ml_partner", name: "Partner" }],
},
]);
expect(JSON.parse(utilizationCategoriesResult.content)).toEqual([
{
id: "util_billable",
code: "BILLABLE",
name: "Billable",
description: "Client work",
projectCount: 3,
},
]);
});
});