feat(platform): checkpoint current implementation state

This commit is contained in:
2026-04-01 07:42:03 +02:00
parent 3e53471f05
commit 8c5be51251
125 changed files with 10269 additions and 17808 deletions
@@ -222,6 +222,124 @@ describe("timeline allocation entry resolution", () => {
);
});
it("extracts a visible subrange into its own assignment fragment", async () => {
const existingAssignment = {
id: "assignment_1",
demandRequirementId: null,
resourceId: "resource_1",
projectId: "project_1",
startDate: new Date("2026-03-16"),
endDate: new Date("2026-03-27"),
hoursPerDay: 8,
percentage: 100,
role: "Compositor",
roleId: "role_comp",
dailyCostCents: 40000,
status: AllocationStatus.CONFIRMED,
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 db = {
project: {
findUnique: vi.fn().mockResolvedValue({ id: "project_1" }),
},
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().mockResolvedValue([]),
},
demandRequirement: {
findUnique: vi.fn().mockResolvedValue(null),
},
assignment: {
findUnique: vi.fn().mockResolvedValue(existingAssignment),
findMany: vi.fn().mockResolvedValue([]),
update: vi.fn().mockImplementation(async ({ data }: { data: Record<string, unknown> }) => ({
...existingAssignment,
...data,
metadata: data.metadata ?? existingAssignment.metadata,
})),
create: vi.fn()
.mockResolvedValueOnce({
...existingAssignment,
id: "assignment_left",
startDate: new Date("2026-03-16"),
endDate: new Date("2026-03-20"),
})
.mockResolvedValueOnce({
...existingAssignment,
id: "assignment_right",
startDate: new Date("2026-03-26"),
endDate: new Date("2026-03-27"),
}),
},
auditLog: {
create: vi.fn().mockResolvedValue({}),
},
$transaction: vi.fn(async (callback: (tx: unknown) => unknown) => callback(db)),
};
const caller = createManagerCaller(db);
const result = await caller.extractAllocationFragment({
allocationId: "assignment_1",
startDate: new Date("2026-03-23"),
endDate: new Date("2026-03-25"),
});
expect(result).toEqual({
action: "extracted",
allocationGroupId: expect.any(String),
extractedAllocationId: "assignment_1",
updatedAllocationIds: ["assignment_1"],
createdAllocationIds: ["assignment_left", "assignment_right"],
projectId: "project_1",
resourceId: "resource_1",
});
expect(db.assignment.update).toHaveBeenCalledWith(
expect.objectContaining({
where: { id: "assignment_1" },
data: expect.objectContaining({
startDate: new Date("2026-03-23"),
endDate: new Date("2026-03-25"),
}),
}),
);
expect(db.assignment.create).toHaveBeenCalledTimes(2);
});
it("falls back to default rules when calculationRule and vacation tables are missing", async () => {
const existingAssignment = {
id: "assignment_legacy_1",