import { describe, expect, it, vi } from "vitest"; import type { PrismaClient } from "./client.js"; import { createProjectGoalRepos, mapProjectGoal } from "./project-goals.js"; describe("project goals", () => { it("maps rows to contract shape", () => { const mapped = mapProjectGoal({ id: "goal_1", sectionId: "sec_1", groupId: "grp_1", title: "Voice First", description: "Test", status: "doing", createdAt: new Date("2026-01-01T00:00:00.000Z"), updatedAt: new Date("2026-01-02T00:00:00.000Z"), }); expect(mapped).toEqual({ id: "goal_1", sectionId: "sec_1", groupId: "grp_1", title: "Voice First", description: "Test", status: "doing", createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-02T00:00:00.000Z", }); }); it("seeds Voice First for evOo sections on list", async () => { const findFirstSection = vi .fn() .mockResolvedValueOnce({ id: "sec_evoo", name: "evOo" }) .mockResolvedValueOnce({ id: "sec_evoo", name: "evOo" }); const findFirstGoal = vi.fn().mockResolvedValue(null); const createGoal = vi.fn().mockResolvedValue({ id: "goal_voice", sectionId: "sec_evoo", groupId: "grp_1", title: "Voice First", description: "Voice-first Interaktion als primäre evOo-Erfahrung — sprechen statt tippen, wo es passt.", status: "open", createdAt: new Date("2026-01-01T00:00:00.000Z"), updatedAt: new Date("2026-01-01T00:00:00.000Z"), }); const findMany = vi.fn().mockResolvedValue([ { id: "goal_voice", sectionId: "sec_evoo", groupId: "grp_1", title: "Voice First", description: "Voice-first Interaktion als primäre evOo-Erfahrung — sprechen statt tippen, wo es passt.", status: "open", createdAt: new Date("2026-01-01T00:00:00.000Z"), updatedAt: new Date("2026-01-01T00:00:00.000Z"), }, ]); const findGroup = vi.fn().mockResolvedValue({ id: "grp_1" }); const prisma = { botSection: { findFirst: findFirstSection }, projectGoal: { findFirst: findFirstGoal, create: createGoal, findMany }, chatGroup: { findFirst: findGroup }, } as unknown as PrismaClient; const repos = createProjectGoalRepos(prisma); const actor = { spaceId: "space_1", userId: "user_1", email: "user@example.test", isDeploymentOwner: false, }; const goals = await repos.listGoals(actor, { sectionId: "sec_evoo", groupId: "grp_1", seedDefaults: true, }); expect(createGoal).toHaveBeenCalledOnce(); expect(goals[0]?.title).toBe("Voice First"); }); });