chore(repo): initialize planarchy workspace
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
import { AllocationStatus } from "@planarchy/shared";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { updateAllocationEntry } from "../index.js";
|
||||
|
||||
describe("allocation entry resolution helpers", () => {
|
||||
it("updates an explicit demand requirement", async () => {
|
||||
const existingDemand = {
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-20"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "FX Artist",
|
||||
roleId: "role_fx",
|
||||
headcount: 1,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_fx", name: "FX Artist", color: "#222222" },
|
||||
};
|
||||
const updatedDemand = {
|
||||
...existingDemand,
|
||||
headcount: 2,
|
||||
status: AllocationStatus.CONFIRMED,
|
||||
metadata: { source: "entry-test" },
|
||||
updatedAt: new Date("2026-03-14"),
|
||||
};
|
||||
|
||||
const demandRequirementFindUnique = vi.fn().mockResolvedValue(existingDemand);
|
||||
const demandRequirementUpdate = vi.fn().mockResolvedValue(updatedDemand);
|
||||
const assignmentFindUnique = vi.fn().mockResolvedValue(null);
|
||||
const assignmentUpdate = vi.fn();
|
||||
const auditLogCreate = vi.fn().mockResolvedValue({});
|
||||
|
||||
const result = await updateAllocationEntry(
|
||||
{
|
||||
demandRequirement: {
|
||||
findUnique: demandRequirementFindUnique,
|
||||
update: demandRequirementUpdate,
|
||||
},
|
||||
assignment: {
|
||||
findUnique: assignmentFindUnique,
|
||||
update: assignmentUpdate,
|
||||
},
|
||||
auditLog: { create: auditLogCreate },
|
||||
} as never,
|
||||
{
|
||||
id: "demand_1",
|
||||
demandRequirementUpdate: {
|
||||
headcount: 2,
|
||||
status: AllocationStatus.CONFIRMED,
|
||||
metadata: { source: "entry-test" },
|
||||
},
|
||||
assignmentUpdate: {},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.strategy).toBe("explicit_demand");
|
||||
expect(result.allocation.id).toBe("demand_1");
|
||||
expect(result.allocation.isPlaceholder).toBe(true);
|
||||
expect(result.allocation.headcount).toBe(2);
|
||||
expect(demandRequirementUpdate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { id: "demand_1" },
|
||||
data: expect.objectContaining({
|
||||
headcount: 2,
|
||||
status: AllocationStatus.CONFIRMED,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(assignmentUpdate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("updates an explicit assignment", 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-20"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
dailyCostCents: 20000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
resource: {
|
||||
id: "resource_1",
|
||||
displayName: "Alice",
|
||||
eid: "E-001",
|
||||
lcrCents: 5000,
|
||||
},
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_comp", name: "Compositor", color: "#111111" },
|
||||
demandRequirement: null,
|
||||
};
|
||||
const updatedAssignment = {
|
||||
...existingAssignment,
|
||||
hoursPerDay: 6,
|
||||
percentage: 75,
|
||||
dailyCostCents: 30000,
|
||||
status: AllocationStatus.ACTIVE,
|
||||
updatedAt: new Date("2026-03-14"),
|
||||
};
|
||||
|
||||
const demandRequirementFindUnique = vi.fn().mockResolvedValue(null);
|
||||
const assignmentFindUnique = vi.fn().mockResolvedValue(existingAssignment);
|
||||
const assignmentUpdate = vi.fn().mockResolvedValue(updatedAssignment);
|
||||
const auditLogCreate = vi.fn().mockResolvedValue({});
|
||||
|
||||
const result = await updateAllocationEntry(
|
||||
{
|
||||
demandRequirement: {
|
||||
findUnique: demandRequirementFindUnique,
|
||||
},
|
||||
assignment: {
|
||||
findUnique: assignmentFindUnique,
|
||||
update: assignmentUpdate,
|
||||
},
|
||||
auditLog: { create: auditLogCreate },
|
||||
} as never,
|
||||
{
|
||||
id: "assignment_1",
|
||||
demandRequirementUpdate: {},
|
||||
assignmentUpdate: {
|
||||
hoursPerDay: 6,
|
||||
percentage: 75,
|
||||
dailyCostCents: 30000,
|
||||
status: AllocationStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.strategy).toBe("explicit_assignment");
|
||||
expect(result.allocation.id).toBe("assignment_1");
|
||||
expect(assignmentUpdate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { id: "assignment_1" },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("throws NOT_FOUND when the id does not match any demand or assignment", async () => {
|
||||
const demandRequirementFindUnique = vi.fn().mockResolvedValue(null);
|
||||
const assignmentFindUnique = vi.fn().mockResolvedValue(null);
|
||||
|
||||
await expect(
|
||||
updateAllocationEntry(
|
||||
{
|
||||
demandRequirement: {
|
||||
findUnique: demandRequirementFindUnique,
|
||||
},
|
||||
assignment: {
|
||||
findUnique: assignmentFindUnique,
|
||||
},
|
||||
} as never,
|
||||
{
|
||||
id: "nonexistent_id",
|
||||
demandRequirementUpdate: {
|
||||
status: AllocationStatus.CONFIRMED,
|
||||
},
|
||||
assignmentUpdate: {},
|
||||
},
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
code: "NOT_FOUND",
|
||||
message: "Allocation not found",
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,237 @@
|
||||
import { AllocationStatus } from "@planarchy/shared";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createAssignment,
|
||||
updateAssignment,
|
||||
updateDemandRequirement,
|
||||
} from "../index.js";
|
||||
|
||||
describe("allocation entry update flows", () => {
|
||||
it("excludes the current assignment from conflict checks during update", async () => {
|
||||
const projectFindUnique = vi.fn().mockResolvedValue({ id: "project_1" });
|
||||
const resourceFindUnique = vi.fn().mockResolvedValue({
|
||||
id: "resource_1",
|
||||
lcrCents: 5000,
|
||||
availability: {
|
||||
monday: 8,
|
||||
tuesday: 8,
|
||||
wednesday: 8,
|
||||
thursday: 8,
|
||||
friday: 8,
|
||||
saturday: 0,
|
||||
sunday: 0,
|
||||
},
|
||||
});
|
||||
const assignmentFindMany = vi.fn().mockResolvedValue([]);
|
||||
const vacationFindMany = vi.fn().mockResolvedValue([]);
|
||||
const assignmentCreate = vi.fn().mockResolvedValue({
|
||||
id: "assignment_1",
|
||||
demandRequirementId: null,
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
dailyCostCents: 20000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001", lcrCents: 5000 },
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_comp", name: "Compositor", color: "#111111" },
|
||||
demandRequirement: null,
|
||||
});
|
||||
const auditLogCreate = vi.fn().mockResolvedValue({});
|
||||
|
||||
await createAssignment(
|
||||
{
|
||||
project: { findUnique: projectFindUnique },
|
||||
resource: { findUnique: resourceFindUnique },
|
||||
assignment: { findMany: assignmentFindMany, create: assignmentCreate },
|
||||
vacation: { findMany: vacationFindMany },
|
||||
auditLog: { create: auditLogCreate },
|
||||
} as never,
|
||||
{
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
},
|
||||
);
|
||||
|
||||
expect(assignmentFindMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({
|
||||
resourceId: { in: ["resource_1"] },
|
||||
status: { not: "CANCELLED" },
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates a linked demand requirement directly", async () => {
|
||||
const demandRequirementFindUnique = vi.fn().mockResolvedValue({
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "FX Artist",
|
||||
roleId: "role_fx",
|
||||
headcount: 2,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_fx", name: "FX Artist", color: "#222222" },
|
||||
});
|
||||
const demandRequirementUpdate = vi.fn().mockResolvedValue({
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "FX Artist",
|
||||
roleId: "role_fx",
|
||||
headcount: 1,
|
||||
status: AllocationStatus.COMPLETED,
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_fx", name: "FX Artist", color: "#222222" },
|
||||
});
|
||||
const auditLogCreate = vi.fn().mockResolvedValue({});
|
||||
|
||||
const result = await updateDemandRequirement(
|
||||
{
|
||||
demandRequirement: {
|
||||
findUnique: demandRequirementFindUnique,
|
||||
update: demandRequirementUpdate,
|
||||
},
|
||||
auditLog: { create: auditLogCreate },
|
||||
} as never,
|
||||
"demand_1",
|
||||
{
|
||||
headcount: 1,
|
||||
status: AllocationStatus.COMPLETED,
|
||||
metadata: { source: "update-test" },
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.headcount).toBe(1);
|
||||
expect(auditLogCreate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
entityType: "DemandRequirement",
|
||||
entityId: "demand_1",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("updates a linked assignment directly", async () => {
|
||||
const existingAssignment = {
|
||||
id: "assignment_1",
|
||||
demandRequirementId: "demand_1",
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
dailyCostCents: 20000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001", lcrCents: 5000 },
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_comp", name: "Compositor", color: "#111111" },
|
||||
demandRequirement: {
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
headcount: 1,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
},
|
||||
};
|
||||
const assignmentFindUnique = vi.fn().mockResolvedValue(existingAssignment);
|
||||
const assignmentUpdate = vi.fn().mockResolvedValue({
|
||||
...existingAssignment,
|
||||
id: "assignment_1",
|
||||
demandRequirementId: "demand_1",
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-17"),
|
||||
endDate: new Date("2026-03-28"),
|
||||
hoursPerDay: 6,
|
||||
percentage: 75,
|
||||
role: "Lead Compositor",
|
||||
roleId: "role_lead_comp",
|
||||
dailyCostCents: 32000,
|
||||
status: AllocationStatus.CONFIRMED,
|
||||
metadata: { source: "update-test" },
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001", lcrCents: 5000 },
|
||||
project: { id: "project_1", name: "Project One", shortCode: "PRJ" },
|
||||
roleEntity: { id: "role_lead_comp", name: "Lead Compositor", color: "#444444" },
|
||||
demandRequirement: {
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-16"),
|
||||
endDate: new Date("2026-03-27"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
headcount: 1,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
},
|
||||
});
|
||||
const auditLogCreate = vi.fn().mockResolvedValue({});
|
||||
|
||||
const result = await updateAssignment(
|
||||
{
|
||||
assignment: {
|
||||
findUnique: assignmentFindUnique,
|
||||
update: assignmentUpdate,
|
||||
},
|
||||
auditLog: { create: auditLogCreate },
|
||||
} as never,
|
||||
"assignment_1",
|
||||
{
|
||||
startDate: new Date("2026-03-17"),
|
||||
endDate: new Date("2026-03-28"),
|
||||
hoursPerDay: 6,
|
||||
percentage: 75,
|
||||
role: "Lead Compositor",
|
||||
roleId: "role_lead_comp",
|
||||
dailyCostCents: 32000,
|
||||
status: AllocationStatus.CONFIRMED,
|
||||
metadata: { source: "update-test" },
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.dailyCostCents).toBe(32000);
|
||||
expect(auditLogCreate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
entityType: "Assignment",
|
||||
entityId: "assignment_1",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { AllocationStatus, type AllocationWithDetails } from "@planarchy/shared";
|
||||
import { buildAllocationReadModel } from "../index.js";
|
||||
|
||||
function makeAllocation(overrides: Partial<AllocationWithDetails>): AllocationWithDetails {
|
||||
return {
|
||||
id: "alloc_1",
|
||||
resourceId: "res_1",
|
||||
projectId: "proj_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-05T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Compositor",
|
||||
roleId: "role_1",
|
||||
isPlaceholder: false,
|
||||
headcount: 1,
|
||||
dailyCostCents: 12_000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
resource: {
|
||||
id: "res_1",
|
||||
displayName: "Alice",
|
||||
eid: "E-001",
|
||||
lcrCents: 15_000,
|
||||
},
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Project One",
|
||||
shortCode: "P1",
|
||||
status: "ACTIVE",
|
||||
endDate: new Date("2026-03-31T00:00:00.000Z"),
|
||||
},
|
||||
roleEntity: {
|
||||
id: "role_1",
|
||||
name: "Compositor",
|
||||
color: "#111111",
|
||||
},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("allocation read model", () => {
|
||||
it("splits assignments from placeholder demand rows", () => {
|
||||
const input: AllocationWithDetails[] = [
|
||||
makeAllocation({ id: "assign_1" }),
|
||||
makeAllocation({
|
||||
id: "demand_1",
|
||||
resourceId: null,
|
||||
isPlaceholder: true,
|
||||
headcount: 3,
|
||||
dailyCostCents: 0,
|
||||
resource: null,
|
||||
}),
|
||||
];
|
||||
|
||||
const result = buildAllocationReadModel(input);
|
||||
|
||||
expect(result.allocations).toHaveLength(2);
|
||||
expect(result.assignments).toHaveLength(1);
|
||||
expect(result.demands).toHaveLength(1);
|
||||
expect(result.assignments[0]).toMatchObject({
|
||||
id: "assign_1",
|
||||
kind: "assignment",
|
||||
sourceAllocationId: "assign_1",
|
||||
resourceId: "res_1",
|
||||
isPlaceholder: false,
|
||||
});
|
||||
expect(result.demands[0]).toMatchObject({
|
||||
id: "demand_1",
|
||||
kind: "demand",
|
||||
sourceAllocationId: "demand_1",
|
||||
resourceId: null,
|
||||
isPlaceholder: true,
|
||||
requestedHeadcount: 3,
|
||||
unfilledHeadcount: 3,
|
||||
});
|
||||
});
|
||||
|
||||
it("treats null-resource rows as demand for legacy safety", () => {
|
||||
const input: AllocationWithDetails[] = [
|
||||
makeAllocation({
|
||||
id: "legacy_1",
|
||||
resourceId: null,
|
||||
isPlaceholder: false,
|
||||
headcount: 2,
|
||||
dailyCostCents: 0,
|
||||
resource: null,
|
||||
}),
|
||||
];
|
||||
|
||||
const result = buildAllocationReadModel(input);
|
||||
|
||||
expect(result.assignments).toEqual([]);
|
||||
expect(result.demands).toHaveLength(1);
|
||||
expect(result.demands[0]?.sourceAllocationId).toBe("legacy_1");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,197 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { listAssignmentBookings } from "../index.js";
|
||||
|
||||
describe("listAssignmentBookings", () => {
|
||||
it("returns assignments with cost metadata", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "asn_1",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 6,
|
||||
dailyCostCents: 900,
|
||||
status: "CONFIRMED",
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
status: "ACTIVE",
|
||||
orderType: "CHARGEABLE",
|
||||
},
|
||||
resource: {
|
||||
id: "res_1",
|
||||
displayName: "Alice",
|
||||
chapter: "CGI",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "asn_2",
|
||||
projectId: "proj_2",
|
||||
resourceId: "res_2",
|
||||
startDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
dailyCostCents: 500,
|
||||
status: "PROPOSED",
|
||||
project: {
|
||||
id: "proj_2",
|
||||
name: "Bravo",
|
||||
shortCode: "BRAVO",
|
||||
status: "DRAFT",
|
||||
orderType: "INTERNAL",
|
||||
},
|
||||
resource: {
|
||||
id: "res_2",
|
||||
displayName: "Bob",
|
||||
chapter: "Lighting",
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await listAssignmentBookings(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-31T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
id: "asn_1",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 6,
|
||||
dailyCostCents: 900,
|
||||
status: "CONFIRMED",
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
status: "ACTIVE",
|
||||
orderType: "CHARGEABLE",
|
||||
},
|
||||
resource: {
|
||||
id: "res_1",
|
||||
displayName: "Alice",
|
||||
chapter: "CGI",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "asn_2",
|
||||
projectId: "proj_2",
|
||||
resourceId: "res_2",
|
||||
startDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
dailyCostCents: 500,
|
||||
status: "PROPOSED",
|
||||
project: {
|
||||
id: "proj_2",
|
||||
name: "Bravo",
|
||||
shortCode: "BRAVO",
|
||||
status: "DRAFT",
|
||||
orderType: "INTERNAL",
|
||||
},
|
||||
resource: {
|
||||
id: "res_2",
|
||||
displayName: "Bob",
|
||||
chapter: "Lighting",
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("supports unbounded resource context queries when no date window is provided", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
await listAssignmentBookings(db as never, {
|
||||
resourceIds: ["res_1", "res_2"],
|
||||
});
|
||||
|
||||
expect(db.assignment.findMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
status: { not: "CANCELLED" },
|
||||
resourceId: { in: ["res_1", "res_2"] },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
projectId: true,
|
||||
resourceId: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
hoursPerDay: true,
|
||||
dailyCostCents: true,
|
||||
status: true,
|
||||
project: {
|
||||
select: { id: true, name: true, shortCode: true, status: true, orderType: true },
|
||||
},
|
||||
resource: {
|
||||
select: { id: true, displayName: true, chapter: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects partial date bounds", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
await expect(
|
||||
listAssignmentBookings(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
}),
|
||||
).rejects.toThrow("startDate and endDate must be provided together");
|
||||
|
||||
expect(db.assignment.findMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("supports excluding explicit assignment ids", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
await listAssignmentBookings(db as never, {
|
||||
resourceIds: ["res_1"],
|
||||
excludeAssignmentIds: ["asn_1"],
|
||||
});
|
||||
|
||||
expect(db.assignment.findMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
status: { not: "CANCELLED" },
|
||||
resourceId: { in: ["res_1"] },
|
||||
id: { notIn: ["asn_1"] },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
projectId: true,
|
||||
resourceId: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
hoursPerDay: true,
|
||||
dailyCostCents: true,
|
||||
status: true,
|
||||
project: {
|
||||
select: { id: true, name: true, shortCode: true, status: true, orderType: true },
|
||||
},
|
||||
resource: {
|
||||
select: { id: true, displayName: true, chapter: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { AllocationStatus } from "@planarchy/shared";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { countEstimateHandoffPlanningEntries } from "../index.js";
|
||||
|
||||
describe("countEstimateHandoffPlanningEntries", () => {
|
||||
it("counts demand and assignment handoff entries", async () => {
|
||||
const result = await countEstimateHandoffPlanningEntries(
|
||||
{
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "demand_handoff",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-17"),
|
||||
endDate: new Date("2026-03-18"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Comp",
|
||||
roleId: "role_comp",
|
||||
headcount: 1,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: { estimateHandoff: { estimateVersionId: "ver_1" } },
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
},
|
||||
]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "assignment_handoff",
|
||||
demandRequirementId: "demand_handoff",
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-17"),
|
||||
endDate: new Date("2026-03-18"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Comp",
|
||||
roleId: "role_comp",
|
||||
dailyCostCents: 32000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: { estimateHandoff: { estimateVersionId: "ver_1" } },
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
},
|
||||
{
|
||||
id: "assignment_explicit_only",
|
||||
demandRequirementId: null,
|
||||
resourceId: "resource_2",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-19"),
|
||||
endDate: new Date("2026-03-20"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "Lead",
|
||||
roleId: "role_lead",
|
||||
dailyCostCents: 20000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: { estimateHandoff: { estimateVersionId: "ver_1" } },
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
},
|
||||
]),
|
||||
},
|
||||
} as never,
|
||||
{ projectId: "project_1", estimateVersionId: "ver_1" },
|
||||
);
|
||||
|
||||
expect(result).toBe(3);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import { AllocationStatus } from "@planarchy/shared";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { countPlanningEntries } from "../index.js";
|
||||
|
||||
describe("countPlanningEntries", () => {
|
||||
it("counts demand and assignment planning entries", async () => {
|
||||
const result = await countPlanningEntries(
|
||||
{
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-17"),
|
||||
endDate: new Date("2026-03-18"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "FX",
|
||||
roleId: "role_fx",
|
||||
headcount: 2,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
},
|
||||
]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "assignment_1",
|
||||
demandRequirementId: null,
|
||||
resourceId: "resource_1",
|
||||
projectId: "project_1",
|
||||
startDate: new Date("2026-03-17"),
|
||||
endDate: new Date("2026-03-18"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Lead",
|
||||
roleId: "role_lead",
|
||||
dailyCostCents: 32000,
|
||||
status: AllocationStatus.ACTIVE,
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-13"),
|
||||
updatedAt: new Date("2026-03-13"),
|
||||
},
|
||||
]),
|
||||
},
|
||||
} as never,
|
||||
{ projectIds: ["project_1"] },
|
||||
);
|
||||
|
||||
expect(result.totalCount).toBe(2);
|
||||
expect(result.countsByProjectId.get("project_1")).toBe(2);
|
||||
expect(result.countsByRoleId.get("role_fx")).toBe(1);
|
||||
expect(result.countsByRoleId.get("role_lead")).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,707 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
getDashboardDemand,
|
||||
getDashboardOverview,
|
||||
getDashboardPeakTimes,
|
||||
getDashboardTopValueResources,
|
||||
} from "../index.js";
|
||||
|
||||
describe("dashboard use-cases", () => {
|
||||
it("computes overview budget summary from project budgets and allocation cost", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "assignment_1",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
dailyCostCents: 1_000,
|
||||
status: "ACTIVE",
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
status: "ACTIVE",
|
||||
orderType: "FIXED",
|
||||
},
|
||||
resource: {
|
||||
id: "res_1",
|
||||
displayName: "Alice",
|
||||
chapter: "CGI",
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
resource: {
|
||||
count: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(4)
|
||||
.mockResolvedValueOnce(3),
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{ chapter: "CGI", chargeabilityTarget: 80 },
|
||||
{ chapter: "CGI", chargeabilityTarget: 60 },
|
||||
{ chapter: null, chargeabilityTarget: null },
|
||||
]),
|
||||
},
|
||||
project: {
|
||||
count: vi.fn().mockResolvedValue(2),
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{ status: "ACTIVE", budgetCents: 100_000 },
|
||||
{ status: "DRAFT", budgetCents: 50_000 },
|
||||
]),
|
||||
},
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
auditLog: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "audit_1",
|
||||
entityType: "Allocation",
|
||||
action: "CREATE",
|
||||
createdAt: new Date("2026-03-05T10:00:00.000Z"),
|
||||
},
|
||||
]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardOverview(db as never);
|
||||
|
||||
expect(result.budgetSummary).toEqual({
|
||||
totalBudgetCents: 150_000,
|
||||
totalCostCents: 3_000,
|
||||
avgUtilizationPercent: 2,
|
||||
});
|
||||
expect(result.projectsByStatus).toEqual([
|
||||
{ status: "ACTIVE", count: 1 },
|
||||
{ status: "DRAFT", count: 1 },
|
||||
]);
|
||||
expect(result.chapterUtilization).toEqual([
|
||||
{ chapter: "CGI", resourceCount: 2, avgChargeabilityTarget: 70 },
|
||||
{ chapter: "Unassigned", resourceCount: 1, avgChargeabilityTarget: 0 },
|
||||
]);
|
||||
});
|
||||
|
||||
it("avoids double-counting linked legacy allocations in overview budget totals", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "assignment_1",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
dailyCostCents: 2_000,
|
||||
status: "ACTIVE",
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
status: "ACTIVE",
|
||||
orderType: "FIXED",
|
||||
},
|
||||
resource: {
|
||||
id: "res_1",
|
||||
displayName: "Alice",
|
||||
chapter: "CGI",
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
resource: {
|
||||
count: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(1)
|
||||
.mockResolvedValueOnce(1),
|
||||
findMany: vi.fn().mockResolvedValue([{ chapter: "CGI", chargeabilityTarget: 80 }]),
|
||||
},
|
||||
project: {
|
||||
count: vi.fn().mockResolvedValue(1),
|
||||
findMany: vi.fn().mockResolvedValue([{ status: "ACTIVE", budgetCents: 100_000 }]),
|
||||
},
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
auditLog: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardOverview(db as never);
|
||||
|
||||
expect(result.budgetSummary).toEqual({
|
||||
totalBudgetCents: 100_000,
|
||||
totalCostCents: 4_000,
|
||||
avgUtilizationPercent: 4,
|
||||
});
|
||||
});
|
||||
|
||||
it("counts explicit demand and assignment rows in overview totals even without legacy allocation rows", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: "assignment_explicit",
|
||||
demandRequirementId: "demand_explicit",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
dailyCostCents: 2_000,
|
||||
status: "ACTIVE",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: "assignment_explicit",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
dailyCostCents: 2_000,
|
||||
status: "ACTIVE",
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
status: "ACTIVE",
|
||||
orderType: "FIXED",
|
||||
},
|
||||
resource: {
|
||||
id: "res_1",
|
||||
displayName: "Alice",
|
||||
chapter: "CGI",
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
resource: {
|
||||
count: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(1)
|
||||
.mockResolvedValueOnce(1),
|
||||
findMany: vi.fn().mockResolvedValue([{ chapter: "CGI", chargeabilityTarget: 80 }]),
|
||||
},
|
||||
project: {
|
||||
count: vi.fn().mockResolvedValue(1),
|
||||
findMany: vi.fn().mockResolvedValue([{ status: "ACTIVE", budgetCents: 100_000 }]),
|
||||
},
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "demand_explicit",
|
||||
projectId: "proj_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Compositor",
|
||||
roleId: "role_comp",
|
||||
headcount: 1,
|
||||
status: "ACTIVE",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
},
|
||||
{
|
||||
id: "demand_cancelled",
|
||||
projectId: "proj_2",
|
||||
startDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: "FX",
|
||||
roleId: "role_fx",
|
||||
headcount: 1,
|
||||
status: "CANCELLED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
},
|
||||
]),
|
||||
},
|
||||
auditLog: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardOverview(db as never);
|
||||
|
||||
expect(result.totalAllocations).toBe(3);
|
||||
expect(result.activeAllocations).toBe(2);
|
||||
expect(result.budgetSummary).toEqual({
|
||||
totalBudgetCents: 100_000,
|
||||
totalCostCents: 4_000,
|
||||
avgUtilizationPercent: 4,
|
||||
});
|
||||
});
|
||||
|
||||
it("aggregates peak times into sorted buckets and capacity totals", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "assign_1",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
status: "PROPOSED",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
dailyCostCents: 0,
|
||||
project: { id: "proj_1", name: "Alpha", shortCode: "ALPHA", status: "ACTIVE", orderType: "FIXED" },
|
||||
resource: { id: "res_1", displayName: "Alice", chapter: "CGI" },
|
||||
},
|
||||
{
|
||||
id: "assign_2",
|
||||
projectId: "proj_2",
|
||||
resourceId: "res_2",
|
||||
status: "PROPOSED",
|
||||
startDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 3,
|
||||
dailyCostCents: 0,
|
||||
project: { id: "proj_2", name: "Bravo", shortCode: "BRAVO", status: "ACTIVE", orderType: "FIXED" },
|
||||
resource: { id: "res_2", displayName: "Bob", chapter: "Lighting" },
|
||||
},
|
||||
]),
|
||||
},
|
||||
resource: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{ availability: { monday: 8, tuesday: 8, wednesday: 8, thursday: 8, friday: 8 } },
|
||||
{ availability: { monday: 6, tuesday: 6, wednesday: 6, thursday: 6, friday: 6 } },
|
||||
]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardPeakTimes(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
granularity: "month",
|
||||
groupBy: "project",
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
period: "2026-03",
|
||||
groups: [
|
||||
{ name: "ALPHA", hours: 8 },
|
||||
{ name: "BRAVO", hours: 3 },
|
||||
],
|
||||
totalHours: 11,
|
||||
capacityHours: 308,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("enforces visible-role filtering for top value resources", async () => {
|
||||
const db = {
|
||||
systemSettings: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
scoreVisibleRoles: ["ADMIN"],
|
||||
}),
|
||||
},
|
||||
resource: {
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
const hidden = await getDashboardTopValueResources(db as never, {
|
||||
limit: 10,
|
||||
userRole: "USER",
|
||||
});
|
||||
|
||||
expect(hidden).toEqual([]);
|
||||
expect(db.resource.findMany).not.toHaveBeenCalled();
|
||||
|
||||
db.resource.findMany.mockResolvedValue([{ id: "res_1", valueScore: 99 }]);
|
||||
|
||||
const visible = await getDashboardTopValueResources(db as never, {
|
||||
limit: 1,
|
||||
userRole: "ADMIN",
|
||||
});
|
||||
|
||||
expect(visible).toEqual([{ id: "res_1", valueScore: 99 }]);
|
||||
expect(db.resource.findMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ take: 1 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("returns distinct resource counts for chapter demand grouping", async () => {
|
||||
const db = {
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "alloc_1",
|
||||
demandRequirementId: null,
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [],
|
||||
},
|
||||
resource: { id: "res_1", displayName: "Alice", chapter: "CGI" },
|
||||
},
|
||||
{
|
||||
id: "alloc_2",
|
||||
demandRequirementId: null,
|
||||
projectId: "proj_2",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 6,
|
||||
percentage: 75,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
project: {
|
||||
id: "proj_2",
|
||||
name: "Bravo",
|
||||
shortCode: "BRAVO",
|
||||
staffingReqs: [],
|
||||
},
|
||||
resource: { id: "res_1", displayName: "Alice", chapter: "CGI" },
|
||||
},
|
||||
{
|
||||
id: "alloc_3",
|
||||
demandRequirementId: null,
|
||||
projectId: "proj_2",
|
||||
resourceId: "res_2",
|
||||
startDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 5,
|
||||
percentage: 62.5,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
project: {
|
||||
id: "proj_2",
|
||||
name: "Bravo",
|
||||
shortCode: "BRAVO",
|
||||
staffingReqs: [],
|
||||
},
|
||||
resource: { id: "res_2", displayName: "Bob", chapter: "CGI" },
|
||||
},
|
||||
]),
|
||||
},
|
||||
project: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardDemand(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-31T00:00:00.000Z"),
|
||||
groupBy: "chapter",
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
id: "CGI",
|
||||
name: "CGI",
|
||||
shortCode: "CGI",
|
||||
allocatedHours: 19,
|
||||
requiredFTEs: 0,
|
||||
resourceCount: 2,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("prefers demand requirements and assignments for project demand semantics", async () => {
|
||||
const db = {
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "dem_1",
|
||||
projectId: "proj_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
headcount: 2,
|
||||
status: "PROPOSED",
|
||||
},
|
||||
{
|
||||
id: "dem_2",
|
||||
projectId: "proj_1",
|
||||
startDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
headcount: 1,
|
||||
status: "COMPLETED",
|
||||
},
|
||||
]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "asn_1",
|
||||
demandRequirementId: "dem_1",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
resource: { id: "res_1", displayName: "Alice", chapter: "CGI" },
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [{ fteCount: 9 }],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "asn_2",
|
||||
demandRequirementId: "dem_2",
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_2",
|
||||
startDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 4,
|
||||
percentage: 50,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-02T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-02T00:00:00.000Z"),
|
||||
resource: { id: "res_2", displayName: "Bob", chapter: "Lighting" },
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [{ fteCount: 9 }],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "asn_3",
|
||||
demandRequirementId: null,
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_3",
|
||||
startDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-03T00:00:00.000Z"),
|
||||
hoursPerDay: 6,
|
||||
percentage: 75,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-03T00:00:00.000Z"),
|
||||
resource: { id: "res_3", displayName: "Cara", chapter: "CGI" },
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [{ fteCount: 9 }],
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
project: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [{ fteCount: 9 }],
|
||||
},
|
||||
]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardDemand(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-31T00:00:00.000Z"),
|
||||
groupBy: "project",
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
allocatedHours: 18,
|
||||
requiredFTEs: 3.5,
|
||||
resourceCount: 3,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps explicit project metadata when demand and assignment rows exist without legacy allocations", async () => {
|
||||
const db = {
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "dem_1",
|
||||
projectId: "proj_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
headcount: 1,
|
||||
status: "PROPOSED",
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [],
|
||||
},
|
||||
},
|
||||
]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "asn_1",
|
||||
demandRequirementId: "dem_1",
|
||||
projectId: "proj_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [],
|
||||
},
|
||||
resource: { id: "res_1", displayName: "Alice", chapter: "CGI" },
|
||||
},
|
||||
]),
|
||||
},
|
||||
project: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardDemand(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-31T00:00:00.000Z"),
|
||||
groupBy: "project",
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
allocatedHours: 8,
|
||||
requiredFTEs: 2,
|
||||
resourceCount: 1,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("falls back to staffing requirements when no demand rows exist", async () => {
|
||||
const db = {
|
||||
demandRequirement: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
assignment: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "alloc_1",
|
||||
demandRequirementId: null,
|
||||
projectId: "proj_1",
|
||||
resourceId: "res_1",
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-02T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: null,
|
||||
roleId: null,
|
||||
dailyCostCents: 0,
|
||||
status: "PROPOSED",
|
||||
metadata: {},
|
||||
createdAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-03-01T00:00:00.000Z"),
|
||||
project: {
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [{ fteCount: 2 }],
|
||||
},
|
||||
resource: { id: "res_1", displayName: "Alice", chapter: "CGI" },
|
||||
},
|
||||
]),
|
||||
},
|
||||
project: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
staffingReqs: [{ fteCount: 2 }],
|
||||
},
|
||||
]),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getDashboardDemand(db as never, {
|
||||
startDate: new Date("2026-03-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-03-31T00:00:00.000Z"),
|
||||
groupBy: "project",
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
id: "proj_1",
|
||||
name: "Alpha",
|
||||
shortCode: "ALPHA",
|
||||
allocatedHours: 16,
|
||||
requiredFTEs: 2,
|
||||
resourceCount: 1,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { deleteAssignment } from "../index.js";
|
||||
|
||||
describe("deleteAssignment", () => {
|
||||
it("deletes an explicit assignment row", async () => {
|
||||
const db = {
|
||||
assignment: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
}),
|
||||
delete: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await deleteAssignment(db as never, "assignment_1");
|
||||
|
||||
expect(result).toEqual({
|
||||
deletedId: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
});
|
||||
expect(db.assignment.delete).toHaveBeenCalledWith({
|
||||
where: { id: "assignment_1" },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { deleteDemandRequirement } from "../index.js";
|
||||
|
||||
describe("deleteDemandRequirement", () => {
|
||||
it("deletes an explicit demand and unlinks assignments", async () => {
|
||||
const db = {
|
||||
demandRequirement: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "demand_1",
|
||||
projectId: "project_1",
|
||||
}),
|
||||
delete: vi.fn().mockResolvedValue({}),
|
||||
},
|
||||
assignment: {
|
||||
updateMany: vi.fn().mockResolvedValue({ count: 2 }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await deleteDemandRequirement(db as never, "demand_1");
|
||||
|
||||
expect(result).toEqual({
|
||||
deletedId: "demand_1",
|
||||
projectId: "project_1",
|
||||
});
|
||||
expect(db.assignment.updateMany).toHaveBeenCalledWith({
|
||||
where: { demandRequirementId: "demand_1" },
|
||||
data: { demandRequirementId: null },
|
||||
});
|
||||
expect(db.demandRequirement.delete).toHaveBeenCalledWith({
|
||||
where: { id: "demand_1" },
|
||||
});
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,759 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
assessDispoImportReadiness,
|
||||
parseDispoChargeabilityWorkbook,
|
||||
parseDispoPlanningWorkbook,
|
||||
parseResourceRosterMasterWorkbook,
|
||||
parseDispoRosterWorkbook,
|
||||
parseMandatoryDispoReferenceWorkbook,
|
||||
stageDispoImportBatch,
|
||||
stageDispoChargeabilityResources,
|
||||
stageDispoPlanningData,
|
||||
stageDispoProjects,
|
||||
stageDispoRosterResources,
|
||||
stageDispoReferenceData,
|
||||
} from "../index.js";
|
||||
|
||||
const mandatoryWorkbookPath = fileURLToPath(
|
||||
new URL("../../../../samples/Dispov2/MandatoryDispoCategories_V3.xlsx", import.meta.url),
|
||||
);
|
||||
const chargeabilityWorkbookPath = fileURLToPath(
|
||||
new URL(
|
||||
"../../../../samples/Dispov2/20260309_Bi-Weekly_Chargeability_Reporting_Content_Production_V0.943_4Hartmut.xlsx",
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
const planningWorkbookPath = fileURLToPath(
|
||||
new URL("../../../../samples/Dispov2/DISPO_2026.xlsx", import.meta.url),
|
||||
);
|
||||
const rosterWorkbookPath = fileURLToPath(
|
||||
new URL("../../../../samples/Dispov2/MV_DispoRoster.xlsx", import.meta.url),
|
||||
);
|
||||
const costWorkbookPath = fileURLToPath(
|
||||
new URL(
|
||||
"../../../../samples/Dispov2/Resource Roster_MASTER_FY26_CJ_20251201.xlsx",
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
|
||||
describe("dispo import", () => {
|
||||
it("parses the mandatory reference workbook into normalized master data", async () => {
|
||||
const parsed = await parseMandatoryDispoReferenceWorkbook(mandatoryWorkbookPath);
|
||||
|
||||
expect(parsed.countries).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
countryCode: "DE",
|
||||
name: "Germany",
|
||||
metroCities: expect.arrayContaining(["Munich", "Stuttgart"]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
countryCode: "ES",
|
||||
name: "Spain",
|
||||
dailyWorkingHours: 8,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(parsed.orgUnits).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ level: 5, name: "Content Production", parentName: null }),
|
||||
expect.objectContaining({
|
||||
level: 6,
|
||||
name: "CGI Content",
|
||||
parentName: "Content Production",
|
||||
}),
|
||||
expect.objectContaining({ level: 7, name: "Art Direction", parentName: "CGI Content" }),
|
||||
]),
|
||||
);
|
||||
expect(parsed.managementLevelGroups).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "Consultant",
|
||||
targetPercentage: 0.808,
|
||||
levels: expect.arrayContaining(["8-Associate Manager", "9-Team Lead/Consultant"]),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(parsed.clients).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ name: "BMW", clientCode: "BMW", parentName: null }),
|
||||
expect.objectContaining({ name: "BMW AG", parentName: "BMW", parentClientCode: "BMW" }),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("parses the chargeability workbook into deduplicated staged resources", async () => {
|
||||
const parsed = await parseDispoChargeabilityWorkbook(chargeabilityWorkbookPath);
|
||||
|
||||
expect(parsed.resources.length).toBeGreaterThan(300);
|
||||
expect(parsed.unresolved).toEqual([]);
|
||||
expect(parsed.resources).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
canonicalExternalId: "a.kasperovich",
|
||||
chapter: "CGI Development",
|
||||
countryCode: "DE",
|
||||
chargeabilityTarget: 74.7,
|
||||
resourceType: "EMPLOYEE",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
canonicalExternalId: "alexander.broeckel",
|
||||
chapter: "Digital Content Production",
|
||||
chapterCode: "3D",
|
||||
roleTokens: ["3D"],
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("parses the planning workbook into staged assignments, vacations, availability rules, and unresolved project references", async () => {
|
||||
const parsed = await parseDispoPlanningWorkbook(planningWorkbookPath);
|
||||
|
||||
expect(parsed.assignments.length).toBeGreaterThan(1000);
|
||||
expect(parsed.vacations.length).toBeGreaterThan(1000);
|
||||
expect(parsed.availabilityRules.length).toBeGreaterThan(0);
|
||||
expect(parsed.unresolved.length).toBeGreaterThan(0);
|
||||
expect(parsed.assignments).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
resourceExternalId: "a.d.singh.sandhu",
|
||||
assignmentDate: new Date("2025-12-22T00:00:00.000Z"),
|
||||
hoursPerDay: 8,
|
||||
isInternal: false,
|
||||
isTbd: true,
|
||||
projectKey: null,
|
||||
utilizationCategoryCode: "Chg",
|
||||
winProbability: 80,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(parsed.vacations).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
resourceExternalId: "samuel.bubat",
|
||||
startDate: new Date("2025-12-22T00:00:00.000Z"),
|
||||
endDate: new Date("2025-12-22T00:00:00.000Z"),
|
||||
vacationType: "ANNUAL",
|
||||
isHalfDay: false,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
resourceExternalId: "samuel.bubat",
|
||||
startDate: new Date("2025-12-24T00:00:00.000Z"),
|
||||
endDate: new Date("2025-12-24T00:00:00.000Z"),
|
||||
vacationType: "PUBLIC_HOLIDAY",
|
||||
isPublicHoliday: true,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(parsed.availabilityRules).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
resourceExternalId: "marina.hechler",
|
||||
effectiveStartDate: new Date("2025-12-22T00:00:00.000Z"),
|
||||
availableHours: 6,
|
||||
percentage: 75,
|
||||
ruleType: "PART_TIME",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("parses the roster workbook into merged resource master rows", async () => {
|
||||
const parsed = await parseDispoRosterWorkbook(rosterWorkbookPath, { costWorkbookPath });
|
||||
|
||||
expect(parsed.resources.length).toBeGreaterThan(500);
|
||||
expect(parsed.ignoredPseudoDemandRows).toBeGreaterThan(100);
|
||||
expect(parsed.excludedCanonicalExternalIds).toEqual(
|
||||
expect.arrayContaining(["antonia.melzer", "placeholder.hamburg"]),
|
||||
);
|
||||
expect(parsed.resources).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
canonicalExternalId: "a.kasperovich",
|
||||
displayName: "Alexander Kasperovich",
|
||||
email: "a.kasperovich@accenture.com",
|
||||
lcrCents: 10892,
|
||||
rateResolution: "EXACT",
|
||||
ucrCents: 7261,
|
||||
chapter: "CGI-Dev",
|
||||
clientUnitName: "Cross-Unit",
|
||||
sourceSheet: "DispoRoster",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
canonicalExternalId: "alexander.broeckel",
|
||||
displayName: "Alex Bröckel",
|
||||
email: "alexander.broeckel@accenture.com",
|
||||
sourceSheet: "SAP_data",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
canonicalExternalId: "a.appelt",
|
||||
email: "a.appelt@accenture.com",
|
||||
rateResolution: "LEVEL_AVERAGE",
|
||||
rateResolutionLevel: "10-Senior Analyst",
|
||||
resourceType: "FREELANCER",
|
||||
roleTokens: ["2D"],
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(parsed.resources.find((resource) => resource.canonicalExternalId === "antonia.melzer")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("parses the cost workbook into exact rates and level averages", async () => {
|
||||
const parsed = await parseResourceRosterMasterWorkbook(costWorkbookPath);
|
||||
|
||||
expect(parsed.rates.get("a.kasperovich")).toEqual(
|
||||
expect.objectContaining({
|
||||
canonicalExternalId: "a.kasperovich",
|
||||
lcrCents: 10892,
|
||||
ucrCents: 7261,
|
||||
level: "7-Manager",
|
||||
}),
|
||||
);
|
||||
expect(parsed.levelAverages.get("10-Senior Analyst")).toEqual(
|
||||
expect.objectContaining({
|
||||
level: "10-Senior Analyst",
|
||||
lcrCents: expect.any(Number),
|
||||
ucrCents: expect.any(Number),
|
||||
sampleCount: expect.any(Number),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("assesses import readiness against the merged workbook constraints", async () => {
|
||||
const report = await assessDispoImportReadiness({
|
||||
referenceWorkbookPath: mandatoryWorkbookPath,
|
||||
chargeabilityWorkbookPath,
|
||||
planningWorkbookPath,
|
||||
rosterWorkbookPath,
|
||||
costWorkbookPath,
|
||||
});
|
||||
|
||||
expect(report.resourceCount).toBeGreaterThan(500);
|
||||
expect(report.canCommitWithStrictSourceData).toBe(true);
|
||||
expect(report.canCommitWithFallbacks).toBe(true);
|
||||
expect(report.issues.find((issue) => issue.code === "FALLBACK_EMAIL_REQUIRED")).toBeUndefined();
|
||||
expect(report.issues.find((issue) => issue.code === "FALLBACK_LCR_REQUIRED")).toBeUndefined();
|
||||
expect(report.issues.find((issue) => issue.code === "FALLBACK_UCR_REQUIRED")).toBeUndefined();
|
||||
expect(
|
||||
report.issues.find((issue) => issue.code === "PLANNING_RESOURCE_MISSING_FROM_ROSTER"),
|
||||
).toBeUndefined();
|
||||
expect(report.issues).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "REFERENCE_RESOURCE_MASTER_MISSING",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(report.issues).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "UNRESOLVED_RECORDS_PRESENT",
|
||||
severity: "warning",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("stages reference workbook clients and upserts master data", async () => {
|
||||
const db = {
|
||||
importBatch: {
|
||||
create: vi.fn().mockResolvedValue({ id: "batch_1", summary: {} }),
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn().mockResolvedValue({ id: "batch_1", summary: {} }),
|
||||
},
|
||||
country: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "country_1" }),
|
||||
},
|
||||
metroCity: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "city_1" }),
|
||||
},
|
||||
orgUnit: {
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
create: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ id: "org_root" })
|
||||
.mockResolvedValue({ id: "org_child" }),
|
||||
update: vi.fn(),
|
||||
upsert: vi.fn().mockResolvedValue({ id: "org_upserted" }),
|
||||
},
|
||||
managementLevelGroup: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "group_1" }),
|
||||
},
|
||||
managementLevel: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "level_1" }),
|
||||
},
|
||||
client: {
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
create: vi.fn().mockResolvedValue({ id: "client_1" }),
|
||||
update: vi.fn(),
|
||||
},
|
||||
stagedClient: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 10 }),
|
||||
},
|
||||
stagedResource: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedUnresolvedRecord: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await stageDispoReferenceData(db as never, {
|
||||
referenceWorkbookPath: mandatoryWorkbookPath,
|
||||
});
|
||||
|
||||
expect(result.batchId).toBe("batch_1");
|
||||
expect(result.counts.countries).toBeGreaterThan(0);
|
||||
expect(db.country.upsert).toHaveBeenCalled();
|
||||
expect(db.stagedClient.createMany).toHaveBeenCalled();
|
||||
expect(db.importBatch.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { id: "batch_1" },
|
||||
data: expect.objectContaining({
|
||||
status: "STAGED",
|
||||
summary: expect.objectContaining({
|
||||
reference: expect.objectContaining({
|
||||
stagedClients: expect.any(Number),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("stages chargeability roster resources into staged resource rows", async () => {
|
||||
const db = {
|
||||
importBatch: {
|
||||
create: vi.fn().mockResolvedValue({ id: "batch_2", summary: {} }),
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn().mockResolvedValue({ id: "batch_2", summary: {} }),
|
||||
},
|
||||
client: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
country: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
metroCity: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
orgUnit: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevelGroup: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevel: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
stagedClient: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedResource: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
stagedUnresolvedRecord: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await stageDispoChargeabilityResources(db as never, {
|
||||
chargeabilityWorkbookPath,
|
||||
});
|
||||
|
||||
expect(result.batchId).toBe("batch_2");
|
||||
expect(result.counts.stagedResources).toBeGreaterThan(300);
|
||||
expect(db.stagedResource.createMany).toHaveBeenCalled();
|
||||
expect(db.importBatch.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
status: "STAGED",
|
||||
summary: expect.objectContaining({
|
||||
chargeability: expect.objectContaining({
|
||||
stagedResources: expect.any(Number),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("stages roster and SAP workbook rows into staged resource rows", async () => {
|
||||
const db = {
|
||||
importBatch: {
|
||||
create: vi.fn().mockResolvedValue({ id: "batch_roster", summary: {} }),
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn().mockResolvedValue({ id: "batch_roster", summary: {} }),
|
||||
},
|
||||
client: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
country: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
metroCity: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
orgUnit: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevelGroup: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevel: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
stagedClient: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedResource: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
stagedUnresolvedRecord: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await stageDispoRosterResources(db as never, {
|
||||
rosterWorkbookPath,
|
||||
costWorkbookPath,
|
||||
});
|
||||
|
||||
expect(result.batchId).toBe("batch_roster");
|
||||
expect(result.counts.stagedResources).toBeGreaterThan(500);
|
||||
expect(result.counts.ignoredPseudoDemandRows).toBeGreaterThan(100);
|
||||
expect(result.counts.excludedResources).toBeGreaterThan(0);
|
||||
expect(db.stagedResource.createMany).toHaveBeenCalled();
|
||||
expect(db.stagedResource.createMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
lcrCents: expect.any(Number),
|
||||
ucrCents: expect.any(Number),
|
||||
normalizedData: expect.objectContaining({
|
||||
rateResolution: expect.any(String),
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(db.importBatch.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
status: "STAGED",
|
||||
summary: expect.objectContaining({
|
||||
roster: expect.objectContaining({
|
||||
stagedResources: expect.any(Number),
|
||||
ignoredPseudoDemandRows: expect.any(Number),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("stages planning workbook rows into staged planning records", async () => {
|
||||
const db = {
|
||||
importBatch: {
|
||||
create: vi.fn().mockResolvedValue({ id: "batch_3", summary: {} }),
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn().mockResolvedValue({ id: "batch_3", summary: {} }),
|
||||
},
|
||||
client: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
country: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
metroCity: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
orgUnit: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevelGroup: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevel: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
stagedClient: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedResource: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedAssignment: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 1000 }),
|
||||
},
|
||||
stagedVacation: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 1000 }),
|
||||
},
|
||||
stagedAvailabilityRule: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
stagedUnresolvedRecord: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await stageDispoPlanningData(db as never, {
|
||||
planningWorkbookPath,
|
||||
});
|
||||
|
||||
expect(result.batchId).toBe("batch_3");
|
||||
expect(result.counts.stagedAssignments).toBeGreaterThan(1000);
|
||||
expect(result.counts.stagedVacations).toBeGreaterThan(1000);
|
||||
expect(result.counts.stagedAvailabilityRules).toBeGreaterThan(0);
|
||||
expect(result.counts.unresolved).toBeGreaterThan(0);
|
||||
expect(db.stagedAssignment.createMany).toHaveBeenCalled();
|
||||
expect(db.stagedVacation.createMany).toHaveBeenCalled();
|
||||
expect(db.stagedAvailabilityRule.createMany).toHaveBeenCalled();
|
||||
expect(db.stagedUnresolvedRecord.createMany).toHaveBeenCalled();
|
||||
expect(db.importBatch.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
status: "STAGED",
|
||||
summary: expect.objectContaining({
|
||||
planning: expect.objectContaining({
|
||||
stagedAssignments: expect.any(Number),
|
||||
stagedVacations: expect.any(Number),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves staged projects from planning workbook assignments", async () => {
|
||||
const db = {
|
||||
importBatch: {
|
||||
create: vi.fn().mockResolvedValue({ id: "batch_4", summary: {} }),
|
||||
findUnique: vi.fn(),
|
||||
update: vi.fn().mockResolvedValue({ id: "batch_4", summary: {} }),
|
||||
},
|
||||
client: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
country: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
metroCity: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
orgUnit: {
|
||||
findFirst: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevelGroup: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
managementLevel: {
|
||||
upsert: vi.fn(),
|
||||
},
|
||||
stagedClient: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedResource: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedAssignment: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedVacation: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedAvailabilityRule: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
stagedProject: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
stagedUnresolvedRecord: {
|
||||
deleteMany: vi.fn(),
|
||||
createMany: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await stageDispoProjects(db as never, {
|
||||
planningWorkbookPath,
|
||||
});
|
||||
|
||||
expect(result.batchId).toBe("batch_4");
|
||||
expect(result.counts.stagedProjects).toBeGreaterThan(10);
|
||||
expect(db.stagedProject.createMany).toHaveBeenCalled();
|
||||
expect(db.stagedProject.createMany).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
projectKey: "INT-MO",
|
||||
shortCode: "INT-MO",
|
||||
name: "Management & Operations",
|
||||
isInternal: true,
|
||||
utilizationCategoryCode: "M&O",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
projectKey: "11035763",
|
||||
shortCode: "11035763",
|
||||
clientCode: "BMW",
|
||||
isInternal: false,
|
||||
utilizationCategoryCode: "Chg",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(db.importBatch.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
status: "STAGED",
|
||||
summary: expect.objectContaining({
|
||||
projectResolution: expect.objectContaining({
|
||||
stagedProjects: expect.any(Number),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("stages all dispo workbooks into one import batch and persists readiness", async () => {
|
||||
const db = {
|
||||
importBatch: {
|
||||
create: vi.fn().mockResolvedValue({ id: "batch_5", summary: {} }),
|
||||
findUnique: vi.fn().mockResolvedValue({ id: "batch_5", summary: {} }),
|
||||
update: vi.fn().mockResolvedValue({ id: "batch_5", summary: {} }),
|
||||
},
|
||||
client: {
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
create: vi.fn().mockResolvedValue({ id: "client_1" }),
|
||||
update: vi.fn(),
|
||||
},
|
||||
country: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "country_1" }),
|
||||
},
|
||||
metroCity: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "metro_1" }),
|
||||
},
|
||||
orgUnit: {
|
||||
findFirst: vi.fn().mockResolvedValue(null),
|
||||
create: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ id: "org_root" })
|
||||
.mockResolvedValue({ id: "org_child" }),
|
||||
update: vi.fn(),
|
||||
upsert: vi.fn().mockResolvedValue({ id: "org_upserted" }),
|
||||
},
|
||||
managementLevelGroup: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "group_1" }),
|
||||
},
|
||||
managementLevel: {
|
||||
upsert: vi.fn().mockResolvedValue({ id: "level_1" }),
|
||||
},
|
||||
stagedClient: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 10 }),
|
||||
},
|
||||
stagedResource: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ count: 100 })
|
||||
.mockResolvedValueOnce({ count: 100 }),
|
||||
},
|
||||
stagedProject: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 50 }),
|
||||
},
|
||||
stagedAssignment: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 1000 }),
|
||||
},
|
||||
stagedVacation: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 1000 }),
|
||||
},
|
||||
stagedAvailabilityRule: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
stagedUnresolvedRecord: {
|
||||
deleteMany: vi.fn().mockResolvedValue({ count: 0 }),
|
||||
createMany: vi.fn().mockResolvedValue({ count: 100 }),
|
||||
},
|
||||
};
|
||||
|
||||
const result = await stageDispoImportBatch(db as never, {
|
||||
referenceWorkbookPath: mandatoryWorkbookPath,
|
||||
chargeabilityWorkbookPath,
|
||||
planningWorkbookPath,
|
||||
rosterWorkbookPath,
|
||||
costWorkbookPath,
|
||||
});
|
||||
|
||||
expect(result.batchId).toBe("batch_5");
|
||||
expect(result.counts.stagedResources).toBeGreaterThan(800);
|
||||
expect(result.counts.stagedRosterResources).toBeGreaterThan(500);
|
||||
expect(result.counts.stagedAssignments).toBeGreaterThan(1000);
|
||||
expect(result.readiness.canCommitWithStrictSourceData).toBe(true);
|
||||
expect(result.readiness.issues).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "REFERENCE_RESOURCE_MASTER_MISSING",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(db.importBatch.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { id: "batch_5" },
|
||||
data: expect.objectContaining({
|
||||
summary: expect.objectContaining({
|
||||
readiness: expect.objectContaining({
|
||||
canCommitWithStrictSourceData: true,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { AllocationStatus, type AllocationWithDetails } from "@planarchy/shared";
|
||||
import {
|
||||
buildSplitAllocationReadModel,
|
||||
} from "../index.js";
|
||||
|
||||
const project = {
|
||||
id: "project_1",
|
||||
name: "Project One",
|
||||
shortCode: "P1",
|
||||
status: "ACTIVE",
|
||||
startDate: new Date("2026-01-01"),
|
||||
endDate: new Date("2026-01-31"),
|
||||
orderType: "CHARGEABLE",
|
||||
budgetCents: 100_000,
|
||||
winProbability: 100,
|
||||
staffingReqs: [],
|
||||
responsiblePerson: "Alex",
|
||||
} satisfies AllocationWithDetails["project"];
|
||||
|
||||
const resource = {
|
||||
id: "resource_1",
|
||||
displayName: "Ada Lovelace",
|
||||
eid: "E-1",
|
||||
lcrCents: 10_000,
|
||||
chapter: "Engineering",
|
||||
availability: null,
|
||||
};
|
||||
|
||||
const roleEntity = {
|
||||
id: "role_1",
|
||||
name: "Engineer",
|
||||
color: "#123456",
|
||||
};
|
||||
|
||||
describe("buildSplitAllocationReadModel", () => {
|
||||
it("builds demand and assignment entries from explicit rows", () => {
|
||||
const result = buildSplitAllocationReadModel({
|
||||
demandRequirements: [
|
||||
{
|
||||
id: "demand_1",
|
||||
projectId: project.id,
|
||||
startDate: new Date("2026-01-06"),
|
||||
endDate: new Date("2026-01-10"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Engineer",
|
||||
roleId: roleEntity.id,
|
||||
headcount: 2,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: { source: "explicit-demand" },
|
||||
createdAt: new Date("2026-01-01"),
|
||||
updatedAt: new Date("2026-01-02"),
|
||||
project,
|
||||
roleEntity,
|
||||
},
|
||||
],
|
||||
assignments: [
|
||||
{
|
||||
id: "assignment_1",
|
||||
demandRequirementId: "demand_1",
|
||||
resourceId: resource.id,
|
||||
projectId: project.id,
|
||||
startDate: new Date("2026-01-06"),
|
||||
endDate: new Date("2026-01-10"),
|
||||
hoursPerDay: 8,
|
||||
percentage: 100,
|
||||
role: "Engineer",
|
||||
roleId: roleEntity.id,
|
||||
dailyCostCents: 80_000,
|
||||
status: AllocationStatus.PROPOSED,
|
||||
metadata: { source: "explicit-assignment" },
|
||||
createdAt: new Date("2026-01-01"),
|
||||
updatedAt: new Date("2026-01-02"),
|
||||
resource,
|
||||
project,
|
||||
roleEntity,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(result.allocations).toHaveLength(2);
|
||||
expect(result.demands).toHaveLength(1);
|
||||
expect(result.assignments).toHaveLength(1);
|
||||
|
||||
expect(result.demands[0]).toMatchObject({
|
||||
id: "demand_1",
|
||||
entityId: "demand_1",
|
||||
sourceAllocationId: "demand_1",
|
||||
requestedHeadcount: 2,
|
||||
metadata: { source: "explicit-demand" },
|
||||
});
|
||||
expect(result.assignments[0]).toMatchObject({
|
||||
id: "assignment_1",
|
||||
entityId: "assignment_1",
|
||||
sourceAllocationId: "assignment_1",
|
||||
resourceId: resource.id,
|
||||
metadata: { source: "explicit-assignment" },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns empty arrays when given no inputs", () => {
|
||||
const result = buildSplitAllocationReadModel({
|
||||
demandRequirements: [],
|
||||
assignments: [],
|
||||
});
|
||||
|
||||
expect(result.allocations).toHaveLength(0);
|
||||
expect(result.demands).toHaveLength(0);
|
||||
expect(result.assignments).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user