refactor(api): extract timeline batch shift support
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildTimelineBatchShiftAuditChanges,
|
||||
shiftTimelineAllocationWindow,
|
||||
} from "../router/timeline-allocation-batch-shift-support.js";
|
||||
|
||||
describe("timeline allocation batch shift support", () => {
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user