Changelog - 2026-11-04
RepositoryDouble gives a repository double the real runInTransaction
New FeatureIn one line. RepositoryDouble.withTransactions({ repository, transaction, source }) from @venizia/ignis/testing gives a hand-made repository double the repository's own runInTransaction, so a service that opens a transaction runs in a unit test with no database.
What changed
- One helper. It installs
runInTransactionand the two private helpers it calls (rollbackOwnedTransaction,resolveEndedByExecute) from the prototype ofsource, a repository class you pass (DefaultCRUDRepository), and setsbeginTransactionto return thetransactionyou pass. Nothing is reimplemented, so the double commits, rolls back and joins as a repository does. - No driver at import.
sourceis passed in, so the testing entry imports no repository code and loads without the database driver, like the transaction doubles. - No casts. Reaching the private helpers needed a cast in every test suite that copied them. The helper reads them for you.
- A logger.
runInTransactionlogs when it joins a transaction with options and when a rollback fails. The helper gives the double a logger; passloggerto use your own. It overwrites anyrunInTransaction,beginTransactionorloggerthe double already had.
Who is affected
- Tests that copy
runInTransactiononto a repository double. Replace the copy with the helper. - Everyone else. No action needed. Nothing in production code changes.
Details
typescript
import { DefaultCRUDRepository } from '@venizia/ignis-connectors/postgres';
import { PostgresTransactionDouble, RepositoryDouble } from '@venizia/ignis/testing';
const transaction = new PostgresTransactionDouble();
const create = mock(async (opts: { data: { name: string } }) => opts.data);
const repository = RepositoryDouble.withTransactions({
repository: { create },
transaction,
source: DefaultCRUDRepository,
});
await repository.runInTransaction({
execute: ({ transaction: owned }) => repository.create({ data: { name: 'a' }, options: { transaction: owned } }),
});
transaction.commitCount; // 1Pass a fresh transaction double per test: a handle that has ended stays ended.