Skip to content

Commit

Permalink
fix: exam id logging (#56)
Browse files Browse the repository at this point in the history
* fix: fix nonexistent exam id property

* test: test ping failure
  • Loading branch information
zacharis278 authored Jan 13, 2022
1 parent 342a551 commit d0b35e7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
35 changes: 34 additions & 1 deletion src/data/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jest.mock('./messages/handlers', () => ({
...jest.requireActual('./messages/handlers'),
createWorker: jest.fn(),
workerPromiseForEventNames: jest.fn(() => mockPromise),
pingApplication: jest.fn(() => mockPromise()),
}));

describe('Data layer integration tests', () => {
Expand Down Expand Up @@ -547,8 +548,9 @@ describe('Data layer integration tests', () => {
await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch);
await executeThunk(thunks.startProctoredExam(), store.dispatch, store.getState);
expect(loggingService.logError).toHaveBeenCalledWith(
Error('test error'), {
'test error', {
attemptId: createdWorkerAttempt.attempt_id,
attemptStatus: createdWorkerAttempt.attempt_status,
courseId: createdWorkerAttempt.course_id,
examId: createdWorkerExam.id,
},
Expand Down Expand Up @@ -632,4 +634,35 @@ describe('Data layer integration tests', () => {
expect(state.examState.apiErrorMsg).toBe('Network Error');
});
});

describe('Test pingAttempt', () => {
it('Should send attempt to error state on ping failure', async () => {
const startedWorkerAttempt = Factory.build(
'attempt', { attempt_status: ExamStatus.STARTED, desktop_application_js_url: 'http://proctortest.com' },
);
const startedWorkerExam = Factory.build('exam', { attempt: startedWorkerAttempt });
axiosMock.onGet(fetchExamAttemptsDataUrl).reply(
200, { exam: startedWorkerExam, active_attempt: startedWorkerAttempt },
);
axiosMock.onPut(updateAttemptStatusUrl).reply(200, { exam_attempt_id: startedWorkerAttempt.attempt_id });

await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch);
await executeThunk(thunks.pingAttempt(), store.dispatch, store.getState);

expect(loggingService.logError).toHaveBeenCalledWith(
'test error', {
attemptId: startedWorkerAttempt.attempt_id,
attemptStatus: startedWorkerAttempt.attempt_status,
courseId: startedWorkerAttempt.course_id,
examId: startedWorkerExam.id,
},
);
const request = axiosMock.history.put[0];
expect(request.url).toEqual(updateAttemptStatusUrl);
expect(request.data).toEqual(JSON.stringify({
action: 'error',
detail: 'test error',
}));
});
});
});
28 changes: 17 additions & 11 deletions src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ export function startProctoredExam() {
exam.course_id, exam.content_id, continueAttempt(attempt.attempt_id),
)(dispatch))
.catch(error => {
if (error) {
logError(
error,
{
attemptId: attempt.attempt_id,
courseId: attempt.course_id,
examId: exam.id,
},
);
}
const message = error ? error.message : 'Worker failed to respond.';
logError(
message,
{
attemptId: attempt.attempt_id,
attemptStatus: attempt.attempt_status,
courseId: attempt.course_id,
examId: exam.id,
},
);
handleAPIError(
{ message: 'Something has gone wrong starting your exam. Please double-check that the application is running.' },
dispatch,
Expand Down Expand Up @@ -385,12 +385,18 @@ export function pingAttempt(timeoutInSeconds, workerUrl) {
.catch(async (error) => {
const { exam, activeAttempt } = getState().examState;
const message = error ? error.message : 'Worker failed to respond.';
/**
* Note: The exam id logged here represents the current section being rendered.
* This may be different from the exam they are currently attempting
* if the learner has navigated to other course content during the exam.
* */
logError(
message,
{
attemptId: activeAttempt.attempt_id,
attemptStatus: activeAttempt.attempt_status,
courseId: activeAttempt.course_id,
examId: activeAttempt.exam.id,
examId: exam.id,
},
);
await updateAttemptAfter(
Expand Down

0 comments on commit d0b35e7

Please sign in to comment.