Files
TREK/server/tests/helpers/test-addons.ts
T
Maurice 3f38621024 feat(server): let a trip owner switch trip addons for one trip
A trip can now turn a trip addon (lists, costs, documents, collab, road
trip, tours) on or off for itself, whatever the instance switch says. No
row in the new trip_addon_overrides table means the trip follows the
instance; a row is the owner's choice. Going back to the instance setting
deletes the row, and no addon data is touched either way.

- GET/PUT /api/trips/:tripId/addons[/:addonId] (every member reads, the
  owner writes) and the MCP tools get_trip_addons and set_trip_addon, on
  the shared tripAddons contract; tripAddons:changed tells the members.
- Every trip-scoped addon surface asks the trip: REST through
  TripAddonGuard, MCP through a per-call gate on the named or pinned trip,
  plugin RPC and events, the share link, the offline bundle, reminders,
  doc sync, the assistant (tools, keep_attached_file), booking costs, the
  trip summary prompt, and the cross-trip tour reads (library, Atlas
  stats, collection save).
- Routes without a trip open while the addon is on in any of the user's
  trips. Switching an addon on that the instance has off ends the members'
  MCP sessions so they reconnect with its tools.
- A copied trip takes its owner's choices along.

Behaviour changes: an anonymous call to an addon route that is off now
gets 401 instead of 404, and with an instance switch off the packing,
todo and files plugin RPC methods, the files MCP tools, todo reminder
mails, core plugin events, plugin view contributions, the share link's
lists, costs and chat sections and the offline bundle's lists follow it.
2026-11-21 13:23:09 +01:00

51 lines
2.4 KiB
TypeScript

import { SqliteEngine } from '../../src/db/engine/sqlite/sqlite-engine';
import { Addons } from '../../src/db/entities/Addons.entity';
import { AppSettings } from '../../src/db/entities/AppSettings.entity';
import { PhotoProviderFields } from '../../src/db/entities/PhotoProviderFields.entity';
import { PhotoProviders } from '../../src/db/entities/PhotoProviders.entity';
import { TripAddonOverrides } from '../../src/db/entities/TripAddonOverrides.entity';
import { Users } from '../../src/db/entities/Users.entity';
import { AddonsService } from '../../src/nest/addons/addons.service';
import { UnitOfWork } from '../../src/nest/database/unit-of-work';
import { sharedTestOrm } from './test-uow';
import type Database from 'better-sqlite3';
/**
* AddonsService's constructor grew from one `DatabaseService` to four
* injected repositories plus `DatabaseService` (Plan 3a Task 4, addons.md —
* the `AppSettingsRepository`/`AddonsRepository`/`PhotoProvidersRepository`/
* `PhotoProviderFieldsRepository` wiring). Every hand-constructed
* `new AddonsService(dbs)` in the test tree needs the same four repositories
* a real `@InjectRepository` graph would hand it — this file is that
* factory, named `test-addons.ts` per the Task 4 brief (owned by Task 4;
* `tests/helpers/test-uow.ts` stays Task 3's file to extend).
*
* Built on the shared per-handle ORM (`test-uow.ts`'s `sharedTestOrm`, not a
* fresh `createTestOrm` here) — the SAME one `createTestAppSettingsRepo`/
* `createTestUnitOfWork` draw from, so a repository built here and a
* `UnitOfWork`/repository built elsewhere for the same handle resolve
* through the identical context-resolving `EntityManager`, exactly like
* Nest's real DI graph (task-2-review.md I2's fix, carried forward for this
* domain).
*/
/**
* The full `AddonsService` a hand-constructed test collaborator needs, bound
* to the suite's own better-sqlite3 handle. Plan 4 Task 4 dropped the
* trailing `DatabaseService` param (dead in `AddonsService` itself since
* `transit-provider.ts`/`instance-api-keys.ts` moved onto
* `AppSettingsRepository` — Plan 4 Task 1).
*/
export async function createTestAddonsService(db: Database.Database): Promise<AddonsService> {
const t = await sharedTestOrm(db);
return new AddonsService(
t.repo(Addons),
t.repo(PhotoProviders),
t.repo(PhotoProviderFields),
t.repo(AppSettings),
t.repo(Users),
new UnitOfWork(t.em, new SqliteEngine()),
t.repo(TripAddonOverrides),
);
}