Skip to content

Commit

Permalink
feat: update URL for provider settings (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Apr 11, 2023
1 parent eeb7b11 commit 5161dd3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/data/__snapshots__/redux.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
9 changes: 7 additions & 2 deletions src/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
26 changes: 19 additions & 7 deletions src/data/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5161dd3

Please sign in to comment.