fix(application): normalize dashboard top value score breakdown

This commit is contained in:
2026-03-31 22:35:02 +02:00
parent 78d19c59b6
commit f2bcf4b7f0
2 changed files with 221 additions and 5 deletions
@@ -352,6 +352,11 @@ describe("dashboard use-cases", () => {
totalHours: 7,
capacityHours: 28,
derivation: expect.objectContaining({
baseAvailableHours: 28,
effectiveAvailableHours: 28,
publicHolidayHoursDeduction: 0,
absenceDayEquivalent: 0,
absenceHoursDeduction: 0,
bookedHours: 7,
capacityHours: 28,
remainingCapacityHours: 21,
@@ -441,6 +446,11 @@ describe("dashboard use-cases", () => {
totalHours: 8,
capacityHours: 12,
derivation: expect.objectContaining({
baseAvailableHours: 12,
effectiveAvailableHours: 12,
publicHolidayHoursDeduction: 0,
absenceDayEquivalent: 0,
absenceHoursDeduction: 0,
bookedHours: 8,
capacityHours: 12,
remainingCapacityHours: 4,
@@ -473,16 +483,68 @@ describe("dashboard use-cases", () => {
expect(hidden).toEqual([]);
expect(db.resource.findMany).not.toHaveBeenCalled();
db.resource.findMany.mockResolvedValue([{ id: "res_1", valueScore: 99 }]);
db.resource.findMany.mockResolvedValue([
{
id: "res_1",
eid: "alice",
displayName: "Alice",
chapter: "Delivery",
valueScore: 99,
valueScoreBreakdown: {
skillDepth: 90,
skillBreadth: 80,
costEfficiency: 85,
chargeability: 88,
experience: 92,
total: 99,
},
valueScoreUpdatedAt: new Date("2026-03-01T00:00:00.000Z"),
lcrCents: 12_300,
country: { code: "DE", name: "Germany" },
federalState: "BY",
metroCity: { name: "Munich" },
},
]);
const visible = await getDashboardTopValueResources(db as never, {
limit: 1,
userRole: "ADMIN",
});
expect(visible).toEqual([{ id: "res_1", valueScore: 99 }]);
expect(visible).toEqual([
{
id: "res_1",
eid: "alice",
displayName: "Alice",
chapter: "Delivery",
valueScore: 99,
valueScoreBreakdown: {
skillDepth: 90,
skillBreadth: 80,
costEfficiency: 85,
chargeability: 88,
experience: 92,
total: 99,
},
valueScoreUpdatedAt: new Date("2026-03-01T00:00:00.000Z"),
lcrCents: 12_300,
countryCode: "DE",
countryName: "Germany",
federalState: "BY",
metroCityName: "Munich",
},
]);
expect(db.resource.findMany).toHaveBeenCalledWith(
expect.objectContaining({ take: 1 }),
expect.objectContaining({
take: 1,
select: expect.objectContaining({
valueScoreBreakdown: true,
valueScoreUpdatedAt: true,
country: { select: { code: true, name: true } },
federalState: true,
metroCity: { select: { name: true } },
}),
}),
);
});
@@ -789,6 +851,11 @@ describe("dashboard use-cases", () => {
totalHours: 8,
capacityHours: 8,
derivation: expect.objectContaining({
baseAvailableHours: 16,
effectiveAvailableHours: 8,
publicHolidayHoursDeduction: 8,
absenceDayEquivalent: 0,
absenceHoursDeduction: 0,
bookedHours: 8,
capacityHours: 8,
remainingCapacityHours: 0,
@@ -801,6 +868,69 @@ describe("dashboard use-cases", () => {
]);
});
it("exposes holiday and approved-absence deductions in peak times derivation", async () => {
const db = {
assignment: {
findMany: vi.fn().mockResolvedValue([]),
},
resource: {
findMany: vi.fn().mockResolvedValue([
{
id: "res_by",
displayName: "Bruce",
chapter: "CGI",
availability: { monday: 8, tuesday: 8, wednesday: 8, thursday: 8, friday: 8 },
countryId: "country_de",
federalState: "BY",
metroCityId: "city_munich",
country: { code: "DE" },
metroCity: { name: "Munich" },
},
]),
},
vacation: {
findMany: vi.fn().mockResolvedValue([
{
resourceId: "res_by",
startDate: new Date("2026-01-05T00:00:00.000Z"),
endDate: new Date("2026-01-05T00:00:00.000Z"),
type: "VACATION",
isHalfDay: false,
},
]),
},
};
const result = await getDashboardPeakTimes(db as never, {
startDate: new Date("2026-01-05T00:00:00.000Z"),
endDate: new Date("2026-01-06T00:00:00.000Z"),
granularity: "month",
groupBy: "chapter",
});
expect(result).toEqual([
expect.objectContaining({
period: "2026-01",
totalHours: 0,
capacityHours: 0,
derivation: expect.objectContaining({
baseAvailableHours: 16,
effectiveAvailableHours: 0,
publicHolidayHoursDeduction: 8,
absenceDayEquivalent: 1,
absenceHoursDeduction: 8,
bookedHours: 0,
capacityHours: 0,
remainingCapacityHours: 0,
overbookedHours: 0,
utilizationPct: 0,
groupCount: 0,
resourceCount: 1,
}),
}),
]);
});
it("does not burn budget on regional public holidays", async () => {
const db = {
project: {
@@ -919,6 +1049,17 @@ describe("dashboard use-cases", () => {
remainingCents: 95_000,
burnRate: 4_000,
activeAssignmentCount: 1,
derivation: expect.objectContaining({
calendarContextCount: 1,
holidayAwareAssignmentCount: 1,
fallbackAssignmentCount: 0,
baseBurnRateCents: 4_000,
adjustedBurnRateCents: 4_000,
publicHolidayDayEquivalent: 0,
publicHolidayCostDeductionCents: 0,
absenceDayEquivalent: 0,
absenceCostDeductionCents: 0,
}),
calendarLocations: [
expect.objectContaining({
countryCode: "DE",
@@ -1040,6 +1181,19 @@ describe("dashboard use-cases", () => {
budgetHealth: 90,
spentCents: 1_000,
budgetUtilizationPercent: 10,
derivation: expect.objectContaining({
periodStart: "2026-01-05",
periodEnd: "2026-01-06",
calendarContextCount: 1,
holidayAwareAssignmentCount: 1,
fallbackAssignmentCount: 0,
baseSpentCents: 2_000,
adjustedSpentCents: 1_000,
publicHolidayDayEquivalent: 1,
publicHolidayCostDeductionCents: 1_000,
absenceDayEquivalent: 0,
absenceCostDeductionCents: 0,
}),
calendarLocations: [
expect.objectContaining({
countryCode: "DE",