refactor(api): extract timeline entry read builders
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildTimelineEntriesDetailInput,
|
||||
buildTimelineEntriesDetailResponse,
|
||||
buildTimelineEntriesViewResponse,
|
||||
} from "../router/timeline-read-shared.js";
|
||||
|
||||
describe("timeline read shared", () => {
|
||||
const directory = {
|
||||
config: { enabled: true, mode: "alias", domain: "example.test" },
|
||||
byResourceId: new Map([
|
||||
[
|
||||
"resource_1",
|
||||
{
|
||||
displayName: "Anon Alice",
|
||||
eid: "ANON-001",
|
||||
email: "anon-alice@example.test",
|
||||
},
|
||||
],
|
||||
]),
|
||||
byAliasEid: new Map([["anon-001", "resource_1"]]),
|
||||
};
|
||||
|
||||
it("builds anonymized entries view responses", () => {
|
||||
const readModel = {
|
||||
allocations: [
|
||||
{
|
||||
id: "allocation_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001" },
|
||||
},
|
||||
],
|
||||
demands: [{ id: "demand_1", projectId: "project_1" }],
|
||||
assignments: [
|
||||
{
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(buildTimelineEntriesViewResponse(readModel, directory as never)).toEqual({
|
||||
allocations: [
|
||||
{
|
||||
id: "allocation_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Anon Alice", eid: "ANON-001" },
|
||||
},
|
||||
],
|
||||
demands: [{ id: "demand_1", projectId: "project_1" }],
|
||||
assignments: [
|
||||
{
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Anon Alice", eid: "ANON-001" },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("builds detail input from period and normalized filters", () => {
|
||||
expect(
|
||||
buildTimelineEntriesDetailInput({
|
||||
startDate: "2026-04-01",
|
||||
durationDays: 3,
|
||||
resourceIds: [" resource_1 ", ""],
|
||||
projectIds: ["project_1"],
|
||||
chapters: [" Compositing "],
|
||||
}),
|
||||
).toEqual({
|
||||
period: {
|
||||
startDate: new Date("2026-04-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-04-03T00:00:00.000Z"),
|
||||
},
|
||||
filters: {
|
||||
resourceIds: ["resource_1"],
|
||||
projectIds: ["project_1"],
|
||||
clientIds: undefined,
|
||||
chapters: ["Compositing"],
|
||||
eids: undefined,
|
||||
countryCodes: undefined,
|
||||
},
|
||||
timelineInput: {
|
||||
startDate: new Date("2026-04-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-04-03T00:00:00.000Z"),
|
||||
resourceIds: ["resource_1"],
|
||||
projectIds: ["project_1"],
|
||||
clientIds: undefined,
|
||||
chapters: ["Compositing"],
|
||||
eids: undefined,
|
||||
countryCodes: undefined,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds detail responses with combined summary and anonymized entries", () => {
|
||||
const readModel = {
|
||||
allocations: [
|
||||
{
|
||||
id: "allocation_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001" },
|
||||
},
|
||||
],
|
||||
demands: [{ id: "demand_1", projectId: "project_1" }],
|
||||
assignments: [
|
||||
{
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Alice", eid: "E-001" },
|
||||
},
|
||||
],
|
||||
};
|
||||
const overlays = [{ id: "overlay_1", resourceId: "resource_1" }];
|
||||
|
||||
expect(
|
||||
buildTimelineEntriesDetailResponse({
|
||||
period: {
|
||||
startDate: new Date("2026-04-01T00:00:00.000Z"),
|
||||
endDate: new Date("2026-04-05T00:00:00.000Z"),
|
||||
},
|
||||
filters: {
|
||||
resourceIds: ["resource_1"],
|
||||
projectIds: undefined,
|
||||
clientIds: undefined,
|
||||
chapters: undefined,
|
||||
eids: undefined,
|
||||
countryCodes: undefined,
|
||||
},
|
||||
readModel,
|
||||
directory: directory as never,
|
||||
holidayOverlays: overlays,
|
||||
holidaySummary: {
|
||||
overlayCount: 1,
|
||||
holidayResourceCount: 1,
|
||||
byScope: [{ scope: "COUNTRY", count: 1 }],
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
period: {
|
||||
startDate: "2026-04-01",
|
||||
endDate: "2026-04-05",
|
||||
},
|
||||
filters: {
|
||||
resourceIds: ["resource_1"],
|
||||
projectIds: undefined,
|
||||
clientIds: undefined,
|
||||
chapters: undefined,
|
||||
eids: undefined,
|
||||
countryCodes: undefined,
|
||||
},
|
||||
summary: {
|
||||
allocationCount: 1,
|
||||
demandCount: 1,
|
||||
assignmentCount: 1,
|
||||
projectCount: 1,
|
||||
resourceCount: 1,
|
||||
overlayCount: 1,
|
||||
holidayResourceCount: 1,
|
||||
byScope: [{ scope: "COUNTRY", count: 1 }],
|
||||
},
|
||||
allocations: [
|
||||
{
|
||||
id: "allocation_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Anon Alice", eid: "ANON-001" },
|
||||
},
|
||||
],
|
||||
demands: [{ id: "demand_1", projectId: "project_1" }],
|
||||
assignments: [
|
||||
{
|
||||
id: "assignment_1",
|
||||
projectId: "project_1",
|
||||
resourceId: "resource_1",
|
||||
resource: { id: "resource_1", displayName: "Anon Alice", eid: "ANON-001" },
|
||||
},
|
||||
],
|
||||
holidayOverlays: overlays,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user