Skip to content

Commit

Permalink
fix: video upload api fetch body (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinAoki authored Jan 10, 2024
1 parent 13f039a commit 4653322
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/editors/data/redux/thunkActions/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}));
Expand Down
4 changes: 2 additions & 2 deletions src/editors/data/redux/thunkActions/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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);
});
});

Expand Down

0 comments on commit 4653322

Please sign in to comment.