From 1d9fe9a3df2b38bb3e3cbec65ca0a6625e9f95a6 Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 29 Jul 2026 11:17:47 +0200 Subject: [PATCH] test(import): stop the upload fixtures lying about their size The helpers built a one-byte File and then redefined size to 100, so the multipart body and the length it announced disagreed. Node 24 rejects that while 22 lets it through, which is why only CI saw it: every test that uploaded such a file and expected success failed, the one expecting an error passed for the wrong reason, and the KML case with a truthful File was fine. --- client/src/components/Planner/BookingImportModal.test.tsx | 8 ++++++-- client/src/components/Planner/FileImportModal.test.tsx | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/src/components/Planner/BookingImportModal.test.tsx b/client/src/components/Planner/BookingImportModal.test.tsx index 16ed99d4a..ea5cdcdb9 100644 --- a/client/src/components/Planner/BookingImportModal.test.tsx +++ b/client/src/components/Planner/BookingImportModal.test.tsx @@ -12,9 +12,13 @@ vi.mock('../../db/offlineDb', () => ({ saveImportFiles: vi.fn(async () => {}) }) const defaultProps = { isOpen: true, onClose: vi.fn(), tripId: 4 }; +// A file that is actually uploaded has to carry as many bytes as it reports — +// a size that lies leaves the multipart body and its length disagreeing, and the +// upload then fails to parse. Only the oversize case fakes the number, and that +// file is rejected by validateFile before it is ever sent. const eml = (name = 'booking.eml', size = 100) => { - const f = new File(['x'], name, { type: 'message/rfc822' }); - Object.defineProperty(f, 'size', { value: size }); + const f = new File(['x'.repeat(Math.min(size, 4096))], name, { type: 'message/rfc822' }); + if (size > 4096) Object.defineProperty(f, 'size', { value: size }); return f; }; diff --git a/client/src/components/Planner/FileImportModal.test.tsx b/client/src/components/Planner/FileImportModal.test.tsx index d77c603bb..fe4ee533f 100644 --- a/client/src/components/Planner/FileImportModal.test.tsx +++ b/client/src/components/Planner/FileImportModal.test.tsx @@ -19,9 +19,11 @@ vi.mock('../shared/Toast', () => ({ const defaultProps = { isOpen: true, onClose: vi.fn(), tripId: 3 }; +// See BookingImportModal.test.tsx: a file that is really uploaded must carry as +// many bytes as it reports, otherwise the multipart body and its length disagree. const gpx = (name = 'route.gpx', size = 100) => { - const f = new File([''], name, { type: 'application/gpx+xml' }); - Object.defineProperty(f, 'size', { value: size }); + const f = new File([''.padEnd(Math.min(size, 4096), ' ')], name, { type: 'application/gpx+xml' }); + if (size > 4096) Object.defineProperty(f, 'size', { value: size }); return f; }; const kml = (name = 'places.kml') => new File([''], name, { type: 'application/vnd.google-earth.kml+xml' });