Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct exam entry check not called #147

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
rijuma marked this conversation as resolved.
Show resolved Hide resolved
}
} 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
Loading