mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(journey): client repo and hook for draft entries from photos
Online-only api and repo over the new routes, parsed against the shared contract, and a markup-free hook (with its pure choice model) that reads the preview, keeps the chosen groups and titles across reloads and sends the create, for the desktop dialog and the phone sheet to build on (#1920).
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// FE-API-JOURNEY-FROM-PHOTOS-001
|
||||
//
|
||||
// #1920: the preview and the create pin their path and body and hand back what the server answered.
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { server } from '../../tests/helpers/msw/server';
|
||||
import { journeyEntriesFromPhotosApi } from './journeyEntriesFromPhotos';
|
||||
|
||||
describe('journeyEntriesFromPhotosApi', () => {
|
||||
it('FE-API-JOURNEY-FROM-PHOTOS-001: posts the preview and the create of a journey', async () => {
|
||||
const sent: Array<{ path: string; body: unknown }> = [];
|
||||
const preview = { clusters: [], withoutCaptureTime: 0, maxGapMinutes: 180, maxDistanceKm: 20 };
|
||||
const created = { entries: [], skippedPhotoIds: [4] };
|
||||
server.use(
|
||||
http.post('/api/journeys/7/entries/from-photos/preview', async ({ request }) => {
|
||||
sent.push({ path: new URL(request.url).pathname, body: await request.json() });
|
||||
return HttpResponse.json(preview);
|
||||
}),
|
||||
http.post('/api/journeys/7/entries/from-photos', async ({ request }) => {
|
||||
sent.push({ path: new URL(request.url).pathname, body: await request.json() });
|
||||
return HttpResponse.json(created);
|
||||
})
|
||||
);
|
||||
expect(await journeyEntriesFromPhotosApi.preview(7, { lang: 'de' })).toEqual(preview);
|
||||
expect(await journeyEntriesFromPhotosApi.create(7, { groups: [{ photoIds: [4] }] })).toEqual(created);
|
||||
expect(sent).toEqual([
|
||||
{ path: '/api/journeys/7/entries/from-photos/preview', body: { lang: 'de' } },
|
||||
{ path: '/api/journeys/7/entries/from-photos', body: { groups: [{ photoIds: [4] }] } },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import type {
|
||||
JourneyEntriesFromPhotosCreateRequest,
|
||||
JourneyEntriesFromPhotosCreateResponse,
|
||||
JourneyEntriesFromPhotosPreviewRequest,
|
||||
JourneyEntriesFromPhotosPreviewResponse,
|
||||
} from '@trek/shared';
|
||||
import apiClient from './client';
|
||||
|
||||
const base = (journeyId: number) => `/journeys/${journeyId}/entries/from-photos`;
|
||||
|
||||
/** #1920: the gallery photos on no entry as proposed entries, and the drafts made of the groups kept. */
|
||||
export const journeyEntriesFromPhotosApi = {
|
||||
preview: (
|
||||
journeyId: number,
|
||||
body: JourneyEntriesFromPhotosPreviewRequest,
|
||||
signal?: AbortSignal
|
||||
): Promise<JourneyEntriesFromPhotosPreviewResponse> =>
|
||||
apiClient.post(`${base(journeyId)}/preview`, body, { signal }).then((r) => r.data),
|
||||
create: (
|
||||
journeyId: number,
|
||||
body: JourneyEntriesFromPhotosCreateRequest
|
||||
): Promise<JourneyEntriesFromPhotosCreateResponse> => apiClient.post(base(journeyId), body).then((r) => r.data),
|
||||
};
|
||||
Reference in New Issue
Block a user