mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
feat(db): generated entities declare their repository type; test casts dropped
This commit is contained in:
@@ -5,7 +5,6 @@ import { resetTestDb } from '../../../helpers/test-db';
|
||||
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
|
||||
import { createUser } from '../../../helpers/factories';
|
||||
import { Users } from '../../../../src/db/entities/Users.entity';
|
||||
import type { UsersRepository } from '../../../../src/db/repositories/Users.repository';
|
||||
import { UnitOfWork } from '../../../../src/nest/database/unit-of-work';
|
||||
|
||||
/**
|
||||
@@ -41,10 +40,10 @@ describe('UnitOfWork transaction resolution (D5)', () => {
|
||||
let forkMatches: boolean | undefined;
|
||||
|
||||
await uow.transactional(async () => {
|
||||
const repo = t.repo(Users) as UsersRepository;
|
||||
const repo = t.repo(Users);
|
||||
globalMatches = repo.getEntityManager().getContext() === TransactionContext.getEntityManager();
|
||||
|
||||
const forkedRepo = t.orm.em.fork().getRepository(Users) as UsersRepository;
|
||||
const forkedRepo = t.orm.em.fork().getRepository(Users);
|
||||
forkMatches = forkedRepo.getEntityManager().getContext() === TransactionContext.getEntityManager();
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ let days: DaysRepository;
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
uow = new UnitOfWork(t.em);
|
||||
days = t.repo(Days) as DaysRepository;
|
||||
days = t.repo(Days);
|
||||
});
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
@@ -87,7 +87,7 @@ describe('UnitOfWork.transactional', () => {
|
||||
// A separate fork = a separate acquirer of the connection. It waits on the
|
||||
// ConnectionMutex instead of deadlocking because nothing inside the
|
||||
// transaction waits on it: the writer's own timer resolves regardless.
|
||||
const reader = t.orm.em.fork().getRepository(Days) as DaysRepository;
|
||||
const reader = t.orm.em.fork().getRepository(Days);
|
||||
const seen = await reader.listByTrip(trip.id);
|
||||
await tx;
|
||||
expect(seen).toHaveLength(1);
|
||||
|
||||
Reference in New Issue
Block a user