test: added test case

This commit is contained in:
sundasnoreen12
2025-05-20 18:29:06 +05:00
committed by Muhammad Faraz Maqsood
parent 44d47f8783
commit ce337aedef
3 changed files with 19 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { cloneDeep } from 'lodash';
import { closestCorners } from '@dnd-kit/core';
import { logError } from '@edx/frontend-platform/logging';
import { useLocation } from 'react-router-dom';
import userEvent from '@testing-library/user-event';
import {
@@ -22,6 +22,7 @@ import {
getCourseItemApiUrl,
getXBlockBaseApiUrl,
exportTags,
createDiscussionsTopics,
} from './data/api';
import { RequestStatus } from '../data/constants';
import {
@@ -115,6 +116,10 @@ jest.mock('../library-authoring/component-picker', () => ({
},
}));
jest.mock('@edx/frontend-platform/logging', () => ({
logError: jest.fn(),
}));
const queryClient = new QueryClient();
jest.mock('@dnd-kit/core', () => ({
@@ -192,6 +197,16 @@ describe('<CourseOutline />', () => {
});
});
it('logs an error when syncDiscussionsTopics encounters an API failure', async () => {
axiosMock
.onGet(createDiscussionsTopics(courseId))
.reply(500, 'some internal error');
await executeThunk(syncDiscussionsTopics(), store.dispatch);
expect(logError).toHaveBeenCalledTimes(1);
});
it('handles course outline fetch api errors', async () => {
axiosMock
.onGet(getCourseOutlineIndexApiUrl(courseId))

View File

@@ -3149,6 +3149,7 @@ module.exports = {
selectedGroupsLabel: '',
},
},
createdOn: new Date(),
deprecatedBlocksInfo: {
deprecatedEnabledBlockTypes: [],
blocks: [],

View File

@@ -1,3 +1,4 @@
import { logError } from '@edx/frontend-platform/logging';
import { RequestStatus } from '../../data/constants';
import { NOTIFICATION_MESSAGES } from '../../constants';
import { COURSE_BLOCK_NAMES } from '../constants';
@@ -100,8 +101,7 @@ export function syncDiscussionsTopics(courseId) {
try {
await createDiscussionsTopics(courseId);
} catch (error) {
// eslint-disable-next-line no-console
console.log('There was an issue in discussion topic sync', error);
logError(error);
}
};
}