import { describe, expect, it } from "vitest"; import { INTEGRATION_CATALOG } from "./catalog.js"; import { buildAppUpsertData, buildCatalogSeedPlan } from "./catalog-seed.js"; // R-P5 — the catalog seed plan mirrors INTEGRATION_CATALOG 1:1 and stays // idempotent by unique key (deferred App-table seed, now shipped). describe("buildCatalogSeedPlan", () => { it("produces one upsert payload per catalog entry, keyed uniquely", () => { const plan = buildCatalogSeedPlan(); expect(plan).toHaveLength(INTEGRATION_CATALOG.length); expect(new Set(plan.map((entry) => entry.key)).size).toBe(plan.length); }); it("maps catalog fields onto the App columns (title carries the i18n key)", () => { const sample = INTEGRATION_CATALOG.find((entry) => entry.key === "sample-data-sync")!; const data = buildAppUpsertData(sample); expect(data).toMatchObject({ key: "sample-data-sync", title: "integrations.app.sampleDataSync.title", category: "erp", connectionType: "rest_api", phase: "P5", icon: null, isActive: true, }); expect(data.connectionSchema.fields.map((field) => field.name)).toEqual(["baseUrl", "apiKey"]); }); it("keeps oauth2 apps with empty credential forms seedable", () => { const gmail = buildCatalogSeedPlan().find((entry) => entry.key === "gmail")!; expect(gmail.connectionType).toBe("oauth2"); expect(gmail.connectionSchema.fields).toEqual([]); }); });