mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
3f38621024
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.
81 lines
4.3 KiB
TypeScript
81 lines
4.3 KiB
TypeScript
/**
|
|
* WandererWatchController (WAN-02) and the hint route of
|
|
* ToursWandererController: their route metadata and their delegation to
|
|
* WandererWatchService. The watch has no MCP tool, as no part of the wanderer
|
|
* connection has one: it runs on a personal credential that never leaves the
|
|
* server. The hint of a tour asks 'place_edit', the right of the check it
|
|
* leads to.
|
|
*/
|
|
import 'reflect-metadata';
|
|
|
|
import { AddonGuard } from '../../../src/nest/addons/addon.guard';
|
|
import { REQUIRE_ADDON } from '../../../src/nest/addons/require-addon.decorator';
|
|
import { JwtAuthGuard } from '../../../src/nest/auth-core/jwt-auth.guard';
|
|
import { TRIP_PERMISSION_KEY, TripAccessGuard } from '../../../src/nest/permissions/trip-access.guard';
|
|
import { ToursWandererController } from '../../../src/nest/tours/tours-wanderer.controller';
|
|
import type { ToursWandererService } from '../../../src/nest/tours/tours-wanderer.service';
|
|
import { WandererWatchController } from '../../../src/nest/tours/wanderer-watch.controller';
|
|
import type { WandererWatchService } from '../../../src/nest/tours/wanderer-watch.service';
|
|
import { WandererEnabledGuard } from '../../../src/nest/wanderer/wanderer-enabled.guard';
|
|
import type { User } from '../../../src/types';
|
|
import { RequestMethod } from '@nestjs/common';
|
|
import { GUARDS_METADATA, METHOD_METADATA, PATH_METADATA } from '@nestjs/common/constants';
|
|
|
|
import type { Request } from 'express';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const STATUS = { enabled: true, connected: true, lastRunAt: null, pausedUntil: null, blocked: false, hints: [] };
|
|
|
|
function watchService() {
|
|
return {
|
|
status: vi.fn(async () => STATUS),
|
|
setEnabled: vi.fn(async () => STATUS),
|
|
hintFor: vi.fn(async () => ({ hint: null })),
|
|
};
|
|
}
|
|
|
|
describe('WandererWatchController', () => {
|
|
it('WWCTL-001: sits beside the connection, behind auth, Tours for the caller and the wanderer switch', () => {
|
|
expect(Reflect.getMetadata(PATH_METADATA, WandererWatchController)).toBe('api/integrations/wanderer/watch');
|
|
// Auth first: the watch belongs to no one trip, so Tours opens once the caller is known (any trip of theirs).
|
|
expect(Reflect.getMetadata(GUARDS_METADATA, WandererWatchController)).toEqual([
|
|
JwtAuthGuard,
|
|
AddonGuard,
|
|
WandererEnabledGuard,
|
|
]);
|
|
expect(Reflect.getMetadata(REQUIRE_ADDON, WandererWatchController)).toEqual({ addonId: 'tours', label: 'Tours' });
|
|
expect(Reflect.getMetadata(METHOD_METADATA, WandererWatchController.prototype.status)).toBe(RequestMethod.GET);
|
|
expect(Reflect.getMetadata(METHOD_METADATA, WandererWatchController.prototype.setEnabled)).toBe(RequestMethod.PUT);
|
|
});
|
|
|
|
it('WWCTL-002: reads and switches only the caller own watch', async () => {
|
|
const service = watchService();
|
|
const controller = new WandererWatchController(service as unknown as WandererWatchService);
|
|
const user = { id: 4 } as User;
|
|
expect(await controller.status(user)).toBe(STATUS);
|
|
expect(service.status).toHaveBeenCalledExactlyOnceWith(4);
|
|
const req = { headers: {}, socket: { remoteAddress: '10.0.0.9' } } as unknown as Request;
|
|
expect(await controller.setEnabled(user, { enabled: false }, req)).toBe(STATUS);
|
|
expect(service.setEnabled).toHaveBeenCalledExactlyOnceWith(4, false, expect.anything());
|
|
});
|
|
});
|
|
|
|
describe('ToursWandererController hint route', () => {
|
|
it('WWCTL-003: asks place_edit like the check, and hands trip, user and tour to the watch', async () => {
|
|
const fn = ToursWandererController.prototype.hint;
|
|
expect(Reflect.getMetadata(METHOD_METADATA, fn)).toBe(RequestMethod.GET);
|
|
expect(Reflect.getMetadata(PATH_METADATA, fn)).toBe('sources/:placeId/hint');
|
|
expect(Reflect.getMetadata(TRIP_PERMISSION_KEY, fn)).toBe('place_edit');
|
|
expect(Reflect.getMetadata(TRIP_PERMISSION_KEY, ToursWandererController.prototype.checkSource)).toBe('place_edit');
|
|
expect(Reflect.getMetadata(GUARDS_METADATA, ToursWandererController)).toContain(TripAccessGuard);
|
|
|
|
const service = watchService();
|
|
const controller = new ToursWandererController(
|
|
{} as ToursWandererService,
|
|
service as unknown as WandererWatchService,
|
|
);
|
|
expect(await controller.hint('7', '3', { id: 4 } as User)).toEqual({ hint: null });
|
|
expect(service.hintFor).toHaveBeenCalledExactlyOnceWith('7', 4, '3');
|
|
});
|
|
});
|