-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor upload thunk, no progress bar (#894)
* feat: add progress bar for video uploads and refactor --------- Co-authored-by: Kristin Aoki <[email protected]>
- Loading branch information
1 parent
6baec5b
commit a88a88e
Showing
10 changed files
with
174 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { addVideoFile } from './thunks'; | ||
import * as api from './api'; | ||
|
||
describe('addVideoFile', () => { | ||
const dispatch = jest.fn(); | ||
const getState = jest.fn(); | ||
const courseId = 'course-123'; | ||
const mockFile = { | ||
name: 'mockName', | ||
|
||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('Should dispatch failed status and set error if url cannot be created.', async () => { | ||
jest.spyOn(api, 'addVideo').mockResolvedValue({ | ||
status: 404, | ||
}); | ||
|
||
await addVideoFile(courseId, mockFile)(dispatch, getState); | ||
|
||
expect(dispatch).toHaveBeenCalledWith({ | ||
payload: { | ||
error: 'add', | ||
message: `Failed to upload ${mockFile.name}.`, | ||
}, | ||
|
||
type: 'videos/updateErrors', | ||
}); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
payload: { | ||
editType: 'add', | ||
status: 'failed', | ||
}, | ||
type: 'videos/updateEditStatus', | ||
}); | ||
}); | ||
it('Failed video upload dispatches updateEditStatus with failed, and sends the failure to the api', async () => { | ||
const videoStatusMock = jest.spyOn(api, 'sendVideoUploadStatus').mockResolvedValue({ | ||
status: 200, | ||
}); | ||
const mockEdxVideoId = 'iD'; | ||
jest.spyOn(api, 'addVideo').mockResolvedValue({ | ||
status: 200, | ||
data: { | ||
files: [ | ||
{ edxVideoId: mockEdxVideoId, uploadUrl: 'a Url' }, | ||
], | ||
}, | ||
}); | ||
jest.spyOn(api, 'uploadVideo').mockResolvedValue({ | ||
status: 404, | ||
}); | ||
await addVideoFile(courseId, mockFile)(dispatch, getState); | ||
expect(videoStatusMock).toHaveBeenCalledWith(courseId, mockEdxVideoId, 'Upload failed', 'upload_failed'); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
payload: { | ||
editType: 'add', | ||
status: 'failed', | ||
}, | ||
type: 'videos/updateEditStatus', | ||
}); | ||
}); | ||
it('Successful video upload sends the success to the api', async () => { | ||
const videoStatusMock = jest.spyOn(api, 'sendVideoUploadStatus').mockResolvedValue({ | ||
status: 200, | ||
}); | ||
const mockEdxVideoId = 'iD'; | ||
jest.spyOn(api, 'addVideo').mockResolvedValue({ | ||
status: 200, | ||
data: { | ||
files: [ | ||
{ edxVideoId: mockEdxVideoId, uploadUrl: 'a Url' }, | ||
], | ||
}, | ||
}); | ||
jest.spyOn(api, 'uploadVideo').mockResolvedValue({ | ||
status: 200, | ||
}); | ||
await addVideoFile(courseId, mockFile)(dispatch, getState); | ||
expect(videoStatusMock).toHaveBeenCalledWith(courseId, mockEdxVideoId, 'Upload completed', 'upload_completed'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters