refactor(api): extract timeline allocation mutation schemas

This commit is contained in:
2026-03-31 18:06:09 +02:00
parent cb70e81e17
commit 0b72eef61f
3 changed files with 116 additions and 45 deletions
@@ -0,0 +1,68 @@
import { AllocationStatus } from "@capakraken/shared";
import { describe, expect, it } from "vitest";
import {
timelineBatchQuickAssignInputSchema,
timelineBatchShiftAllocationsInputSchema,
timelineQuickAssignInputSchema,
} from "../router/timeline-allocation-mutation-schema-support.js";
describe("timeline allocation mutation schema support", () => {
it("applies defaults for quick assign input", () => {
expect(
timelineQuickAssignInputSchema.parse({
resourceId: "resource_1",
projectId: "project_1",
startDate: "2026-04-01T00:00:00.000Z",
endDate: "2026-04-05T00:00:00.000Z",
}),
).toEqual({
resourceId: "resource_1",
projectId: "project_1",
startDate: new Date("2026-04-01T00:00:00.000Z"),
endDate: new Date("2026-04-05T00:00:00.000Z"),
hoursPerDay: 8,
role: "Team Member",
status: AllocationStatus.PROPOSED,
});
});
it("applies defaults to each batch quick assign entry", () => {
expect(
timelineBatchQuickAssignInputSchema.parse({
assignments: [
{
resourceId: "resource_1",
projectId: "project_1",
startDate: "2026-04-01T00:00:00.000Z",
endDate: "2026-04-05T00:00:00.000Z",
},
],
}),
).toEqual({
assignments: [
{
resourceId: "resource_1",
projectId: "project_1",
startDate: new Date("2026-04-01T00:00:00.000Z"),
endDate: new Date("2026-04-05T00:00:00.000Z"),
hoursPerDay: 8,
role: "Team Member",
status: AllocationStatus.PROPOSED,
},
],
});
});
it("defaults batch shift mode to move", () => {
expect(
timelineBatchShiftAllocationsInputSchema.parse({
allocationIds: ["allocation_1"],
daysDelta: 3,
}),
).toEqual({
allocationIds: ["allocation_1"],
daysDelta: 3,
mode: "move",
});
});
});