Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

2.0 KB
Raw Blame
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));
}