feat(api): explain dashboard chargeability by chapter
This commit is contained in:
@@ -4,6 +4,7 @@ import { SystemRole } from "@capakraken/shared";
|
||||
import {
|
||||
createToolContext,
|
||||
executeTool,
|
||||
getDashboardChargeabilityOverview,
|
||||
getDashboardDemand,
|
||||
getDashboardOverview,
|
||||
getDashboardPeakTimes,
|
||||
@@ -139,6 +140,38 @@ describe("assistant dashboard tools detail aggregation", () => {
|
||||
},
|
||||
},
|
||||
]);
|
||||
vi.mocked(getDashboardChargeabilityOverview).mockResolvedValue({
|
||||
rows: [
|
||||
{
|
||||
id: "res_1",
|
||||
eid: "pparker",
|
||||
displayName: "Peter Parker",
|
||||
chapter: "Delivery",
|
||||
chargeabilityTarget: 78,
|
||||
actualChargeability: 70,
|
||||
expectedChargeability: 76,
|
||||
derivation: {
|
||||
weeklyAvailabilityHours: 40,
|
||||
baseWorkingDays: 22,
|
||||
effectiveWorkingDayEquivalent: 21,
|
||||
baseAvailableHours: 176,
|
||||
effectiveAvailableHours: 168,
|
||||
publicHolidayCount: 1,
|
||||
publicHolidayWorkdayCount: 1,
|
||||
publicHolidayHoursDeduction: 8,
|
||||
absenceDayEquivalent: 0,
|
||||
absenceHoursDeduction: 0,
|
||||
actualBookedHours: 117.6,
|
||||
expectedBookedHours: 127.7,
|
||||
targetBookedHours: 131,
|
||||
unassignedHours: 40.3,
|
||||
},
|
||||
},
|
||||
],
|
||||
top: [],
|
||||
watchlist: [],
|
||||
month: "2026-03",
|
||||
});
|
||||
|
||||
const ctx = createToolContext(
|
||||
{
|
||||
@@ -263,8 +296,28 @@ describe("assistant dashboard tools detail aggregation", () => {
|
||||
chargeabilityByChapter: [
|
||||
{
|
||||
chapter: "Delivery",
|
||||
headcount: 4,
|
||||
headcount: 1,
|
||||
avgTargetPct: 78,
|
||||
avgActualPct: 70,
|
||||
avgExpectedPct: 76,
|
||||
gapToTargetPct: 8,
|
||||
avgTarget: "78%",
|
||||
avgActual: "70%",
|
||||
avgExpected: "76%",
|
||||
explainability: {
|
||||
month: "2026-03",
|
||||
resourceCount: 1,
|
||||
derivedHeadcount: 1,
|
||||
baseAvailableHours: 176,
|
||||
effectiveAvailableHours: 168,
|
||||
actualBookedHours: 117.6,
|
||||
expectedBookedHours: 127.7,
|
||||
targetBookedHours: 131,
|
||||
publicHolidayHoursDeduction: 8,
|
||||
absenceDayEquivalent: 0,
|
||||
absenceHoursDeduction: 0,
|
||||
unassignedHours: 40.3,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { PermissionKey, SystemRole } from "@capakraken/shared";
|
||||
import { vi } from "vitest";
|
||||
|
||||
vi.mock("@capakraken/application", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@capakraken/application")>();
|
||||
return {
|
||||
...actual,
|
||||
getDashboardDemand: vi.fn().mockResolvedValue([]),
|
||||
getDashboardBudgetForecast: vi.fn().mockResolvedValue([]),
|
||||
getDashboardChargeabilityOverview: vi.fn().mockResolvedValue({
|
||||
rows: [],
|
||||
top: [],
|
||||
watchlist: [],
|
||||
month: "2026-03",
|
||||
}),
|
||||
getDashboardOverview: vi.fn(),
|
||||
getDashboardSkillGapSummary: vi.fn().mockResolvedValue({
|
||||
roleGaps: [],
|
||||
totalOpenPositions: 0,
|
||||
skillSupplyTop10: [],
|
||||
resourcesByRole: [],
|
||||
}),
|
||||
getDashboardProjectHealth: vi.fn().mockResolvedValue([]),
|
||||
getDashboardPeakTimes: vi.fn().mockResolvedValue([]),
|
||||
getDashboardTopValueResources: vi.fn().mockResolvedValue([]),
|
||||
listAssignmentBookings: vi.fn().mockResolvedValue([]),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../lib/cache.js", () => ({
|
||||
cacheGet: vi.fn().mockResolvedValue(null),
|
||||
cacheSet: vi.fn().mockResolvedValue(undefined),
|
||||
cacheInvalidate: vi.fn().mockResolvedValue(undefined),
|
||||
invalidateDashboardCache: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
import {
|
||||
getDashboardChargeabilityOverview as getDashboardChargeabilityOverviewMock,
|
||||
getDashboardDemand as getDashboardDemandMock,
|
||||
getDashboardOverview as getDashboardOverviewMock,
|
||||
getDashboardProjectHealth as getDashboardProjectHealthMock,
|
||||
getDashboardPeakTimes as getDashboardPeakTimesMock,
|
||||
getDashboardSkillGapSummary as getDashboardSkillGapSummaryMock,
|
||||
getDashboardTopValueResources as getDashboardTopValueResourcesMock,
|
||||
} from "@capakraken/application";
|
||||
import { executeTool as executeAssistantTool, type ToolContext } from "../router/assistant-tools.js";
|
||||
|
||||
export const executeTool = executeAssistantTool;
|
||||
export const getDashboardChargeabilityOverview = getDashboardChargeabilityOverviewMock;
|
||||
export const getDashboardDemand = getDashboardDemandMock;
|
||||
export const getDashboardOverview = getDashboardOverviewMock;
|
||||
export const getDashboardProjectHealth = getDashboardProjectHealthMock;
|
||||
export const getDashboardPeakTimes = getDashboardPeakTimesMock;
|
||||
export const getDashboardSkillGapSummary = getDashboardSkillGapSummaryMock;
|
||||
export const getDashboardTopValueResources = getDashboardTopValueResourcesMock;
|
||||
|
||||
export function createToolContext(
|
||||
db: Record<string, unknown>,
|
||||
options?: {
|
||||
permissions?: PermissionKey[];
|
||||
userRole?: SystemRole;
|
||||
},
|
||||
): ToolContext {
|
||||
const userRole = options?.userRole ?? SystemRole.ADMIN;
|
||||
return {
|
||||
db: db as ToolContext["db"],
|
||||
userId: "user_1",
|
||||
userRole,
|
||||
permissions: new Set(options?.permissions ?? []),
|
||||
session: {
|
||||
user: { email: "assistant@example.com", name: "Assistant User", image: null },
|
||||
expires: "2026-03-29T00:00:00.000Z",
|
||||
},
|
||||
dbUser: {
|
||||
id: "user_1",
|
||||
systemRole: userRole,
|
||||
permissionOverrides: null,
|
||||
},
|
||||
roleDefaults: null,
|
||||
};
|
||||
}
|
||||
@@ -225,6 +225,38 @@ describe("dashboard procedure support", () => {
|
||||
},
|
||||
},
|
||||
]);
|
||||
vi.mocked(getDashboardChargeabilityOverview).mockResolvedValue({
|
||||
rows: [
|
||||
{
|
||||
id: "res_1",
|
||||
eid: "E-001",
|
||||
displayName: "Ada Lovelace",
|
||||
chapter: "CGI",
|
||||
chargeabilityTarget: 78,
|
||||
actualChargeability: 64,
|
||||
expectedChargeability: 72,
|
||||
derivation: {
|
||||
weeklyAvailabilityHours: 40,
|
||||
baseWorkingDays: 23,
|
||||
effectiveWorkingDayEquivalent: 21,
|
||||
baseAvailableHours: 184,
|
||||
effectiveAvailableHours: 168,
|
||||
publicHolidayCount: 1,
|
||||
publicHolidayWorkdayCount: 1,
|
||||
publicHolidayHoursDeduction: 8,
|
||||
absenceDayEquivalent: 1,
|
||||
absenceHoursDeduction: 8,
|
||||
actualBookedHours: 107.5,
|
||||
expectedBookedHours: 121,
|
||||
targetBookedHours: 131,
|
||||
unassignedHours: 47,
|
||||
},
|
||||
},
|
||||
],
|
||||
top: [],
|
||||
watchlist: [],
|
||||
month: "2026-03",
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await getDashboardDetail(createContext(), { section: "all" });
|
||||
@@ -298,11 +330,40 @@ describe("dashboard procedure support", () => {
|
||||
chargeabilityByChapter: [
|
||||
{
|
||||
chapter: "CGI",
|
||||
headcount: 5,
|
||||
headcount: 1,
|
||||
avgTargetPct: 78,
|
||||
avgActualPct: 64,
|
||||
avgExpectedPct: 72,
|
||||
gapToTargetPct: 14,
|
||||
avgTarget: "78%",
|
||||
avgActual: "64%",
|
||||
avgExpected: "72%",
|
||||
explainability: {
|
||||
month: "2026-03",
|
||||
resourceCount: 1,
|
||||
derivedHeadcount: 1,
|
||||
baseAvailableHours: 184,
|
||||
effectiveAvailableHours: 168,
|
||||
actualBookedHours: 107.5,
|
||||
expectedBookedHours: 121,
|
||||
targetBookedHours: 131,
|
||||
publicHolidayHoursDeduction: 8,
|
||||
absenceDayEquivalent: 1,
|
||||
absenceHoursDeduction: 8,
|
||||
unassignedHours: 47,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(getDashboardChargeabilityOverview).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({
|
||||
includeProposed: false,
|
||||
topN: 10,
|
||||
watchlistThreshold: 15,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
@@ -838,6 +838,38 @@ describe("dashboard router", () => {
|
||||
},
|
||||
},
|
||||
]);
|
||||
vi.mocked(getDashboardChargeabilityOverview).mockResolvedValue({
|
||||
rows: [
|
||||
{
|
||||
id: "res_1",
|
||||
eid: "pparker",
|
||||
displayName: "Peter Parker",
|
||||
chapter: "Delivery",
|
||||
chargeabilityTarget: 78,
|
||||
actualChargeability: 70,
|
||||
expectedChargeability: 76,
|
||||
derivation: {
|
||||
weeklyAvailabilityHours: 40,
|
||||
baseWorkingDays: 22,
|
||||
effectiveWorkingDayEquivalent: 21,
|
||||
baseAvailableHours: 176,
|
||||
effectiveAvailableHours: 168,
|
||||
publicHolidayCount: 1,
|
||||
publicHolidayWorkdayCount: 1,
|
||||
publicHolidayHoursDeduction: 8,
|
||||
absenceDayEquivalent: 0,
|
||||
absenceHoursDeduction: 0,
|
||||
actualBookedHours: 117.6,
|
||||
expectedBookedHours: 127.7,
|
||||
targetBookedHours: 131,
|
||||
unassignedHours: 40.3,
|
||||
},
|
||||
},
|
||||
],
|
||||
top: [],
|
||||
watchlist: [],
|
||||
month: "2026-03",
|
||||
});
|
||||
|
||||
const caller = createControllerCaller({});
|
||||
const result = await caller.getDetail({ section: "all" });
|
||||
@@ -929,8 +961,28 @@ describe("dashboard router", () => {
|
||||
chargeabilityByChapter: [
|
||||
{
|
||||
chapter: "Delivery",
|
||||
headcount: 4,
|
||||
headcount: 1,
|
||||
avgTargetPct: 78,
|
||||
avgActualPct: 70,
|
||||
avgExpectedPct: 76,
|
||||
gapToTargetPct: 8,
|
||||
avgTarget: "78%",
|
||||
avgActual: "70%",
|
||||
avgExpected: "76%",
|
||||
explainability: {
|
||||
month: "2026-03",
|
||||
resourceCount: 1,
|
||||
derivedHeadcount: 1,
|
||||
baseAvailableHours: 176,
|
||||
effectiveAvailableHours: 168,
|
||||
actualBookedHours: 117.6,
|
||||
expectedBookedHours: 127.7,
|
||||
targetBookedHours: 131,
|
||||
publicHolidayHoursDeduction: 8,
|
||||
absenceDayEquivalent: 0,
|
||||
absenceHoursDeduction: 0,
|
||||
unassignedHours: 40.3,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -943,6 +995,14 @@ describe("dashboard router", () => {
|
||||
groupBy: "project",
|
||||
}),
|
||||
);
|
||||
expect(getDashboardChargeabilityOverview).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({
|
||||
includeProposed: false,
|
||||
topN: 10,
|
||||
watchlistThreshold: 15,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user