test(api): cover timeline fallback paths
This commit is contained in:
@@ -222,6 +222,117 @@ describe("timeline allocation entry resolution", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to default rules when calculationRule and vacation tables are missing", async () => {
|
||||
const existingAssignment = {
|
||||
id: "assignment_legacy_1",
|
||||
demandRequirementId: null,
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-20"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
dailyCostCents: 20000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
resource: {
|
||||
id: "resource_1",
|
||||
displayName: "Alice",
|
||||
eid: "E-001",
|
||||
lcrCents: 5000,
|
||||
availability: {
|
||||
monday: 8,
|
||||
tuesday: 8,
|
||||
wednesday: 8,
|
||||
thursday: 8,
|
||||
friday: 8,
|
||||
saturday: 0,
|
||||
sunday: 0,
|
||||
},
|
||||
},
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_comp", name: "Compositor", color: "#111111" },
|
||||
demandRequirement: null,
|
||||
};
|
||||
const missingVacationTableError = {
|
||||
code: "P2021",
|
||||
message: "The table `public.vacation` does not exist in the current database.",
|
||||
meta: { table: "public.vacation" },
|
||||
};
|
||||
const missingCalculationRuleTableError = {
|
||||
code: "P2021",
|
||||
message: "The table `public.calculation_rule` does not exist in the current database.",
|
||||
meta: { table: "public.calculation_rule" },
|
||||
};
|
||||
|
||||
const db = {
|
||||
allocation: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
demandRequirement: {
|
||||
findUnique: vi.fn().mockResolvedValue(null),
|
||||
},
|
||||
assignment: {
|
||||
findUnique: vi.fn().mockResolvedValue(existingAssignment),
|
||||
update: vi.fn().mockImplementation(async ({ data }: { data: Record<string, unknown> }) => ({
|
||||
...existingAssignment,
|
||||
...data,
|
||||
metadata: data.metadata ?? existingAssignment.metadata,
|
||||
updatedAt: new Date("2026-03-14"),
|
||||
})),
|
||||
},
|
||||
resource: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "resource_1",
|
||||
lcrCents: 5000,
|
||||
availability: {
|
||||
monday: 8,
|
||||
tuesday: 8,
|
||||
wednesday: 8,
|
||||
thursday: 8,
|
||||
friday: 8,
|
||||
saturday: 0,
|
||||
sunday: 0,
|
||||
},
|
||||
}),
|
||||
},
|
||||
vacation: {
|
||||
findMany: vi.fn().mockRejectedValue(missingVacationTableError),
|
||||
},
|
||||
calculationRule: {
|
||||
findMany: vi.fn().mockRejectedValue(missingCalculationRuleTableError),
|
||||
},
|
||||
auditLog: {
|
||||
create: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
$transaction: vi.fn(async (callback: (tx: unknown) => unknown) => callback(db)),
|
||||
};
|
||||
|
||||
const caller = createManagerCaller(db);
|
||||
const result = await caller.updateAllocationInline({
|
||||
allocationId: "assignment_legacy_1",
|
||||
hoursPerDay: 6,
|
||||
endDate: new Date("2026-03-21"),
|
||||
includeSaturday: true,
|
||||
});
|
||||
|
||||
expect(result.id).toBe("assignment_legacy_1");
|
||||
expect(db.vacation.findMany).toHaveBeenCalledTimes(1);
|
||||
expect(db.calculationRule.findMany).toHaveBeenCalledTimes(1);
|
||||
expect(db.assignment.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
dailyCostCents: expect.any(Number),
|
||||
metadata: expect.objectContaining({ includeSaturday: true }),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates an explicit demand row through updateAllocationInline", async () => {
|
||||
const existingDemand = {
|
||||
id: "demand_1",
|
||||
|
||||
Reference in New Issue
Block a user