chore(repo): checkpoint current capakraken implementation state
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { SystemRole } from "@capakraken/shared";
|
||||
|
||||
vi.mock("@capakraken/application", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@capakraken/application")>();
|
||||
@@ -8,16 +9,21 @@ vi.mock("@capakraken/application", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../lib/audit.js", () => ({
|
||||
createAuditEntry: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
import { executeTool, type ToolContext } from "../router/assistant-tools.js";
|
||||
|
||||
function createToolContext(
|
||||
db: Record<string, unknown>,
|
||||
permissions: string[] = [],
|
||||
userRole: SystemRole = SystemRole.ADMIN,
|
||||
): ToolContext {
|
||||
return {
|
||||
db: db as ToolContext["db"],
|
||||
userId: "user_1",
|
||||
userRole: "ADMIN",
|
||||
userRole,
|
||||
permissions: new Set(permissions) as ToolContext["permissions"],
|
||||
};
|
||||
}
|
||||
@@ -107,6 +113,193 @@ describe("assistant holiday tools", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("lists holiday calendars with scope metadata and entry counts", async () => {
|
||||
const ctx = createToolContext({
|
||||
holidayCalendar: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "cal_by",
|
||||
name: "Bayern Feiertage",
|
||||
scopeType: "STATE",
|
||||
stateCode: "BY",
|
||||
isActive: true,
|
||||
priority: 10,
|
||||
country: { id: "country_de", code: "DE", name: "Deutschland" },
|
||||
metroCity: null,
|
||||
_count: { entries: 2 },
|
||||
entries: [
|
||||
{
|
||||
id: "entry_1",
|
||||
date: new Date("2026-01-06T00:00:00.000Z"),
|
||||
name: "Heilige Drei Koenige",
|
||||
isRecurringAnnual: true,
|
||||
source: "state",
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await executeTool(
|
||||
"list_holiday_calendars",
|
||||
JSON.stringify({ countryCode: "DE", scopeType: "STATE", includeInactive: true }),
|
||||
ctx,
|
||||
);
|
||||
|
||||
const parsed = JSON.parse(result.content) as {
|
||||
count: number;
|
||||
calendars: Array<{
|
||||
name: string;
|
||||
scopeType: string;
|
||||
stateCode: string | null;
|
||||
entryCount: number;
|
||||
country: { code: string };
|
||||
}>;
|
||||
};
|
||||
|
||||
expect(parsed.count).toBe(1);
|
||||
expect(parsed.calendars).toHaveLength(1);
|
||||
expect(parsed.calendars[0]).toMatchObject({
|
||||
name: "Bayern Feiertage",
|
||||
scopeType: "STATE",
|
||||
stateCode: "BY",
|
||||
entryCount: 2,
|
||||
country: { code: "DE" },
|
||||
});
|
||||
});
|
||||
|
||||
it("previews resolved holiday calendars for a scope and shows the source calendar", async () => {
|
||||
const ctx = createToolContext({
|
||||
country: {
|
||||
findUnique: vi.fn().mockResolvedValue({ code: "DE" }),
|
||||
},
|
||||
metroCity: {
|
||||
findUnique: vi.fn().mockResolvedValue({ name: "Augsburg" }),
|
||||
},
|
||||
holidayCalendar: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "cal_city",
|
||||
name: "Augsburg lokal",
|
||||
scopeType: "CITY",
|
||||
priority: 5,
|
||||
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
entries: [
|
||||
{
|
||||
id: "entry_1",
|
||||
date: new Date("2020-08-08T00:00:00.000Z"),
|
||||
name: "Friedensfest lokal",
|
||||
isRecurringAnnual: true,
|
||||
source: "manual",
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await executeTool(
|
||||
"preview_resolved_holiday_calendar",
|
||||
JSON.stringify({ countryId: "country_de", metroCityId: "city_augsburg", year: 2026 }),
|
||||
ctx,
|
||||
);
|
||||
|
||||
const parsed = JSON.parse(result.content) as {
|
||||
count: number;
|
||||
locationContext: { countryCode: string; metroCity: string | null; year: number };
|
||||
holidays: Array<{ name: string; calendarName: string; scope: string; date: string }>;
|
||||
};
|
||||
|
||||
expect(parsed.count).toBeGreaterThan(0);
|
||||
expect(parsed.locationContext).toEqual(
|
||||
expect.objectContaining({
|
||||
countryCode: "DE",
|
||||
metroCity: "Augsburg",
|
||||
year: 2026,
|
||||
}),
|
||||
);
|
||||
expect(parsed.holidays).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "Friedensfest lokal",
|
||||
calendarName: "Augsburg lokal",
|
||||
scope: "CITY",
|
||||
date: "2026-08-08",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("creates a holiday calendar through the assistant for admin users", async () => {
|
||||
const ctx = createToolContext({
|
||||
country: {
|
||||
findUnique: vi.fn().mockResolvedValue({ id: "country_de", code: "DE", name: "Deutschland" }),
|
||||
},
|
||||
holidayCalendar: {
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
create: vi.fn().mockResolvedValue({
|
||||
id: "cal_by",
|
||||
name: "Bayern Feiertage",
|
||||
scopeType: "STATE",
|
||||
stateCode: "BY",
|
||||
isActive: true,
|
||||
priority: 10,
|
||||
country: { id: "country_de", code: "DE", name: "Deutschland" },
|
||||
metroCity: null,
|
||||
entries: [],
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await executeTool(
|
||||
"create_holiday_calendar",
|
||||
JSON.stringify({
|
||||
name: "Bayern Feiertage",
|
||||
scopeType: "STATE",
|
||||
countryId: "country_de",
|
||||
stateCode: "BY",
|
||||
priority: 10,
|
||||
}),
|
||||
ctx,
|
||||
);
|
||||
|
||||
const parsed = JSON.parse(result.content) as {
|
||||
success: boolean;
|
||||
message: string;
|
||||
calendar: { name: string; stateCode: string | null };
|
||||
};
|
||||
|
||||
expect(parsed.success).toBe(true);
|
||||
expect(parsed.message).toContain("Created holiday calendar");
|
||||
expect(parsed.calendar).toEqual(
|
||||
expect.objectContaining({
|
||||
name: "Bayern Feiertage",
|
||||
stateCode: "BY",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects holiday calendar mutations for non-admin assistant users", async () => {
|
||||
const ctx = createToolContext({}, [], SystemRole.MANAGER);
|
||||
const result = await executeTool(
|
||||
"create_holiday_calendar",
|
||||
JSON.stringify({
|
||||
name: "Hamburg Feiertage",
|
||||
scopeType: "STATE",
|
||||
countryId: "country_de",
|
||||
stateCode: "HH",
|
||||
}),
|
||||
ctx,
|
||||
);
|
||||
|
||||
expect(JSON.parse(result.content)).toEqual(
|
||||
expect.objectContaining({
|
||||
error: "Admin role required to perform this action.",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("calculates chargeability with regional holidays excluded from booked and available hours", async () => {
|
||||
const db = {
|
||||
resource: {
|
||||
|
||||
Reference in New Issue
Block a user