mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
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:
@@ -12,9 +12,13 @@ vi.mock('../../db/offlineDb', () => ({ saveImportFiles: vi.fn(async () => {}) })
|
|||||||
|
|
||||||
const defaultProps = { isOpen: true, onClose: vi.fn(), tripId: 4 };
|
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 eml = (name = 'booking.eml', size = 100) => {
|
||||||
const f = new File(['x'], name, { type: 'message/rfc822' });
|
const f = new File(['x'.repeat(Math.min(size, 4096))], name, { type: 'message/rfc822' });
|
||||||
Object.defineProperty(f, 'size', { value: size });
|
if (size > 4096) Object.defineProperty(f, 'size', { value: size });
|
||||||
return f;
|
return f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ vi.mock('../shared/Toast', () => ({
|
|||||||
|
|
||||||
const defaultProps = { isOpen: true, onClose: vi.fn(), tripId: 3 };
|
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 gpx = (name = 'route.gpx', size = 100) => {
|
||||||
const f = new File(['<gpx/>'], name, { type: 'application/gpx+xml' });
|
const f = new File(['<gpx/>'.padEnd(Math.min(size, 4096), ' ')], name, { type: 'application/gpx+xml' });
|
||||||
Object.defineProperty(f, 'size', { value: size });
|
if (size > 4096) Object.defineProperty(f, 'size', { value: size });
|
||||||
return f;
|
return f;
|
||||||
};
|
};
|
||||||
const kml = (name = 'places.kml') => new File(['<kml/>'], name, { type: 'application/vnd.google-earth.kml+xml' });
|
const kml = (name = 'places.kml') => new File(['<kml/>'], name, { type: 'application/vnd.google-earth.kml+xml' });
|
||||||
|
|||||||
Reference in New Issue
Block a user