mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 23:16:46 +00:00
9b71948497
GET /api/journeys/:id/map-layers answers the planned places of the linked trips (one per place, with every day the plan puts it on and the entry written about it), the trips' GPX routes while the track switch is on, and the located stays entries were taken over from. It goes through journey_trips, so a trip nobody wrote about yet shows its plan too. Every source is read on its own: one that fails says unavailable and the others still draw. A position that is not one is left out, never moved. GET /api/public/journey/:token/map-layers cuts the same on the server by the link: nothing while the map is not shared, the plan and its routes only with share_plan, the recorded days only with share_recordings and only beside a published entry, stays only of published entries. Migration 046190 adds both flags to journey_share_tokens, off by default, so a journey that is public already shows what it showed before. The share link REST route and the MCP share tool take them alike; get_journey_map_layers reads the layers over MCP on the same access, a route by its size only.
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
/**
|
|
* JourneyMapController (JRN-04): the journey map's layers route, its guards,
|
|
* its contract and what it hands the service.
|
|
*/
|
|
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 { JourneyMapController } from '../../../src/nest/journey/journey-map.controller';
|
|
import type { JourneyMapService } from '../../../src/nest/journey/journey-map.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';
|
|
|
|
describe('JourneyMapController', () => {
|
|
it('JRNMAP-CTL-001: GET :id/map-layers behind the Journey addon before auth', () => {
|
|
expect(Reflect.getMetadata(PATH_METADATA, JourneyMapController)).toBe('api/journeys');
|
|
expect(Reflect.getMetadata(GUARDS_METADATA, JourneyMapController)).toEqual([AddonGuard, JwtAuthGuard]);
|
|
expect(Reflect.getMetadata(REQUIRE_ADDON, JourneyMapController)).toEqual({ addonId: 'journey', label: 'Journey' });
|
|
const handler = JourneyMapController.prototype.layers;
|
|
expect(Reflect.getMetadata(METHOD_METADATA, handler)).toBe(RequestMethod.GET);
|
|
expect(Reflect.getMetadata(PATH_METADATA, handler)).toBe(':id/map-layers');
|
|
});
|
|
|
|
it('JRNMAP-CTL-002: hands the journey and the caller to the service and answers what it read', async () => {
|
|
const layers = {
|
|
places: { status: 'ok', items: [] },
|
|
routes: { status: 'unavailable' },
|
|
stays: { status: 'ok', items: [] },
|
|
};
|
|
const mapLayers = vi.fn(async () => layers);
|
|
const controller = new JourneyMapController({ mapLayers } as unknown as JourneyMapService);
|
|
|
|
expect(await controller.layers({ id: 4 } as User, '9')).toBe(layers);
|
|
expect(mapLayers).toHaveBeenCalledWith(9, 4);
|
|
});
|
|
});
|