forked from jappel/leistungsbilanz-ts
Harden Linear XLSX end to end
This commit is contained in:
parent
2581beee3c
commit
4ff01b2ccd
26 changed files with 522 additions and 246 deletions
20
tests/batched-insert.persistence.test.ts
Normal file
20
tests/batched-insert.persistence.test.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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)));
|
||||
assert.equal(context.db.select().from(projects).all().length, 0);
|
||||
} finally { context.close(); }
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue