mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +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.
69 lines
3.3 KiB
TypeScript
69 lines
3.3 KiB
TypeScript
/**
|
|
* TourPackingLinkController (P2D-XD-01): the route metadata of a tour's packing
|
|
* link and its delegation to TourPackingLinkService. Parity with the MCP tools
|
|
* lives here too: reading needs the trip only, both writes 'place_edit', the
|
|
* same action the tools check.
|
|
*/
|
|
import 'reflect-metadata';
|
|
|
|
import { REQUIRE_ADDON } from '../../../src/nest/addons/require-addon.decorator';
|
|
import { TripAddonGuard } from '../../../src/nest/addons/trip-addon.guard';
|
|
import { JwtAuthGuard } from '../../../src/nest/auth-core/jwt-auth.guard';
|
|
import { TRIP_PERMISSION_KEY, TripAccessGuard } from '../../../src/nest/permissions/trip-access.guard';
|
|
import { TourPackingLinkController } from '../../../src/nest/tours/tour-packing-link.controller';
|
|
import type { TourPackingLinkService } from '../../../src/nest/tours/tour-packing-link.service';
|
|
import type { User } from '../../../src/types';
|
|
import { RequestMethod } from '@nestjs/common';
|
|
import { GUARDS_METADATA, METHOD_METADATA, PATH_METADATA } from '@nestjs/common/constants';
|
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const link = { category: 'Hiking gear', linked_at: '2026-10-20 09:00:00' };
|
|
const detail = { tour: { place_id: 3 }, waypoints: [], packing_link: link };
|
|
|
|
function controllerWith() {
|
|
const service = {
|
|
read: vi.fn(async () => ({ packing_link: link })),
|
|
link: vi.fn(async () => detail),
|
|
unlink: vi.fn(async () => ({ ...detail, packing_link: null })),
|
|
};
|
|
return { service, controller: new TourPackingLinkController(service as unknown as TourPackingLinkService) };
|
|
}
|
|
|
|
describe('TourPackingLinkController', () => {
|
|
it('TPL-CTL-001: sits behind the addon guard before auth and trip access; only the writes need place_edit', () => {
|
|
expect(Reflect.getMetadata(PATH_METADATA, TourPackingLinkController)).toBe('api/trips/:tripId/tours');
|
|
expect(Reflect.getMetadata(GUARDS_METADATA, TourPackingLinkController)).toEqual([
|
|
JwtAuthGuard,
|
|
TripAccessGuard,
|
|
TripAddonGuard,
|
|
]);
|
|
expect(Reflect.getMetadata(REQUIRE_ADDON, TourPackingLinkController)).toEqual({ addonId: 'tours', label: 'Tours' });
|
|
const routes = [
|
|
['read', RequestMethod.GET, undefined],
|
|
['link', RequestMethod.PUT, 'place_edit'],
|
|
['unlink', RequestMethod.DELETE, 'place_edit'],
|
|
] as const;
|
|
for (const [handler, method, permission] of routes) {
|
|
const fn = TourPackingLinkController.prototype[handler];
|
|
expect(Reflect.getMetadata(METHOD_METADATA, fn)).toBe(method);
|
|
expect(Reflect.getMetadata(PATH_METADATA, fn)).toBe(':placeId/packing-link');
|
|
expect(Reflect.getMetadata(TRIP_PERMISSION_KEY, fn)).toBe(permission);
|
|
}
|
|
});
|
|
|
|
it('TPL-CTL-002: hands the trip, tour, body, user and socket id to the service and answers what it answers', async () => {
|
|
const { service, controller } = controllerWith();
|
|
const user = { id: 4 } as User;
|
|
|
|
expect(await controller.read('7', '3')).toEqual({ packing_link: link });
|
|
expect(service.read).toHaveBeenCalledExactlyOnceWith('7', '3');
|
|
|
|
expect(await controller.link(user, '7', '3', { category: 'Hiking gear' }, 'sock-1')).toBe(detail);
|
|
expect(service.link).toHaveBeenCalledExactlyOnceWith('7', '3', { category: 'Hiking gear' }, 4, 'sock-1');
|
|
|
|
expect((await controller.unlink('7', '3', 'sock-2')).packing_link).toBeNull();
|
|
expect(service.unlink).toHaveBeenCalledExactlyOnceWith('7', '3', 'sock-2');
|
|
});
|
|
});
|