import { describe, expect, it } from "vitest"; import { buildIngestRequest, ingestTable } from "./ingest"; describe("ingestTable", () => { it("maps ingestable kinds to their target table", () => { expect(ingestTable("GoldenFingerResult")).toBe("world_entities"); expect(ingestTable("GlossaryResult")).toBe("world_entities"); expect(ingestTable("DetailedOutlineResult")).toBe("outline"); }); it("returns null for non-ingestable kinds", () => { expect(ingestTable("IdeaListResult")).toBeNull(); expect(ingestTable("unknown")).toBeNull(); }); }); describe("buildIngestRequest", () => { it("maps golden finger rows into world_entities with merged rules", () => { const body = buildIngestRequest({ outputKind: "GoldenFingerResult", rows: [ { name: "吞噬系统", mechanism: "吞噬获取", growth: "等级提升", limits: "需进食" }, ], acknowledgeConflicts: true, }); expect(body).toEqual({ world_entities: [ { type: "力量体系", name: "吞噬系统", rules: ["吞噬获取", "等级提升", "需进食"], }, ], acknowledge_conflicts: true, }); }); it("drops blank rule parts for golden finger", () => { const body = buildIngestRequest({ outputKind: "GoldenFingerResult", rows: [{ name: "x", mechanism: "m", growth: "", limits: "" }], }); expect(body?.world_entities?.[0]?.rules).toEqual(["m"]); }); it("maps glossary rows preserving type and rules array", () => { const body = buildIngestRequest({ outputKind: "GlossaryResult", rows: [{ name: "灵气", type: "概念", rules: ["不可逆"] }], }); expect(body?.world_entities?.[0]).toEqual({ type: "概念", name: "灵气", rules: ["不可逆"], }); }); it("defaults glossary type to 概念 when missing", () => { const body = buildIngestRequest({ outputKind: "GlossaryResult", rows: [{ name: "灵气" }], }); expect(body?.world_entities?.[0]?.type).toBe("概念"); }); it("maps detailed outline rows to scenes with chapter_no", () => { const body = buildIngestRequest({ outputKind: "DetailedOutlineResult", rows: [ { idx: 2, beat: "对峙", purpose: "立威", conflict: "正反", hook: "悬念" }, { beat: "收束" }, ], chapterNo: 7, }); expect(body?.chapter_no).toBe(7); expect(body?.scenes).toEqual([ { idx: 2, beat: "对峙", purpose: "立威", conflict: "正反", hook: "悬念" }, { idx: 1, beat: "收束", purpose: "", conflict: "", hook: "" }, ]); expect(body?.acknowledge_conflicts).toBe(false); }); it("returns null for non-ingestable output kind", () => { expect( buildIngestRequest({ outputKind: "IdeaListResult", rows: [] }), ).toBeNull(); }); });