mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
fix(db): PK reads refresh past the identity map; typed owned-lookup generics; e2e ORM module mirrors production config
This commit is contained in:
@@ -5,6 +5,7 @@ import type { DynamicModule } from '@nestjs/common';
|
||||
import type Database from 'better-sqlite3';
|
||||
import { ALL_ENTITIES } from '../../src/db/entities';
|
||||
import { createBoundSqliteDriver } from '../../src/db/orm-driver';
|
||||
import mikroOrmConfig from '../../src/mikro-orm.config';
|
||||
|
||||
export interface TestOrm {
|
||||
orm: MikroORM;
|
||||
@@ -83,9 +84,30 @@ export async function createTestOrm(
|
||||
* `createNestApplication()`, so `registerRequestContext` (the NestJS
|
||||
* integration's default) forks a context-resolving EntityManager per request
|
||||
* the same way `buildApp()` does — no test-only global context needed here.
|
||||
*
|
||||
* Built from `src/mikro-orm.config.ts` (spread, then overridden only on
|
||||
* `driver`/`dbName`/`discovery`) rather than a hand-rolled options object, so
|
||||
* this stays in lockstep with production instead of being a second copy of
|
||||
* the config that can silently drift.
|
||||
*
|
||||
* UPLOADS-P16 (Phase 1 ledger, entries 102–103): `registerRequestContext` is
|
||||
* left at its NestJS-integration default here — the `@mikro-orm/nestjs` auto
|
||||
* middleware that provides it is *also* the confirmed root cause of
|
||||
* UPLOADS-P16 (its Nest-11 wildcard route throws on a malformed `%`-encoded
|
||||
* upload path before any TREK handler runs). That coupling is faithful to
|
||||
* production as production is broken right now, not a weakened test — but
|
||||
* the recommended fix for UPLOADS-P16 (`registerRequestContext: false` on
|
||||
* `MikroOrmModule.forRoot`, paired with our own keyless `RequestContext.create`
|
||||
* middleware, since D6 needs the per-request EM fork this default provides)
|
||||
* changes what `buildApp()` registers. Building this helper from the same
|
||||
* `mikroOrmConfig` object production uses means that fix reaches both at
|
||||
* once; if it is ever done as a hand-edit instead, this helper's 15 e2e
|
||||
* harnesses would silently stop mirroring production and need the same
|
||||
* `allowGlobalContext`-style re-justification `createTestOrm` above got.
|
||||
*/
|
||||
export function createTestMikroOrmModule(db: Database.Database): DynamicModule | Promise<DynamicModule> {
|
||||
return MikroOrmModule.forRoot({
|
||||
...mikroOrmConfig,
|
||||
entities: [...ALL_ENTITIES],
|
||||
driver: createBoundSqliteDriver(() => db),
|
||||
dbName: ':memory:',
|
||||
|
||||
Reference in New Issue
Block a user