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.
This commit is contained in:
Maurice
2026-07-29 11:17:47 +02:00
committed by Maurice
parent be0164eb91
commit 1d9fe9a3df
2 changed files with 10 additions and 4 deletions
@@ -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;
};
@@ -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(['<gpx/>'], name, { type: 'application/gpx+xml' });
Object.defineProperty(f, 'size', { value: size });
const f = new File(['<gpx/>'.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(['<kml/>'], name, { type: 'application/vnd.google-earth.kml+xml' });