All files / src/test-support fakeTxDb.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                        20x 19x      
/**
 * Minimal stand-in for the `Database` handle in ROUTE/SERVICE unit tests that
 * exercise a `withTransaction(db, cb)` path. Its `.transaction(cb)` invokes the
 * callback with another `fakeTxDb()` as the "tx", so the materialization body
 * runs. Tests that mock the repo constructors (`vi.mock(... SortResultRepository
 * => mockRepo)`) get their mock repos for `new SortResultRepository(tx)`
 * regardless of the tx value, so the writes land on the mocks.
 *
 * This is NOT an atomicity proof — rollback is proven un-mocked against a real
 * DB in src/lib/db/sort-pipeline.integration.test.ts.
 */
export function fakeTxDb(): { transaction: (cb: (tx: unknown) => unknown) => unknown } {
  return {
    transaction: (cb: (tx: unknown) => unknown) => cb(fakeTxDb()),
  };
}