import path from "node:path"; import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { migrate } from "drizzle-orm/better-sqlite3/migrator"; import { createDatabaseContext } from "../src/db/database-context.js"; import { ExternalExportBatchRepository } from "../src/db/repositories/external-export-batch.repository.js"; import { projects } from "../src/db/schema/projects.js"; import { createDefaultExternalModelConfiguration } from "../src/external-model/configuration/external-model-configuration.js"; describe("external export batch repository", () => { it("appends immutable audit metadata without changing the project revision", () => { const context = createDatabaseContext(":memory:"); try { migrate(context.db, { migrationsFolder: path.resolve("src", "db", "migrations") }); context.db.insert(projects).values({ id: "project-1", name: "Projekt", currentRevision: 7 }).run(); const repository = new ExternalExportBatchRepository(context.db); const configuration = createDefaultExternalModelConfiguration(); repository.append({ id: "export-1", projectId: "project-1", projectRevision: 7, importBatchId: "historical-import-without-foreign-key", exportedAtIso: "2026-09-30T10:00:00.000Z", fileName: "Projekt_Revit-Rueckgabe_2026-09-30.xlsx", sha256: "a".repeat(64), configurationSnapshot: configuration, configurationSha256: "b".repeat(64), scope: "all", objectCount: 4, }); configuration.columns.designation = "Nachträglich geändert"; repository.append({ id: "export-2", projectId: "project-1", projectRevision: 7, importBatchId: "historical-import-without-foreign-key", exportedAtIso: "2026-09-30T11:00:00.000Z", fileName: "Projekt_Revit-Rueckgabe_2026-09-30.xlsx", sha256: "c".repeat(64), configurationSnapshot: configuration, configurationSha256: "d".repeat(64), scope: "selected", objectCount: 1, }); const batches = repository.listByProject("project-1"); assert.deepEqual(batches.map((batch) => batch.id), ["export-2", "export-1"]); assert.notEqual(batches[0]!.configurationSnapshot.columns.designation, batches[1]!.configurationSnapshot.columns.designation); assert.equal(context.db.select({ revision: projects.currentRevision }).from(projects).get()!.revision, 7); } finally { context.close(); } }); });