mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +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.
86 lines
3.2 KiB
TypeScript
86 lines
3.2 KiB
TypeScript
import { ADDON_IDS } from '../../../src/addons';
|
|
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 { RESPONSE_CONTRACT_KEY } from '../../../src/nest/common/response-contract';
|
|
import { TripAccessGuard } from '../../../src/nest/permissions/trip-access.guard';
|
|
import { parseHorseRoutesQuery, TourHorseRoutesController } from '../../../src/nest/tours/tour-horse-routes.controller';
|
|
import type { TourHorseRoutesService } from '../../../src/nest/tours/tour-horse-routes.service';
|
|
import { HttpException } from '@nestjs/common';
|
|
import { GUARDS_METADATA } from '@nestjs/common/constants';
|
|
import {
|
|
FERRATA_BBOX_INVALID_MESSAGE,
|
|
FERRATA_BBOX_TOO_LARGE_MESSAGE,
|
|
HORSE_ROUTES_ATTRIBUTION,
|
|
horseRoutesResponseSchema,
|
|
type HorseRoutesResponse,
|
|
} from '@trek/shared';
|
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
// HORSE-CTRL-001 to HORSE-CTRL-004
|
|
|
|
function thrown(fn: () => unknown): { status: number; body: unknown } {
|
|
try {
|
|
fn();
|
|
} catch (err) {
|
|
expect(err).toBeInstanceOf(HttpException);
|
|
const e = err as HttpException;
|
|
return { status: e.getStatus(), body: e.getResponse() };
|
|
}
|
|
throw new Error('expected a throw');
|
|
}
|
|
|
|
const answer: HorseRoutesResponse = {
|
|
routes: [],
|
|
truncated: false,
|
|
source: 'openstreetmap',
|
|
attribution: HORSE_ROUTES_ATTRIBUTION,
|
|
};
|
|
|
|
describe('TourHorseRoutesController (HOR-01)', () => {
|
|
it('HORSE-CTRL-001: reads the box of the map view', () => {
|
|
expect(parseHorseRoutesQuery({ bbox: '47.1,11.2,47.4,11.6' }).bbox).toEqual({
|
|
south: 47.1,
|
|
west: 11.2,
|
|
north: 47.4,
|
|
east: 11.6,
|
|
});
|
|
});
|
|
|
|
it('HORSE-CTRL-002: answers a malformed box and one too large with their own messages', () => {
|
|
for (const raw of [{}, { bbox: '1,2,3' }, { bbox: '47.4,11.2,47.1,11.6' }]) {
|
|
expect(thrown(() => parseHorseRoutesQuery(raw))).toEqual({
|
|
status: 400,
|
|
body: { error: FERRATA_BBOX_INVALID_MESSAGE },
|
|
});
|
|
}
|
|
expect(thrown(() => parseHorseRoutesQuery({ bbox: '46,11,47,11.4' }))).toEqual({
|
|
status: 400,
|
|
body: { error: FERRATA_BBOX_TOO_LARGE_MESSAGE },
|
|
});
|
|
});
|
|
|
|
it('HORSE-CTRL-003: hands the box to the service and returns its answer', async () => {
|
|
const list = vi.fn(async () => answer);
|
|
const controller = new TourHorseRoutesController({ list } as unknown as TourHorseRoutesService);
|
|
await expect(controller.list({ bbox: '47.1,11.2,47.4,11.6' })).resolves.toBe(answer);
|
|
expect(list).toHaveBeenCalledWith({ south: 47.1, west: 11.2, north: 47.4, east: 11.6 });
|
|
});
|
|
|
|
it('HORSE-CTRL-004: sits behind the Tours addon, the session and the trip access, and declares its contract', () => {
|
|
expect(Reflect.getMetadata(GUARDS_METADATA, TourHorseRoutesController)).toEqual([
|
|
JwtAuthGuard,
|
|
TripAccessGuard,
|
|
TripAddonGuard,
|
|
]);
|
|
expect(Reflect.getMetadata(REQUIRE_ADDON, TourHorseRoutesController)).toEqual({
|
|
addonId: ADDON_IDS.TOURS,
|
|
label: 'Tours',
|
|
});
|
|
expect(Reflect.getMetadata(RESPONSE_CONTRACT_KEY, TourHorseRoutesController.prototype.list)).toBe(
|
|
horseRoutesResponseSchema,
|
|
);
|
|
});
|
|
});
|