fix: video upload api fetch body (#454)

This commit is contained in:
Kristin Aoki
2024-01-10 17:13:29 -05:00
committed by GitHub
parent 13f039ae4c
commit 4653322fca
2 changed files with 13 additions and 7 deletions

View File

@@ -411,16 +411,22 @@ export const uploadVideo = ({ supportedFiles, setLoadSpinner, postUploadRedirect
console.error(`Could not find file object with name "${fileName}" in supportedFiles array.`);
return;
}
const formData = new FormData();
formData.append('uploaded-file', uploadFile.get('file'));
const file = uploadFile.get('file');
await fetch(uploadUrl, {
method: 'PUT',
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
'Content-Disposition': `attachment; filename="${file.name}"`,
'Content-Type': file.type,
},
multipart: false,
body: file,
})
.then(() => postUploadRedirect(edxVideoId))
.then((resp) => {
if (!resp.ok) {
throw new Error('Failed to connect with server');
}
postUploadRedirect(edxVideoId);
})
// eslint-disable-next-line no-console
.catch((error) => console.error('Error uploading file:', error));
}));

View File

@@ -760,7 +760,7 @@ describe('uploadVideo', () => {
it('should call fetch with correct arguments for each file', async () => {
const mockResponseData = { success: true };
const mockFetchResponse = Promise.resolve({ data: mockResponseData });
const mockFetchResponse = Promise.resolve({ data: mockResponseData, ok: true });
global.fetch = jest.fn().mockImplementation(() => mockFetchResponse);
const response = {
files: [
@@ -779,7 +779,7 @@ describe('uploadVideo', () => {
});
supportedFiles.forEach((file, index) => {
const fileDataTest = file.get('file');
expect(fetch.mock.calls[index][1].body.get('uploaded-file')).toBe(fileDataTest);
expect(fetch.mock.calls[index][1].body).toBe(fileDataTest);
});
});