mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
feat(tours): route paddle tours on the water, shaping points and auto-loaded regions
Paddle tours are planned on the water by TREK's own router: a water network per paddle region, built from the same Geofabrik extract as the obstacles and searched in a worker thread of the server (no sidecar). Rivers, canals and lakes (direct or along the shore), portages round weirs, locks by policy, whitewater by boat, gaps marked. Found portages and locks become points of their own; an unplannable leg says why and offers a way out. - Shaping points: a click on the line sets a point that steers the route without being a stop (hikes and paddle tours); recompute a single leg. - Lake style direct/shore, suggested from the wind forecast. - Regions load by themselves where a paddler plans (admin setting: automatic, on request, off; size cap and a daily count), with requests for the admins, a notification, and the load followed on the leg. - Portage from the last point, portages follow footways via the walking router (or stay straight), "put in here" on slipways and put-ins. - MCP plan_paddle_route with the REST route's rules.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// FE-REPO-PADDLE-REGION-LOAD-001 to 003: the water data of places asked for online only (PAD-11C).
|
||||
import { paddleRegionLoadRequestSchema, paddleRegionLoadResponseSchema } from '@trek/shared';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { contractHandler } from '../../tests/helpers/msw/contract';
|
||||
import { server } from '../../tests/helpers/msw/server';
|
||||
import { setForcedOffline } from '../sync/networkMode';
|
||||
import { paddleRegionLoadRepo } from './paddleRegionLoadRepo';
|
||||
|
||||
const LOAD = '/api/paddle/regions/load';
|
||||
const PLACE = { lat: 53.2, lng: 12.9 };
|
||||
|
||||
describe('paddleRegionLoadRepo', () => {
|
||||
afterEach(() => setForcedOffline(false));
|
||||
|
||||
it('FE-REPO-PADDLE-REGION-LOAD-001: asks the server for the places and answers its states in order', async () => {
|
||||
const bodies: unknown[] = [];
|
||||
server.use(
|
||||
contractHandler(
|
||||
'post',
|
||||
LOAD,
|
||||
{ request: paddleRegionLoadRequestSchema, response: paddleRegionLoadResponseSchema },
|
||||
async ({ request }) => {
|
||||
bodies.push(await request.json());
|
||||
return { points: [{ state: 'ready', region: { id: 'mv', name: 'Mecklenburg' } }] };
|
||||
}
|
||||
)
|
||||
);
|
||||
await expect(paddleRegionLoadRepo.load([PLACE], true)).resolves.toEqual([
|
||||
{ state: 'ready', region: { id: 'mv', name: 'Mecklenburg' } },
|
||||
]);
|
||||
expect(bodies).toEqual([{ points: [PLACE], retry: true }]);
|
||||
});
|
||||
|
||||
it('FE-REPO-PADDLE-REGION-LOAD-002: asks nothing offline or about no place', async () => {
|
||||
setForcedOffline(true);
|
||||
await expect(paddleRegionLoadRepo.load([PLACE], false)).resolves.toBeNull();
|
||||
setForcedOffline(false);
|
||||
await expect(paddleRegionLoadRepo.load([], false)).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it('FE-REPO-PADDLE-REGION-LOAD-003: refuses an answer that is not the contract', async () => {
|
||||
server.use(http.post(LOAD, () => HttpResponse.json({ points: [{ state: 'maybe' }] })));
|
||||
await expect(paddleRegionLoadRepo.load([PLACE], false)).rejects.toMatchObject({ name: 'ZodError' });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user