mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +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.
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { Users } from '../../../src/db/entities/Users.entity';
|
|
import { createSnapshotTestDb } from '../../helpers/db-mock';
|
|
import { createUser } from '../../helpers/factories';
|
|
import { resetTestDb } from '../../helpers/test-db';
|
|
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
|
|
|
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
const testDb = createSnapshotTestDb();
|
|
let t: TestOrm;
|
|
|
|
beforeAll(async () => {
|
|
t = await createTestOrm(testDb);
|
|
});
|
|
beforeEach(() => {
|
|
resetTestDb(testDb);
|
|
t.clear();
|
|
});
|
|
afterAll(async () => {
|
|
await t.close();
|
|
testDb.close();
|
|
});
|
|
|
|
describe('createTestOrm', () => {
|
|
it('ORM-001: reads through the very handle it was given', async () => {
|
|
const { user } = createUser(testDb, { username: 'alice' });
|
|
const found = await t.repo(Users).findOne({ id: user.id });
|
|
expect(found?.username).toBe('alice');
|
|
});
|
|
|
|
it('ORM-002: clear() drops the identity map so a raw update is visible', async () => {
|
|
const { user } = createUser(testDb, { username: 'bob' });
|
|
await t.repo(Users).findOne({ id: user.id });
|
|
testDb.prepare('UPDATE users SET username = ? WHERE id = ?').run('robert', user.id);
|
|
t.clear();
|
|
const again = await t.repo(Users).findOne({ id: user.id });
|
|
expect(again?.username).toBe('robert');
|
|
});
|
|
|
|
it('ORM-003: closing the ORM leaves the handle usable', async () => {
|
|
const local = await createTestOrm(testDb);
|
|
// Force a real connection first — MikroORM connects lazily, so closing an
|
|
// untouched ORM would prove nothing about NonClosingSqliteDriver.
|
|
await local.repo(Users).findOne({ id: 1 });
|
|
await local.close();
|
|
expect(testDb.prepare('SELECT 1 AS one').get()).toEqual({ one: 1 });
|
|
});
|
|
});
|