Skip to content

Commit

Permalink
fix: test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperhodge committed Jan 6, 2025
1 parent 2436706 commit 80a5a5a
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/optimizer-page/data/thunks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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'));
Expand All @@ -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
Expand All @@ -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({
Expand Down

0 comments on commit 80a5a5a

Please sign in to comment.