From 52826e0bf4869bb9ddc8aafaf53f429b28209992 Mon Sep 17 00:00:00 2001 From: Isaac Lee <124631592+ilee2u@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:30:29 -0400 Subject: [PATCH] fix: pass sequenceId to api call (#139) * fix: pass sequenceId to api call * test: tests pass, cleaning now * chore: lint * chore: update test snapshot * test: corrected snapshot handling timer_ends --- src/data/__snapshots__/redux.test.jsx.snap | 8 ++++---- src/data/redux.test.jsx | 21 +++++++++++++++------ src/data/thunks.js | 5 ++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/data/__snapshots__/redux.test.jsx.snap b/src/data/__snapshots__/redux.test.jsx.snap index b20f2915..0e6a6348 100644 --- a/src/data/__snapshots__/redux.test.jsx.snap +++ b/src/data/__snapshots__/redux.test.jsx.snap @@ -188,7 +188,7 @@ Object { } `; -exports[`Data layer integration tests Test pollAttempt Should poll and update active attempt 1`] = ` +exports[`Data layer integration tests Test pollAttempt Should poll and update active attempt with new proctoring backend 1`] = ` Object { "attempt_code": "", "attempt_id": 1, @@ -202,13 +202,13 @@ Object { "in_timed_exam": true, "software_download_url": "", "taking_as_proctored": false, - "time_remaining_seconds": 1799.9, + "time_remaining_seconds": 1739.9, "timer_ends": Any, "total_time": "30 minutes", } `; -exports[`Data layer integration tests Test pollAttempt with edx-proctoring as a backend (no EXAMS_BASE_URL) Should poll and update active attempt 1`] = ` +exports[`Data layer integration tests Test pollAttempt with edx-proctoring as a backend (no EXAMS_BASE_URL) Should poll and update active attempt with legacy proctoring backend 1`] = ` Object { "attempt_code": "", "attempt_id": 1, @@ -227,7 +227,7 @@ Object { } `; -exports[`Data layer integration tests Test pollAttempt with edx-proctoring as a backend (no EXAMS_BASE_URL) Should poll and update active attempt 2`] = ` +exports[`Data layer integration tests Test pollAttempt with edx-proctoring as a backend (no EXAMS_BASE_URL) Should poll and update active attempt with legacy proctoring backend 2`] = ` Object { "attempt_code": "", "attempt_id": 1, diff --git a/src/data/redux.test.jsx b/src/data/redux.test.jsx index ba86b702..bffa0cde 100644 --- a/src/data/redux.test.jsx +++ b/src/data/redux.test.jsx @@ -925,7 +925,7 @@ describe('Data layer integration tests', () => { mergeConfig({ EXAMS_BASE_URL: null }); }); - it('Should poll and update active attempt', async () => { + it('Should poll and update active attempt with legacy proctoring backend', async () => { axiosMock.onGet(fetchExamAttemptsDataLegacyUrl).replyOnce(200, { exam, active_attempt: attempt }); axiosMock.onGet(pollExamAttemptUrl).reply(200, { time_remaining_seconds: 1739.9, @@ -945,22 +945,31 @@ describe('Data layer integration tests', () => { }); }); - it('Should poll and update active attempt', async () => { + it('Should poll and update active attempt with new proctoring backend', async () => { await initWithExamAttempt(exam, attempt); + // Reset history so we can get url at index 0 later + axiosMock.resetHistory(); - axiosMock.onGet(latestAttemptURL).reply(200, { + const attemptToPollURL = `${latestAttemptURL}?content_id=block-v1%3Atest%2Bspecial%2Bexam%2Btype%40sequential%2Bblock%40abc123`; + axiosMock.onGet(attemptToPollURL).reply(200, { time_remaining_seconds: 1739.9, accessibility_time_string: 'you have 29 minutes remaining', attempt_status: ExamStatus.STARTED, }); - await executeThunk(thunks.pollAttempt(attempt.exam_started_poll_url), store.dispatch, store.getState); + // Make sure the thunk eventually calls the right URL + await executeThunk(thunks.pollAttempt(null, exam.content_id), store.dispatch, store.getState); const state = store.getState(); - expectSpecialExamAttemptToMatchSnapshot(state.specialExams.activeAttempt); + expect(axiosMock.history.get[0].url).toEqual(attemptToPollURL); + expect(state.specialExams.activeAttempt).toMatchSnapshot({ + // Allow for the timer_ends value to be any string, as it varies by milliseconds depending + // on how fast this test runs just about every time. + timer_ends: expect.any(String), + }); }); describe('pollAttempt api called directly', () => { - // in the download view we call this function directly withough invoking the wrapping thunk + // in the download view we call this function directly without invoking the wrapping thunk it('should call pollUrl if one is provided', async () => { const pollExamAttemptUrl = `${getConfig().LMS_BASE_URL}${attempt.exam_started_poll_url}`; axiosMock.onGet(pollExamAttemptUrl).reply(200, { diff --git a/src/data/thunks.js b/src/data/thunks.js index 8a5e39f0..c0628b7f 100644 --- a/src/data/thunks.js +++ b/src/data/thunks.js @@ -271,7 +271,10 @@ export function pollAttempt(url) { } try { - const data = await pollExamAttempt(url); + // TODO: make sure sequenceId pulled here is correct both in-exam-sequence and in outline + // test w/ timed exam + const { exam } = getState().specialExams; + const data = await pollExamAttempt(url, exam.content_id); if (!data) { throw new Error('Poll Exam failed to fetch.'); }