Files
TREK/server/tests/helpers/notifications-repos.ts
T
2026-10-06 21:50:59 +02:00

37 lines
2.0 KiB
TypeScript

import { NotificationChannelPreferences } from '../../src/db/entities/NotificationChannelPreferences.entity';
import { Notifications } from '../../src/db/entities/Notifications.entity';
import { PushSubscriptions } from '../../src/db/entities/PushSubscriptions.entity';
import type { NotificationChannelPreferencesRepository } from '../../src/db/repositories/NotificationChannelPreferences.repository';
import type { NotificationsRepository } from '../../src/db/repositories/Notifications.repository';
import type { PushSubscriptionsRepository } from '../../src/db/repositories/PushSubscriptions.repository';
import { sharedTestOrm } from './test-uow';
import type Database from 'better-sqlite3';
/**
* Plan 3f Task 3 (`NotificationsService`/`NotificationPreferencesService`)
* test-only repository factories, bound to a suite's own better-sqlite3
* handle via the SAME memoised `sharedTestOrm` `test-uow.ts` exports — the
* `todo-repos.ts`/`packing-repos.ts` precedent (a repository from a SECOND,
* independent ORM instance would resolve a different transaction fork than
* the `UnitOfWork`/`AppSettingsRepository` a hand-built service also needs).
*
* A NEW file rather than an addition to `test-uow.ts`, same reasoning those
* two files give for themselves: avoids colliding with a concurrently
* in-flight task's edits to that shared file.
*/
export function createTestNotificationsRepo(db: Database.Database): Promise<NotificationsRepository> {
return sharedTestOrm(db).then((t) => t.repo(Notifications));
}
export function createTestNotificationChannelPreferencesRepo(
db: Database.Database,
): Promise<NotificationChannelPreferencesRepository> {
return sharedTestOrm(db).then((t) => t.repo(NotificationChannelPreferences));
}
/** Web Push (#894): the `push_subscriptions` table behind `PushSubscriptionsService`. */
export function createTestPushSubscriptionsRepo(db: Database.Database): Promise<PushSubscriptionsRepository> {
return sharedTestOrm(db).then((t) => t.repo(PushSubscriptions));
}