mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 13:36:48 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { Users } from '../../../src/db/entities/Users.entity';
|
|
import type { UnitOfWork } from '../../../src/nest/database/unit-of-work';
|
|
import { createSnapshotTestDb } from '../../helpers/db-mock';
|
|
import { createUser } from '../../helpers/factories';
|
|
import { countRows } from '../../helpers/factories/rows';
|
|
import { resetTestDb } from '../../helpers/test-db';
|
|
import { createTestUnitOfWork, sharedTestOrm } from '../../helpers/test-uow';
|
|
|
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
const testDb = createSnapshotTestDb();
|
|
let uow: UnitOfWork;
|
|
|
|
beforeAll(async () => {
|
|
uow = await createTestUnitOfWork(testDb);
|
|
});
|
|
beforeEach(() => resetTestDb(testDb));
|
|
afterAll(() => testDb.close());
|
|
|
|
const countUsers = async () => countRows(await sharedTestOrm(testDb), Users);
|
|
|
|
describe('createTestUnitOfWork', () => {
|
|
it('TUOW-001: raw better-sqlite3 statements inside transactional() commit together', async () => {
|
|
await uow.transactional(async () => {
|
|
createUser(testDb);
|
|
createUser(testDb);
|
|
});
|
|
expect(await countUsers()).toBe(2);
|
|
});
|
|
|
|
it('TUOW-002: a throw rolls raw statements back', async () => {
|
|
await expect(
|
|
uow.transactional(async () => {
|
|
createUser(testDb);
|
|
throw new Error('boom');
|
|
}),
|
|
).rejects.toThrow('boom');
|
|
expect(await countUsers()).toBe(0);
|
|
});
|
|
|
|
it('TUOW-003: the helper is memoised per handle', async () => {
|
|
const again = await createTestUnitOfWork(testDb);
|
|
expect(again).toBe(uow);
|
|
});
|
|
});
|