mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
test(journey): pin the capture hint through the upload routes and the shared contract
This commit is contained in:
@@ -476,7 +476,7 @@ export class JourneyController {
|
||||
// ── Gallery (prefix /:id/gallery — before /:id) ─────────────────────────
|
||||
@Post(':id/gallery/photos')
|
||||
@UseInterceptors(FilesInterceptor('photos'))
|
||||
async uploadGalleryPhotos(@CurrentUser() user: User, @Param('id') id: string, @UploadedFiles() files: Express.Multer.File[] | undefined, @Body() body: JourneyGalleryPhotoUploadDto) {
|
||||
async uploadGalleryPhotos(@CurrentUser() user: User, @Param('id') id: string, @UploadedFiles() files: Express.Multer.File[] | undefined, @Body() body?: JourneyGalleryPhotoUploadDto) {
|
||||
this.refuseDemoUpload(user, files ?? []);
|
||||
if (!files?.length) {
|
||||
throw new HttpException({ error: 'No files uploaded' }, 400);
|
||||
|
||||
@@ -625,7 +625,7 @@ describe('Journey e2e (real auth guard + temp SQLite)', () => {
|
||||
expect(res.body.photos).toHaveLength(1);
|
||||
// The capture backfill runs for the upload (and may place its entry, #1003)...
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
expect(backfillRun).toHaveBeenCalledWith([90], 1);
|
||||
expect(backfillRun).toHaveBeenCalledWith([90], 1, undefined);
|
||||
// ...but no journey refresh follows: a bulk upload would otherwise reload
|
||||
// every open client once per photo.
|
||||
expect(jsvc.broadcastJourneyEvent).not.toHaveBeenCalled();
|
||||
|
||||
@@ -199,10 +199,20 @@ describe('JourneyController', () => {
|
||||
]);
|
||||
// The client uploads one file per request, so a refresh per upload would
|
||||
// reload every open client once per photo: uploads backfill and stay quiet.
|
||||
// No capture fields came along, so no hint does either (#3120).
|
||||
expect(scheduleUpload.mock.calls).toEqual([
|
||||
[[entryPhoto], 1],
|
||||
[[galleryPhoto], 1],
|
||||
[[entryPhoto], 1, null],
|
||||
[[galleryPhoto], 1, null],
|
||||
]);
|
||||
scheduleUpload.mockClear();
|
||||
const fields = { taken_at: '2026-05-30T13:52:19.000Z', lat: '64.1466000', lng: '-21.9426000' };
|
||||
const hint = { takenAt: '2026-05-30T13:52:19.000Z', lat: 64.1466, lng: -21.9426 };
|
||||
await c.uploadGalleryPhotos(user, '9', [{ filename: 'g.jpg' } as Express.Multer.File], fields);
|
||||
await c.uploadEntryPhotos(user, '3', [{ filename: 'a.jpg', originalname: 'a.jpg' } as Express.Multer.File], fields);
|
||||
// Two files in one request: the hint names neither of them.
|
||||
const two = [{ filename: 'g.jpg' }, { filename: 'h.jpg' }] as Express.Multer.File[];
|
||||
await c.uploadGalleryPhotos(user, '9', two, fields);
|
||||
expect(scheduleUpload.mock.calls.map((call) => call[2])).toEqual([hint, hint, null]);
|
||||
});
|
||||
|
||||
it('link-photo: 400 without id (accepts legacy photo_id), 403, success, and the asking tab is skipped', async () => {
|
||||
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
journeyContributorRequestSchema,
|
||||
journeyContributorUpdateRequestSchema,
|
||||
journeyPhotosDeleteToolSchema,
|
||||
journeyEntryPhotoUploadRequestSchema,
|
||||
journeyGalleryPhotoUploadRequestSchema,
|
||||
journeyProviderPhotosRequestSchema,
|
||||
journeyShareLinkRequestSchema,
|
||||
journeyUpdateRequestSchema,
|
||||
@@ -91,6 +93,21 @@ describe('journeyContributorUpdateRequestSchema', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('photo upload capture fields (#3120)', () => {
|
||||
it('takes the capture fields as strings beside the file, and no body at all', () => {
|
||||
const fields = { taken_at: '2026-05-30T13:52:19.000Z', lat: '64.1466000', lng: '-21.9426000' };
|
||||
expect(journeyGalleryPhotoUploadRequestSchema.safeParse(fields).success).toBe(true);
|
||||
expect(journeyGalleryPhotoUploadRequestSchema.safeParse(undefined).success).toBe(true);
|
||||
expect(journeyEntryPhotoUploadRequestSchema.safeParse({ caption: 'x', ...fields }).success).toBe(true);
|
||||
});
|
||||
|
||||
it('refuses a field that is not a string or is far too long to be a time or a coordinate', () => {
|
||||
expect(journeyGalleryPhotoUploadRequestSchema.safeParse({ lat: 64.1 }).success).toBe(false);
|
||||
expect(journeyGalleryPhotoUploadRequestSchema.safeParse({ taken_at: 'x'.repeat(41) }).success).toBe(false);
|
||||
expect(journeyEntryPhotoUploadRequestSchema.safeParse({ lng: 'y'.repeat(33) }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('journeyPhotosDeleteToolSchema', () => {
|
||||
it('takes one journey and 1 to 100 photo ids', () => {
|
||||
expect(journeyPhotosDeleteToolSchema.safeParse({ journeyId: 1, journey_photo_ids: [2, 3] }).success).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user