refactor(api): extract insights procedures

This commit is contained in:
2026-03-31 20:31:55 +02:00
parent a2f9b713c1
commit af88b3528a
4 changed files with 438 additions and 205 deletions
@@ -195,4 +195,29 @@ describe("insights router", () => {
vi.useRealTimers();
}
});
it("returns the cached narrative through the controller router", async () => {
const projectFindUnique = vi.fn().mockResolvedValue({
dynamicFields: {
aiNarrative: "Cached summary",
aiNarrativeGeneratedAt: "2026-03-30T08:00:00.000Z",
},
});
const caller = createControllerCaller({
project: {
findUnique: projectFindUnique,
},
});
const result = await caller.getCachedNarrative({ projectId: "project_1" });
expect(projectFindUnique).toHaveBeenCalledWith({
where: { id: "project_1" },
select: { dynamicFields: true },
});
expect(result).toEqual({
narrative: "Cached summary",
generatedAt: "2026-03-30T08:00:00.000Z",
});
});
});