Files
TREK/server/tests/unit/nest/tour-drafts.controller.test.ts
T
Maurice 31859651d7 feat(help): rewrite the help center for v5 with a Tours section, new pictures in every language, and fix the tour planner bugs it surfaced
Every help screen checked against the v5 redesign. Tours is documented for
the first time, as a screen of its own with twelve screens under it, and
notifications get help of their own. All pictures are taken again on a
realistic demo trip, with short loops where a still cannot show the motion.
The English is plain and every language is written naturally rather than
word for word.

The switcher shows two levels at most, a screen's overview lists its
sub-screens as cards above its guides, each wiki page is linked once, and
the help sidebar is wider.

Fixes found along the way: Save to Collection keeps a tour's route, a track
dropped on the places column opens the Tours import, tour Share on desktop,
the unsaved tour draft lives on the account, a route click no longer adds
an end point, Trip places leaves the trip's tours out, Escape closes a
stage's day menu, confirms before destructive deletes, DWD warnings sharing
one id kept apart, a booking's date moves with it, and smaller fixes across
notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and
the admin screens.
2026-10-22 22:29:35 +02:00

66 lines
3.0 KiB
TypeScript

/**
* TourDraftsController: the route metadata of the planner's account draft and
* its delegation to TourDraftsService with the signed-in user.
*/
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 { TourDraftsController } from '../../../src/nest/tours/tour-drafts.controller';
import type { TourDraftsService } from '../../../src/nest/tours/tour-drafts.service';
import type { User } from '../../../src/types';
import { RequestMethod } from '@nestjs/common';
import { GUARDS_METADATA, METHOD_METADATA, PATH_METADATA } from '@nestjs/common/constants';
import type { TourDraftResponse } from '@trek/shared';
import { describe, expect, it, vi } from 'vitest';
const answer: TourDraftResponse = { draft: { payload: '{"version":11}', updated_at: '2026-10-22 09:00:00' } };
const user = { id: 4 } as User;
function controllerWith() {
const service = {
read: vi.fn(async () => answer),
keep: vi.fn(async () => answer),
forget: vi.fn(async () => ({ success: true as const })),
};
return { service, controller: new TourDraftsController(service as unknown as TourDraftsService) };
}
describe('TourDraftsController', () => {
it('TDRAFT-CTL-001: sits behind the addon guard before auth and trip access; only keeping a draft needs place_edit', () => {
expect(Reflect.getMetadata(PATH_METADATA, TourDraftsController)).toBe('api/trips/:tripId/tour-draft');
expect(Reflect.getMetadata(GUARDS_METADATA, TourDraftsController)).toEqual([
AddonGuard,
JwtAuthGuard,
TripAccessGuard,
]);
expect(Reflect.getMetadata(REQUIRE_ADDON, TourDraftsController)).toEqual({ addonId: 'tours', label: 'Tours' });
const routes = [
['read', RequestMethod.GET, undefined],
['keep', RequestMethod.PUT, 'place_edit'],
['forget', RequestMethod.DELETE, undefined],
] as const;
for (const [handler, method, permission] of routes) {
const fn = TourDraftsController.prototype[handler];
expect(Reflect.getMetadata(METHOD_METADATA, fn)).toBe(method);
expect(Reflect.getMetadata(PATH_METADATA, fn)).toBe('/');
expect(Reflect.getMetadata(TRIP_PERMISSION_KEY, fn)).toBe(permission);
}
});
it('TDRAFT-CTL-002: hands the trip, the signed-in user and the body to the service and answers what it answers', async () => {
const { service, controller } = controllerWith();
expect(await controller.read(user, 7)).toBe(answer);
expect(service.read).toHaveBeenCalledExactlyOnceWith(7, 4);
expect(await controller.keep(user, 7, { payload: '{"version":11}' })).toBe(answer);
expect(service.keep).toHaveBeenCalledExactlyOnceWith(7, 4, { payload: '{"version":11}' });
expect(await controller.forget(user, 7)).toEqual({ success: true });
expect(service.forget).toHaveBeenCalledExactlyOnceWith(7, 4);
});
});