fix(api): harden broadcast and assistant fallback errors

This commit is contained in:
2026-03-30 12:03:27 +02:00
parent 22cff9648e
commit 6a6e98b5f7
5 changed files with 305 additions and 57 deletions
@@ -1374,6 +1374,51 @@ describe("assistant advanced tools and scoping", () => {
});
});
it("returns a stable demand-requirement-not-found error for batch timeline shifts", async () => {
const demandRequirement = {
id: "demand_requirement_1",
startDate: new Date("2026-03-10"),
endDate: new Date("2026-03-14"),
};
const db = {
allocation: {
findUnique: vi.fn().mockResolvedValue(null),
},
demandRequirement: {
findUnique: vi.fn().mockResolvedValue(demandRequirement),
},
assignment: {
findUnique: vi.fn().mockResolvedValue(null),
},
$transaction: vi.fn(async () => {
throw new TRPCError({
code: "NOT_FOUND",
message: "Demand requirement not found",
});
}),
};
const ctx = createToolContext(
db,
[PermissionKey.MANAGE_ALLOCATIONS, PermissionKey.USE_ASSISTANT_ADVANCED_TOOLS],
SystemRole.MANAGER,
);
const result = await executeTool(
"batch_shift_timeline_allocations",
JSON.stringify({
allocationIds: ["demand_requirement_missing"],
daysDelta: 3,
mode: "move",
}),
ctx,
);
expect(result.action).toBeUndefined();
expect(JSON.parse(result.content)).toEqual({
error: "Demand requirement not found with the given criteria.",
});
});
it("returns the chargeability report readmodel through the assistant", async () => {
const { listAssignmentBookings } = await import("@capakraken/application");
vi.mocked(listAssignmentBookings).mockResolvedValue([