mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
feat(tours): via ferrata layer mounted on the tours map (2D and 3D)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// FE-API-FERRATAS-001 to FE-API-FERRATAS-002
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { server } from '../../tests/helpers/msw/server';
|
||||
import { ferratasApi } from './ferratas';
|
||||
|
||||
const reply = { ferratas: [], truncated: false, source: 'openstreetmap', attribution: '© OpenStreetMap contributors' };
|
||||
|
||||
describe('ferratasApi.list', () => {
|
||||
it('FE-API-FERRATAS-001: asks GET /api/trips/:tripId/ferratas with the bbox and returns the body', async () => {
|
||||
let url = '';
|
||||
server.use(
|
||||
http.get('/api/trips/7/ferratas', ({ request }) => {
|
||||
url = request.url;
|
||||
return HttpResponse.json(reply);
|
||||
})
|
||||
);
|
||||
|
||||
await expect(ferratasApi.list(7, '46.500,11.700,46.600,11.900')).resolves.toEqual(reply);
|
||||
expect(new URL(url).searchParams.get('bbox')).toBe('46.500,11.700,46.600,11.900');
|
||||
});
|
||||
|
||||
it('FE-API-FERRATAS-002: an unreachable Overpass (502) rejects', async () => {
|
||||
server.use(
|
||||
http.get('/api/trips/7/ferratas', () =>
|
||||
HttpResponse.json({ error: 'Overpass unavailable', code: 'ferratas_unavailable' }, { status: 502 })
|
||||
)
|
||||
);
|
||||
|
||||
await expect(ferratasApi.list(7, '46.500,11.700,46.600,11.900')).rejects.toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import apiClient from './client';
|
||||
|
||||
/**
|
||||
* How long the browser waits for GET /api/trips/:tripId/ferratas.
|
||||
*
|
||||
* The server races the configured Overpass mirrors under one OVERPASS_TIMEOUT_MS
|
||||
* (25 s by default) and answers 502 when none of them made it. The shared 8 s
|
||||
* on `apiClient` would give up on a slow but healthy mirror and show an error
|
||||
* the server was about to resolve, so this sits just above the server's own
|
||||
* ceiling.
|
||||
*/
|
||||
const FERRATAS_TIMEOUT_MS = 30_000;
|
||||
|
||||
/**
|
||||
* GET /api/trips/:tripId/ferratas: the via ferratas OpenStreetMap knows inside
|
||||
* one map area. In its own file rather than in the `client.ts` god module. The
|
||||
* answer comes back unparsed; repo/ferrataRepo.ts checks it against the shared
|
||||
* contract before anything draws it.
|
||||
*/
|
||||
export const ferratasApi = {
|
||||
list: (tripId: number, bbox: string, signal?: AbortSignal): Promise<unknown> =>
|
||||
apiClient
|
||||
.get(`/trips/${tripId}/ferratas`, { params: { bbox }, signal, timeout: FERRATAS_TIMEOUT_MS })
|
||||
.then((response) => response.data as unknown),
|
||||
};
|
||||
Reference in New Issue
Block a user