diff --git a/src/optimizer-page/data/thunks.test.js b/src/optimizer-page/data/thunks.test.js index e524fbdbe..208b8f452 100644 --- a/src/optimizer-page/data/thunks.test.js +++ b/src/optimizer-page/data/thunks.test.js @@ -68,11 +68,16 @@ describe('startLinkCheck thunk', () => { }); describe('fetchLinkCheckStatus thunk', () => { + const dispatch = jest.fn(); + const getState = jest.fn(); + const courseId = 'course-123'; + + beforeEach(() => { + jest.clearAllMocks(); + }); + describe('successful request', () => { it('should return scan result', async () => { - const dispatch = jest.fn(); - const getState = jest.fn(); - const courseId = 'course-123'; jest .spyOn(api, 'getLinkCheckStatus') .mockResolvedValue({ @@ -103,13 +108,25 @@ describe('fetchLinkCheckStatus thunk', () => { type: 'courseOptimizer/updateLoadingStatus', }); }); + + it('with link check in progress should set current stage to 1', async () => { + jest + .spyOn(api, 'getLinkCheckStatus') + .mockResolvedValue({ + linkCheckStatus: LINK_CHECK_STATUSES.IN_PROGRESS, + }); + + await fetchLinkCheckStatus(courseId)(dispatch, getState); + + expect(dispatch).toHaveBeenCalledWith({ + payload: 1, + type: 'courseOptimizer/updateCurrentStage', + }); + }); }); describe('failed request', () => { it('should set request status to failed', async () => { - const dispatch = jest.fn(); - const getState = jest.fn(); - const courseId = 'course-123'; jest .spyOn(api, 'getLinkCheckStatus') .mockRejectedValue(new Error('error')); @@ -123,6 +140,18 @@ describe('fetchLinkCheckStatus thunk', () => { }); }); + describe('unauthorized request', () => { + it('should set request status to denied', async () => { + jest.spyOn(api, 'getLinkCheckStatus').mockRejectedValue({ response: { status: 403 } }); + await fetchLinkCheckStatus(courseId)(dispatch, getState); + + expect(dispatch).toHaveBeenCalledWith({ + payload: { status: RequestStatus.DENIED }, + type: 'courseOptimizer/updateLoadingStatus', + }); + }); + }); + describe('failed scan', () => { it('should set error message', async () => { jest @@ -133,10 +162,6 @@ describe('fetchLinkCheckStatus thunk', () => { linkCheckCreatedAt: mockApiResponse.LinkCheckCreatedAt, }); - const dispatch = jest.fn(); - const getState = jest.fn(); - const courseId = 'course-123'; - await fetchLinkCheckStatus(courseId)(dispatch, getState); expect(dispatch).toHaveBeenCalledWith({