mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
3eac508baf
RowIdPipe (src/nest/common/row-id.pipe.ts) parses a path param with toRowId. It answers a refused spelling with the route's own not-found answer, so '0x5', '5e0' and 'abc' get what an id that names no row gets. ParseRowIdPipe replaces Nest's ParseIntPipe with the same 400 and message: ParseIntPipe let '-1' and numbers past 2^53 through, and Postgres refuses the latter as out of range. Journey, journey recordings, day import, book design, map, public photo, collections, doc-sync, vacay, atlas and the plugin user-data export declare their ids through it. The upload routes parse in the handler with withRowId, so a refused id takes the existing cleanup path, or carry SpoolCleanupInterceptor (collections).
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);
|
|
});
|
|
});
|