refactor(api): extract computation graph procedures
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
getProjectGraphData,
|
||||
getResourceGraphData,
|
||||
} from "../router/computation-graph-procedure-support.js";
|
||||
|
||||
const { readResourceGraphSnapshot, readProjectGraphSnapshot } = vi.hoisted(() => ({
|
||||
readResourceGraphSnapshot: vi.fn(),
|
||||
readProjectGraphSnapshot: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../router/computation-graph-resource.js", () => ({
|
||||
readResourceGraphSnapshot,
|
||||
}));
|
||||
|
||||
vi.mock("../router/computation-graph-project.js", () => ({
|
||||
readProjectGraphSnapshot,
|
||||
}));
|
||||
|
||||
describe("computation-graph-procedure-support", () => {
|
||||
it("delegates resource graph reads to the snapshot reader", async () => {
|
||||
const ctx = { db: {} } as never;
|
||||
const snapshot = { nodes: [], links: [], meta: { resourceEid: "eid", resourceName: "Bruce" } };
|
||||
readResourceGraphSnapshot.mockResolvedValue(snapshot);
|
||||
|
||||
const result = await getResourceGraphData(ctx, {
|
||||
resourceId: "resource_1",
|
||||
month: "2026-01",
|
||||
});
|
||||
|
||||
expect(result).toBe(snapshot);
|
||||
expect(readResourceGraphSnapshot).toHaveBeenCalledWith(ctx, {
|
||||
resourceId: "resource_1",
|
||||
month: "2026-01",
|
||||
});
|
||||
});
|
||||
|
||||
it("delegates project graph reads to the snapshot reader", async () => {
|
||||
const ctx = { db: {} } as never;
|
||||
const snapshot = { nodes: [], links: [], meta: { projectCode: "GDM", projectName: "Gelddruckmaschine" } };
|
||||
readProjectGraphSnapshot.mockResolvedValue(snapshot);
|
||||
|
||||
const result = await getProjectGraphData(ctx, {
|
||||
projectId: "project_1",
|
||||
});
|
||||
|
||||
expect(result).toBe(snapshot);
|
||||
expect(readProjectGraphSnapshot).toHaveBeenCalledWith(ctx, {
|
||||
projectId: "project_1",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user