leistungsbilanz-ts/tests/batched-insert.persistence.test.ts
Julian Appel a8cc7eca5e Tighten rejection tests to their expected errors
Every assert.throws now names the error it expects, so a broken fixture
or an unrelated failure can no longer satisfy a rejection test. Zod
rejections are matched by issue path and code via tests/support/zod-assertions.ts.

Restore snapshot coverage lost with the release baseline: invalid board
floor, room floor and circuit section references and a reserve state
that contradicts the device rows are rejected again under test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 12:27:46 +01:00

23 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict";
import path from "node:path";
import { describe, it } from "node:test";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import { createDatabaseContext } from "../src/db/database-context.js";
import { insertManyInBatches } from "../src/db/repositories/batched-insert.persistence.js";
import { projects } from "../src/db/schema/projects.js";
describe("batched SQLite inserts", () => {
it("keeps every batch inside the caller transaction", () => {
const context = createDatabaseContext(":memory:");
try {
migrate(context.db, { migrationsFolder: path.resolve("src", "db", "migrations") });
const values = Array.from({ length: 401 }, (_, index) => ({ id: `project-${index}`, name: `Projekt ${index}` }));
values[400] = { id: "project-0", name: "Duplikat" };
assert.throws(
() => context.db.transaction((tx) => insertManyInBatches(tx, projects, values)),
/UNIQUE constraint failed: projects\.id/
);
assert.equal(context.db.select().from(projects).all().length, 0);
} finally { context.close(); }
});
});