Skip to content

Commit

Permalink
fix: pass sequenceId to api call (#139)
Browse files Browse the repository at this point in the history
* fix: pass sequenceId to api call

* test: tests pass, cleaning now

* chore: lint

* chore: update test snapshot

* test: corrected snapshot handling timer_ends
  • Loading branch information
ilee2u authored Mar 11, 2024
1 parent ab01003 commit 52826e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/data/__snapshots__/redux.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<String>,
"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,
Expand All @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions src/data/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, {
Expand Down
5 changes: 4 additions & 1 deletion src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down

0 comments on commit 52826e0

Please sign in to comment.