refactor(api): extract timeline batch shift support

This commit is contained in:
2026-03-31 17:57:28 +02:00
parent e082f1748b
commit fb09d6487f
5 changed files with 110 additions and 105 deletions
@@ -4,8 +4,6 @@ import {
assertTimelineDateRangeValid,
buildTimelineAllocationEntryUpdate,
buildTimelineAllocationMetadata,
buildTimelineBatchShiftAuditChanges,
shiftTimelineAllocationWindow,
validateTimelineAllocationDateRanges,
} from "../router/timeline-allocation-mutation-support.js";
@@ -36,59 +34,6 @@ describe("timeline allocation mutation support", () => {
)).toThrowError(TRPCError);
});
it("shifts and clamps allocation windows for each batch-shift mode", () => {
expect(
shiftTimelineAllocationWindow({
startDate: new Date("2026-04-10T00:00:00.000Z"),
endDate: new Date("2026-04-12T00:00:00.000Z"),
daysDelta: 2,
mode: "move",
}),
).toEqual({
startDate: new Date("2026-04-12T00:00:00.000Z"),
endDate: new Date("2026-04-14T00:00:00.000Z"),
});
expect(
shiftTimelineAllocationWindow({
startDate: new Date("2026-04-10T00:00:00.000Z"),
endDate: new Date("2026-04-12T00:00:00.000Z"),
daysDelta: 5,
mode: "resize-start",
}),
).toEqual({
startDate: new Date("2026-04-12T00:00:00.000Z"),
endDate: new Date("2026-04-12T00:00:00.000Z"),
});
expect(
shiftTimelineAllocationWindow({
startDate: new Date("2026-04-10T00:00:00.000Z"),
endDate: new Date("2026-04-12T00:00:00.000Z"),
daysDelta: -5,
mode: "resize-end",
}),
).toEqual({
startDate: new Date("2026-04-10T00:00:00.000Z"),
endDate: new Date("2026-04-10T00:00:00.000Z"),
});
});
it("builds batch-shift audit payloads", () => {
expect(
buildTimelineBatchShiftAuditChanges({
mode: "move",
daysDelta: 3,
count: 2,
}),
).toEqual({
operation: "batchShift",
mode: "move",
daysDelta: 3,
count: 2,
});
});
it("validates date ranges in bulk", () => {
expect(() =>
validateTimelineAllocationDateRanges([