chore(repo): initialize planarchy workspace
This commit is contained in:
@@ -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,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user