Skip to content

Commit

Permalink
fix: correct exam entry check not called (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharis278 authored Jul 11, 2024
1 parent db51931 commit c41adcb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/data/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,27 @@ describe('Data layer integration tests', () => {
});
});

it('Should refresh exam state from backend if polled attempt has ended in error', async () => {
const errorAttempt = Factory.build('attempt', { attempt_status: ExamStatus.ERROR });
const errorExam = Factory.build('exam', { attempt: errorAttempt });

await initWithExamAttempt(exam, attempt);
const attemptToPollURL = `${latestAttemptURL}?content_id=block-v1%3Atest%2Bspecial%2Bexam%2Btype%40sequential%2Bblock%40abc123`;
axiosMock.onGet(attemptToPollURL).reply(200, {
time_remaining_seconds: 0,
accessibility_time_string: 'you have 0 minutes remaining',
attempt_status: ExamStatus.ERROR,
});
axiosMock.onGet(fetchExamAttemptsDataUrl).reply(200, { exam: errorExam, active_attempt: {} });

axiosMock.resetHistory();
await executeThunk(thunks.pollAttempt(null, exam.content_id), store.dispatch, store.getState);
const state = store.getState();
expect(axiosMock.history.get[0].url).toEqual(attemptToPollURL);
expect(axiosMock.history.get[1].url).toEqual(fetchExamAttemptsDataUrl);
expect(state.specialExams.exam.attempt.attempt_status).toBe(ExamStatus.ERROR);
});

describe('pollAttempt api called directly', () => {
// in the download view we call this function directly without invoking the wrapping thunk
it('should call pollUrl if one is provided', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ export function pollAttempt(url) {
dispatch(setActiveAttempt({
activeAttempt: updatedAttempt,
}));
if (data.status === ExamStatus.SUBMITTED) {
if ([ExamStatus.SUBMITTED, ExamStatus.ERROR].includes(data.status)) {
dispatch(expireExamAttempt());
updateAttemptAfter(exam.course_id, exam.content_id)(dispatch);
}
} catch (error) {
handleAPIError(error, dispatch);
Expand Down
4 changes: 2 additions & 2 deletions src/exam/ExamWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const ExamWrapper = ({ children, ...props }) => {

const loadInitialData = async () => {
await dispatch(getExamAttemptsData(courseId, sequence.id));
await getAllowProctoringOptOut(sequence.allowProctoringOptOut);
await checkExamEntry();
await dispatch(getAllowProctoringOptOut(sequence.allowProctoringOptOut));
await dispatch(checkExamEntry());
};

const isGated = sequence && sequence.gatedContent !== undefined && sequence.gatedContent.gated;
Expand Down

0 comments on commit c41adcb

Please sign in to comment.