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>
174 lines
5.6 KiB
TypeScript
174 lines
5.6 KiB
TypeScript
import { VacationType } from "@nexus/db";
|
|
import { vi } from "vitest";
|
|
|
|
import { executeTool as executeAssistantTool } from "../router/assistant-tools.js";
|
|
|
|
export { createToolContext } from "./assistant-tools-vacation-entitlement-test-helpers.js";
|
|
|
|
export function createHappyPathDb() {
|
|
const vacationFindUnique = vi.fn().mockImplementation(async (args?: any) => {
|
|
const id = args?.where?.id;
|
|
if (id === "vac_cancelled") {
|
|
return {
|
|
id,
|
|
resourceId: "res_1",
|
|
requestedById: "user_1",
|
|
status: "CANCELLED",
|
|
startDate: new Date("2026-07-01T00:00:00.000Z"),
|
|
endDate: new Date("2026-07-02T00:00:00.000Z"),
|
|
type: VacationType.ANNUAL,
|
|
isHalfDay: false,
|
|
resource: {
|
|
id: "res_1",
|
|
displayName: "Alice Example",
|
|
eid: "EMP-001",
|
|
chapter: "Delivery",
|
|
},
|
|
requestedBy: { id: "user_1", name: "Assistant User", email: "assistant@example.com" },
|
|
approvedBy: null,
|
|
};
|
|
}
|
|
if (id === "vac_pending") {
|
|
return {
|
|
id,
|
|
resourceId: "res_1",
|
|
requestedById: "user_1",
|
|
status: "PENDING",
|
|
startDate: new Date("2026-08-03T00:00:00.000Z"),
|
|
endDate: new Date("2026-08-04T00:00:00.000Z"),
|
|
type: VacationType.ANNUAL,
|
|
isHalfDay: false,
|
|
resource: {
|
|
id: "res_1",
|
|
displayName: "Alice Example",
|
|
eid: "EMP-001",
|
|
chapter: "Delivery",
|
|
},
|
|
requestedBy: { id: "user_1", name: "Assistant User", email: "assistant@example.com" },
|
|
approvedBy: null,
|
|
};
|
|
}
|
|
if (id === "vac_self") {
|
|
return {
|
|
id,
|
|
resourceId: "res_1",
|
|
requestedById: "user_1",
|
|
status: "APPROVED",
|
|
startDate: new Date("2026-09-07T00:00:00.000Z"),
|
|
endDate: new Date("2026-09-09T00:00:00.000Z"),
|
|
resource: {
|
|
id: "res_1",
|
|
displayName: "Alice Example",
|
|
eid: "EMP-001",
|
|
chapter: "Delivery",
|
|
},
|
|
requestedBy: { id: "user_1", name: "Assistant User", email: "assistant@example.com" },
|
|
approvedBy: null,
|
|
};
|
|
}
|
|
return null;
|
|
});
|
|
|
|
const db = {
|
|
user: {
|
|
findUnique: vi.fn().mockResolvedValue({ id: "user_1", systemRole: "MANAGER" }),
|
|
},
|
|
resource: {
|
|
findUnique: vi.fn().mockImplementation(async (args?: any) => {
|
|
if (args?.where?.id === "res_1") {
|
|
return {
|
|
id: "res_1",
|
|
eid: "EMP-001",
|
|
displayName: "Alice Example",
|
|
userId: "user_1",
|
|
chapter: "Delivery",
|
|
federalState: "BY",
|
|
countryId: "country_de",
|
|
metroCityId: null,
|
|
country: { code: "DE", name: "Germany" },
|
|
metroCity: null,
|
|
};
|
|
}
|
|
return { userId: "user_1" };
|
|
}),
|
|
count: vi.fn().mockResolvedValue(1),
|
|
findFirst: vi.fn().mockResolvedValue(null),
|
|
},
|
|
holidayCalendar: {
|
|
findMany: vi.fn().mockResolvedValue([]),
|
|
},
|
|
systemSettings: {
|
|
findUnique: vi
|
|
.fn()
|
|
.mockResolvedValueOnce({ vacationDefaultDays: 30 })
|
|
.mockResolvedValueOnce({ anonymizationEnabled: false }),
|
|
},
|
|
vacationEntitlement: {
|
|
findUnique: vi.fn().mockResolvedValue(null),
|
|
create: vi.fn(),
|
|
update: vi.fn(),
|
|
},
|
|
vacation: {
|
|
findUnique: vacationFindUnique,
|
|
findUniqueOrThrow: vi.fn().mockImplementation(async (args?: any) => {
|
|
const result = await vacationFindUnique({ where: { id: args?.where?.id } });
|
|
if (!result) throw new Error("Vacation not found");
|
|
return result;
|
|
}),
|
|
findMany: vi.fn().mockResolvedValue([]),
|
|
findFirst: vi.fn().mockResolvedValue(null),
|
|
create: vi.fn().mockResolvedValue({
|
|
id: "vac_created",
|
|
resourceId: "res_1",
|
|
status: "APPROVED",
|
|
type: VacationType.ANNUAL,
|
|
startDate: new Date("2026-07-01T00:00:00.000Z"),
|
|
endDate: new Date("2026-07-02T00:00:00.000Z"),
|
|
isHalfDay: false,
|
|
resource: {
|
|
id: "res_1",
|
|
displayName: "Alice Example",
|
|
eid: "EMP-001",
|
|
chapter: "Delivery",
|
|
},
|
|
requestedBy: { id: "user_1", name: "Assistant User", email: "assistant@example.com" },
|
|
effectiveDays: 2,
|
|
}),
|
|
update: vi.fn().mockImplementation(async (args?: any) => {
|
|
const existing = await vacationFindUnique({ where: { id: args?.where?.id } });
|
|
return {
|
|
...(existing ?? {
|
|
id: args?.where?.id ?? "vac_unknown",
|
|
resourceId: "res_1",
|
|
startDate: new Date("2026-07-01T00:00:00.000Z"),
|
|
endDate: new Date("2026-07-02T00:00:00.000Z"),
|
|
type: VacationType.ANNUAL,
|
|
isHalfDay: false,
|
|
}),
|
|
status: args?.data?.status ?? existing?.status ?? "APPROVED",
|
|
rejectionReason: args?.data?.rejectionReason ?? null,
|
|
approvedAt: args?.data?.approvedAt ?? null,
|
|
approvedById: args?.data?.approvedById ?? existing?.approvedById ?? null,
|
|
};
|
|
}),
|
|
updateMany: vi.fn().mockResolvedValue({ count: 1 }),
|
|
},
|
|
notification: {
|
|
updateMany: vi.fn().mockResolvedValue({ count: 1 }),
|
|
create: vi.fn().mockResolvedValue({ id: "note_1", userId: "user_1" }),
|
|
},
|
|
auditLog: {
|
|
create: vi.fn().mockResolvedValue({ id: "audit_1" }),
|
|
},
|
|
webhook: {
|
|
findMany: vi.fn().mockResolvedValue([]),
|
|
},
|
|
} as any;
|
|
|
|
db.$transaction = vi.fn(async (callback: (tx: typeof db) => Promise<unknown>) => callback(db));
|
|
|
|
return db;
|
|
}
|
|
|
|
export const executeTool = executeAssistantTool;
|