Files
TREK/server/tests/helpers/dawarich-repos.ts
T
Maurice 724c88c201 style: format server and shared with prettier
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.
2026-10-10 21:23:37 +02:00

44 lines
2.4 KiB
TypeScript

import { DawarichConnections } from '../../src/db/entities/DawarichConnections.entity';
import { DawarichVisitSuggestions } from '../../src/db/entities/DawarichVisitSuggestions.entity';
import type { DawarichConnectionsRepository } from '../../src/db/repositories/DawarichConnections.repository';
import type { DawarichVisitSuggestionsRepository } from '../../src/db/repositories/DawarichVisitSuggestions.repository';
import { sharedTestOrm } from './test-uow';
import type Database from 'better-sqlite3';
/**
* Plan 3h Task 3 (dawarich connection/credentials, sync/reconcile, review
* flow) — the two repositories this domain's own tables need, for a
* hand-constructed `DawarichService`/`DawarichSuggestionsService`/
* `DawarichSyncService`. Same memoisation-per-handle pattern every helper in
* `test-uow.ts` uses: one ORM per test file's better-sqlite3 handle, shared
* with whatever `UnitOfWork`/other repository that same file also builds —
* `sharedTestOrm` (not a second `createTestOrm` call) is what keeps a
* repository built here and a `UnitOfWork` built via `createTestUnitOfWork`
* resolving the SAME context-forking `EntityManager`, so a write inside
* `uow.transactional(...)` through either one is actually inside the open
* transaction.
*/
const connectionsPerHandle = new WeakMap<Database.Database, Promise<DawarichConnectionsRepository>>();
const suggestionsPerHandle = new WeakMap<Database.Database, Promise<DawarichVisitSuggestionsRepository>>();
/** The `DawarichConnectionsRepository` a hand-constructed `DawarichService`/`DawarichSyncService` needs. */
export function createTestDawarichConnectionsRepo(db: Database.Database): Promise<DawarichConnectionsRepository> {
const existing = connectionsPerHandle.get(db);
if (existing !== undefined) return existing;
const pending = sharedTestOrm(db).then((t) => t.repo(DawarichConnections));
connectionsPerHandle.set(db, pending);
return pending;
}
/** The `DawarichVisitSuggestionsRepository` a hand-constructed `DawarichSuggestionsService`/`DawarichSyncService` needs. */
export function createTestDawarichVisitSuggestionsRepo(
db: Database.Database,
): Promise<DawarichVisitSuggestionsRepository> {
const existing = suggestionsPerHandle.get(db);
if (existing !== undefined) return existing;
const pending = sharedTestOrm(db).then((t) => t.repo(DawarichVisitSuggestions));
suggestionsPerHandle.set(db, pending);
return pending;
}