mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 07:26:30 +00:00
test(import): read the upload body instead of parsing it as FormData
These are the only two test files that call request.formData() inside an MSW handler, and they hold exactly the three tests that failed on CI while passing locally. The body axios' XHR adapter produces under jsdom is one Node 24's multipart parser rejects, so the handler threw before reading a field and the component reported a failed upload. Reading the raw payload asserts the same thing without depending on the parser.
This commit is contained in:
@@ -3,6 +3,7 @@ import { render, screen, fireEvent, waitFor } from '../../../tests/helpers/rende
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { server } from '../../../tests/helpers/msw/server';
|
||||
import { readMultipart } from '../../../tests/helpers/multipart';
|
||||
import { useBackgroundTasksStore } from '../../store/backgroundTasksStore';
|
||||
import { resetAllStores } from '../../../tests/helpers/store';
|
||||
import { saveImportFiles } from '../../db/offlineDb';
|
||||
@@ -111,8 +112,7 @@ describe('BookingImportModal', () => {
|
||||
let sentMode: string | null = null;
|
||||
server.use(
|
||||
http.post('/api/trips/4/reservations/import/booking/async', async ({ request }) => {
|
||||
const fd = await request.formData();
|
||||
sentMode = String(fd.get('mode'));
|
||||
sentMode = (await readMultipart(request)).fields.mode ?? null;
|
||||
return HttpResponse.json({ jobId: 'job-42' });
|
||||
}),
|
||||
);
|
||||
@@ -132,8 +132,7 @@ describe('BookingImportModal', () => {
|
||||
server.use(
|
||||
http.get('/api/health/features', () => HttpResponse.json({ bookingImport: true, aiParsing: true })),
|
||||
http.post('/api/trips/4/reservations/import/booking/async', async ({ request }) => {
|
||||
const fd = await request.formData();
|
||||
sentMode = String(fd.get('mode'));
|
||||
sentMode = (await readMultipart(request)).fields.mode ?? null;
|
||||
return HttpResponse.json({ jobId: 'job-ai' });
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { render, screen, fireEvent, waitFor } from '../../../tests/helpers/render';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { server } from '../../../tests/helpers/msw/server';
|
||||
import { readMultipart } from '../../../tests/helpers/multipart';
|
||||
import { useTripStore } from '../../store/tripStore';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import { buildTrip } from '../../../tests/helpers/factories';
|
||||
@@ -127,11 +128,11 @@ describe('FileImportModal', () => {
|
||||
let flags: Record<string, string> = {};
|
||||
server.use(
|
||||
http.post('/api/trips/3/places/import/gpx', async ({ request }) => {
|
||||
const fd = await request.formData();
|
||||
const { fields } = await readMultipart(request);
|
||||
flags = {
|
||||
waypoints: String(fd.get('importWaypoints')),
|
||||
routes: String(fd.get('importRoutes')),
|
||||
tracks: String(fd.get('importTracks')),
|
||||
waypoints: fields.importWaypoints,
|
||||
routes: fields.importRoutes,
|
||||
tracks: fields.importTracks,
|
||||
};
|
||||
return HttpResponse.json({ count: 4, skipped: 0, places: [{ id: 11 }, { id: 12 }] });
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user