mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
test(places): cover the place sheet sections, tags, trip lists and the visited filter
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// FE-API-PLACE-VISITS-001
|
||||
//
|
||||
// D7/PLC-10 to PLC-23: each read pins its verb, its path and its query; there is nothing to write.
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { server } from '../../tests/helpers/msw/server';
|
||||
import { placeVisitsApi } from './placeVisits';
|
||||
|
||||
let calls: Array<[string, string]> = [];
|
||||
|
||||
beforeEach(() => {
|
||||
calls = [];
|
||||
});
|
||||
|
||||
function record(data: object) {
|
||||
return ({ request }: { request: Request }) => {
|
||||
const url = new URL(request.url);
|
||||
calls.push([request.method, `${url.pathname}${url.search}`]);
|
||||
return HttpResponse.json(data);
|
||||
};
|
||||
}
|
||||
|
||||
describe('placeVisitsApi', () => {
|
||||
it('FE-API-PLACE-VISITS-001: reads the visits and the media at the routes the server serves', async () => {
|
||||
server.use(
|
||||
http.get('/api/place-visits', record({ visits: [], total: 0 })),
|
||||
http.get('/api/place-visits/place', record({ visits: [], visit_count: 0, last_visit: null })),
|
||||
http.get('/api/trips/4/place-visits/mine', record({ place_ids: [], places: [] })),
|
||||
http.get(
|
||||
'/api/addons/collections/library/places/trip/3/media',
|
||||
record({ images: [], journey_photos: [], files: [] })
|
||||
)
|
||||
);
|
||||
|
||||
expect(await placeVisitsApi.list({ trip_id: 4 })).toEqual({ visits: [], total: 0 });
|
||||
expect(await placeVisitsApi.forPlace('trip', 3)).toEqual({ visits: [], visit_count: 0, last_visit: null });
|
||||
expect(await placeVisitsApi.tripVisited(4)).toEqual({ place_ids: [], places: [] });
|
||||
expect(await placeVisitsApi.media('trip', 3)).toEqual({ images: [], journey_photos: [], files: [] });
|
||||
expect(Object.keys(placeVisitsApi).sort()).toEqual(['forPlace', 'list', 'media', 'tripVisited']);
|
||||
|
||||
expect(calls).toEqual([
|
||||
['GET', '/api/place-visits?trip_id=4'],
|
||||
['GET', '/api/place-visits/place?kind=trip&id=3'],
|
||||
['GET', '/api/trips/4/place-visits/mine'],
|
||||
['GET', '/api/addons/collections/library/places/trip/3/media'],
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user