diff --git a/src/data/__snapshots__/redux.test.jsx.snap b/src/data/__snapshots__/redux.test.jsx.snap index 5a994348..280ca8d6 100644 --- a/src/data/__snapshots__/redux.test.jsx.snap +++ b/src/data/__snapshots__/redux.test.jsx.snap @@ -167,6 +167,22 @@ Object { } `; +exports[`Data layer integration tests Test getProctoringSettings Test legacy URL for getProctoringSettings Should get, and save proctoringSettings 1`] = ` +Object { + "exam_proctoring_backend": Object { + "download_url": "", + "instructions": Array [], + "name": "", + "rules": Object {}, + }, + "integration_specific_email": "", + "learner_notification_from_email": "", + "provider_name": "", + "provider_tech_support_email": "", + "provider_tech_support_phone": "", +} +`; + exports[`Data layer integration tests Test pollAttempt Should poll and update active attempt 1`] = ` Object { "attempt_code": "", diff --git a/src/data/api.js b/src/data/api.js index ef27e3e1..30a19994 100644 --- a/src/data/api.js +++ b/src/data/api.js @@ -139,8 +139,13 @@ export async function fetchExamReviewPolicy(examId) { return data; } -export async function fetchProctoringSettings(examId) { - const url = new URL(`${getConfig().LMS_BASE_URL}/api/edx_proctoring/v1/proctored_exam/settings/exam_id/${examId}/`); +export async function fetchProctoringSettings(courseId, examId) { + let url; + if (!getConfig().EXAMS_BASE_URL) { + url = new URL(`${getConfig().LMS_BASE_URL}/api/edx_proctoring/v1/proctored_exam/settings/exam_id/${examId}/`); + } else { + url = new URL(`${getConfig().EXAMS_BASE_URL}/api/v1/exam/provider_settings/course_id/${courseId}/exam_id/${examId}`); + } const { data } = await getAuthenticatedHttpClient().get(url.href); return data; } diff --git a/src/data/redux.test.jsx b/src/data/redux.test.jsx index 524ed21c..6f196095 100644 --- a/src/data/redux.test.jsx +++ b/src/data/redux.test.jsx @@ -38,10 +38,12 @@ describe('Data layer integration tests', () => { + `?content_id=${encodeURIComponent(contentId)}&is_learning_mfe=true`; const updateAttemptStatusLegacyUrl = `${getConfig().LMS_BASE_URL}${BASE_API_URL}/${attempt.attempt_id}`; const createExamAttemptLegacyUrl = `${getConfig().LMS_BASE_URL}${BASE_API_URL}`; + const fetchProctoringSettingsLegacyUrl = `${getConfig().LMS_BASE_URL}/api/edx_proctoring/v1/proctored_exam/settings/exam_id/${exam.id}/`; const createUpdateAttemptURL = `${getConfig().EXAMS_BASE_URL}/api/v1/exams/attempt`; const fetchExamAttemptsDataUrl = `${getConfig().EXAMS_BASE_URL}/api/v1/student/exam/attempt/course_id/${courseId}/content_id/${contentId}`; const latestAttemptURL = `${getConfig().EXAMS_BASE_URL}/api/v1/exams/attempt/latest`; + const fetchProctoringSettingsUrl = `${getConfig().EXAMS_BASE_URL}/api/v1/exam/provider_settings/course_id/${courseId}/exam_id/${exam.id}`; let store; const initWithExamAttempt = async (testExam = exam, testAttempt = attempt) => { @@ -92,18 +94,29 @@ describe('Data layer integration tests', () => { }); describe('Test getProctoringSettings', () => { - const fetchProctoringSettingsUrl = `${getConfig().LMS_BASE_URL}/api/edx_proctoring/v1/proctored_exam/settings/exam_id/${exam.id}/`; const proctoringSettings = Factory.build('proctoringSettings'); - beforeEach(async () => { - mergeConfig({ EXAMS_BASE_URL: null }); + describe('Test legacy URL for getProctoringSettings', () => { + beforeEach(async () => { + mergeConfig({ EXAMS_BASE_URL: null }); + }); + + it('Should get, and save proctoringSettings', async () => { + axiosMock.onGet(fetchExamAttemptsDataLegacyUrl).reply(200, { exam, active_attempt: attempt }); + axiosMock.onGet(fetchProctoringSettingsLegacyUrl).reply(200, proctoringSettings); + + await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch); + await executeThunk(thunks.getProctoringSettings(), store.dispatch, store.getState); + + const state = store.getState(); + expect(state.examState.proctoringSettings).toMatchSnapshot(); + }); }); it('Should get, and save proctoringSettings', async () => { - axiosMock.onGet(fetchExamAttemptsDataLegacyUrl).reply(200, { exam, active_attempt: attempt }); + await initWithExamAttempt(); axiosMock.onGet(fetchProctoringSettingsUrl).reply(200, proctoringSettings); - await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch); await executeThunk(thunks.getProctoringSettings(), store.dispatch, store.getState); const state = store.getState(); @@ -121,10 +134,9 @@ describe('Data layer integration tests', () => { }); it('Should fail to fetch if error occurs', async () => { - axiosMock.onGet(fetchExamAttemptsDataLegacyUrl).reply(200, { exam, active_attempt: attempt }); + await initWithExamAttempt(); axiosMock.onGet(fetchProctoringSettingsUrl).networkError(); - await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch); await executeThunk(thunks.getProctoringSettings(), store.dispatch, store.getState); const state = store.getState(); diff --git a/src/data/thunks.js b/src/data/thunks.js index 4e2e36b2..e2219ed1 100644 --- a/src/data/thunks.js +++ b/src/data/thunks.js @@ -110,7 +110,7 @@ export function getProctoringSettings() { return; } try { - const proctoringSettings = await fetchProctoringSettings(exam.id); + const proctoringSettings = await fetchProctoringSettings(exam.course_id, exam.id); dispatch(setProctoringSettings({ proctoringSettings })); } catch (error) { handleAPIError(error, dispatch);