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' });