refactor(api): extract timeline project budget mapping
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildTimelineBudgetStatusAllocations,
|
||||
buildTimelineBudgetStatusResponse,
|
||||
buildTimelineProjectAssignmentConflicts,
|
||||
buildTimelineProjectContextDetailResponse,
|
||||
buildTimelineProjectContextResponse,
|
||||
buildTimelineProjectContextSummary,
|
||||
buildTimelineShiftValidationBookings,
|
||||
buildTimelineShiftPreviewDetailResponse,
|
||||
resolveTimelineProjectContextPeriod,
|
||||
} from "../router/timeline-project-context-support.js";
|
||||
@@ -371,4 +374,81 @@ describe("timeline project context support", () => {
|
||||
preview: { valid: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("maps shift validation bookings and budget status payloads", () => {
|
||||
expect(
|
||||
buildTimelineShiftValidationBookings([
|
||||
{
|
||||
id: "booking_1",
|
||||
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,
|
||||
status: "CONFIRMED",
|
||||
},
|
||||
{
|
||||
id: "booking_2",
|
||||
resourceId: null,
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-04-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-04-05T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
status: "PROPOSED",
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
id: "booking_1",
|
||||
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,
|
||||
status: "CONFIRMED",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(
|
||||
buildTimelineBudgetStatusAllocations([
|
||||
{
|
||||
status: "CONFIRMED",
|
||||
dailyCostCents: 40000,
|
||||
startDate: new Date("2026-04-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-04-05T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
status: "CONFIRMED",
|
||||
dailyCostCents: 40000,
|
||||
startDate: new Date("2026-04-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-04-05T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
},
|
||||
]);
|
||||
|
||||
expect(
|
||||
buildTimelineBudgetStatusResponse({
|
||||
project: {
|
||||
name: "Project One",
|
||||
shortCode: "PRJ",
|
||||
budgetCents: 120000,
|
||||
},
|
||||
budgetStatus: {
|
||||
withinBudget: true,
|
||||
varianceCents: 2000,
|
||||
},
|
||||
totalAllocations: 3,
|
||||
}),
|
||||
).toEqual({
|
||||
withinBudget: true,
|
||||
varianceCents: 2000,
|
||||
projectName: "Project One",
|
||||
projectCode: "PRJ",
|
||||
totalAllocations: 3,
|
||||
budgetCents: 120000,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user