fix tests ugh
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m59s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m59s
This commit is contained in:
@@ -48,6 +48,22 @@ const server = setupServer(
|
||||
}
|
||||
} else if (contentType?.includes('multipart/form-data')) {
|
||||
body = await request.formData();
|
||||
// FIX: When MSW processes FormData, the file's 'name' property is lost in JSDOM.
|
||||
// To fix the tests, we manually reconstruct a File-like object with the name
|
||||
// from the headers for our spy. This makes the test assertions pass.
|
||||
const fileEntry = Array.from((body as FormData).entries()).find(
|
||||
([key, value]) => value instanceof File
|
||||
);
|
||||
if (fileEntry) {
|
||||
const [key, file] = fileEntry as [string, File];
|
||||
// Create a new object that looks like a File for the spy
|
||||
(body as FormData).set(key, {
|
||||
name: file.name, // JSDOM preserves the name on the original File object
|
||||
size: file.size,
|
||||
type: file.type,
|
||||
// The test doesn't need the content, so we can omit it.
|
||||
} as any);
|
||||
}
|
||||
}
|
||||
|
||||
requestSpy({
|
||||
@@ -96,10 +112,10 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
expect(req.method).toBe('POST');
|
||||
// FIX: Use a duck-typing check for FormData to avoid environment-specific instance issues.
|
||||
expect(typeof (req.body as FormData).get).toBe('function');
|
||||
|
||||
const flyerFile = (req.body as FormData).get('flyerFile') as File;
|
||||
|
||||
const flyerFile = (req.body as FormData).get('flyerFile') as { name: string };
|
||||
const checksumValue = (req.body as FormData).get('checksum');
|
||||
|
||||
|
||||
expect(flyerFile.name).toBe('flyer.pdf');
|
||||
expect(checksumValue).toBe(checksum);
|
||||
});
|
||||
@@ -130,7 +146,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
expect(req.endpoint).toBe('check-flyer');
|
||||
expect(req.method).toBe('POST');
|
||||
expect(typeof (req.body as FormData).get).toBe('function');
|
||||
const imageFile = (req.body as FormData).get('image') as File;
|
||||
const imageFile = (req.body as FormData).get('image') as { name: string };
|
||||
expect(imageFile.name).toBe('flyer.jpg');
|
||||
});
|
||||
});
|
||||
@@ -145,7 +161,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
|
||||
expect(req.endpoint).toBe('extract-address');
|
||||
expect(typeof (req.body as FormData).get).toBe('function');
|
||||
const imageFile = (req.body as FormData).get('image') as File;
|
||||
const imageFile = (req.body as FormData).get('image') as { name: string };
|
||||
expect(imageFile.name).toBe('flyer.jpg');
|
||||
});
|
||||
});
|
||||
@@ -160,7 +176,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
|
||||
expect(req.endpoint).toBe('extract-logo');
|
||||
expect(typeof (req.body as FormData).get).toBe('function');
|
||||
const imageFile = (req.body as FormData).get('images') as File;
|
||||
const imageFile = (req.body as FormData).get('images') as { name: string };
|
||||
expect(imageFile.name).toBe('logo.jpg');
|
||||
});
|
||||
});
|
||||
@@ -260,7 +276,7 @@ describe('AI API Client (Network Mocking with MSW)', () => {
|
||||
expect(req.endpoint).toBe('rescan-area');
|
||||
expect(typeof (req.body as FormData).get).toBe('function');
|
||||
|
||||
const imageFile = (req.body as FormData).get('image') as File;
|
||||
const imageFile = (req.body as FormData).get('image') as { name: string };
|
||||
const cropAreaValue = (req.body as FormData).get('cropArea');
|
||||
const extractionTypeValue = (req.body as FormData).get('extractionType');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user