test(api): cover timeline fallback paths
This commit is contained in:
@@ -221,6 +221,38 @@ describe("timeline router detail views", () => {
|
||||
expect(assignmentFindMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns empty self-service holiday overlays when the caller has no linked resource", async () => {
|
||||
const demandFindMany = vi.fn();
|
||||
const assignmentFindMany = vi.fn();
|
||||
const resourceFindMany = vi.fn();
|
||||
|
||||
const caller = createProtectedCaller({
|
||||
demandRequirement: {
|
||||
findMany: demandFindMany,
|
||||
},
|
||||
assignment: {
|
||||
findMany: assignmentFindMany,
|
||||
},
|
||||
resource: {
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
findMany: resourceFindMany,
|
||||
},
|
||||
project: {
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
const result = await caller.getMyHolidayOverlays({
|
||||
startDate: new Date("2026-01-05T00:00:00.000Z"),
|
||||
endDate: new Date("2026-01-09T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(demandFindMany).not.toHaveBeenCalled();
|
||||
expect(assignmentFindMany).not.toHaveBeenCalled();
|
||||
expect(resourceFindMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns a detailed timeline entries view with holiday overlays and summary", async () => {
|
||||
const caller = createAdminCaller({
|
||||
demandRequirement: {
|
||||
@@ -635,4 +667,102 @@ describe("timeline router detail views", () => {
|
||||
caller.getProjectContextDetail({ projectId: "project_ctx" }),
|
||||
).rejects.toThrow(expect.objectContaining({ code: "FORBIDDEN" }));
|
||||
});
|
||||
|
||||
it("returns budget status details for a project", async () => {
|
||||
vi.mocked(listAssignmentBookings).mockResolvedValue([
|
||||
{
|
||||
id: "asg_confirmed",
|
||||
projectId: "project_budget",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-01-05T00:00:00.000Z"),
|
||||
endDate: new Date("2026-01-09T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
dailyCostCents: 10000,
|
||||
status: "CONFIRMED",
|
||||
project: null,
|
||||
resource: null,
|
||||
},
|
||||
{
|
||||
id: "asg_proposed",
|
||||
projectId: "project_budget",
|
||||
resourceId: "res_2",
|
||||
startDate: new Date("2026-01-12T00:00:00.000Z"),
|
||||
endDate: new Date("2026-01-16T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
dailyCostCents: 5000,
|
||||
status: "PROPOSED",
|
||||
project: null,
|
||||
resource: null,
|
||||
},
|
||||
] as never);
|
||||
|
||||
const projectFindUnique = vi.fn().mockResolvedValue({
|
||||
id: "project_budget",
|
||||
name: "Gelddruckmaschine",
|
||||
shortCode: "GDM",
|
||||
budgetCents: 100000,
|
||||
winProbability: 80,
|
||||
startDate: new Date("2026-01-05T00:00:00.000Z"),
|
||||
endDate: new Date("2026-01-31T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const caller = createAdminCaller({
|
||||
project: {
|
||||
findUnique: projectFindUnique,
|
||||
},
|
||||
});
|
||||
|
||||
const result = await caller.getBudgetStatus({ projectId: "project_budget" });
|
||||
|
||||
expect(projectFindUnique).toHaveBeenCalledWith({
|
||||
where: { id: "project_budget" },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
shortCode: true,
|
||||
budgetCents: true,
|
||||
winProbability: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
},
|
||||
});
|
||||
expect(listAssignmentBookings).toHaveBeenCalledWith(expect.anything(), {
|
||||
projectIds: ["project_budget"],
|
||||
});
|
||||
expect(result).toEqual(
|
||||
expect.objectContaining({
|
||||
projectName: "Gelddruckmaschine",
|
||||
projectCode: "GDM",
|
||||
totalAllocations: 2,
|
||||
budgetCents: 100000,
|
||||
confirmedCents: 50000,
|
||||
proposedCents: 25000,
|
||||
allocatedCents: 75000,
|
||||
remainingCents: 25000,
|
||||
winProbabilityWeightedCents: 60000,
|
||||
}),
|
||||
);
|
||||
expect(result.utilizationPercent).toBeCloseTo(75, 5);
|
||||
expect(result.warnings).toEqual([
|
||||
expect.objectContaining({
|
||||
level: "info",
|
||||
code: "BUDGET_INFO",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns NOT_FOUND for budget status when the project does not exist", async () => {
|
||||
const caller = createAdminCaller({
|
||||
project: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
caller.getBudgetStatus({ projectId: "project_missing" }),
|
||||
).rejects.toThrow(expect.objectContaining({
|
||||
code: "NOT_FOUND",
|
||||
message: "Project not found",
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user