Skip to content

Commit

Permalink
feat: use lti for exam end (#117)
Browse files Browse the repository at this point in the history
* feat: remove temp end exam message

* feat: single tab lti flow
  • Loading branch information
zacharis278 authored Sep 19, 2023
1 parent d09716c commit 27dd196
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
7 changes: 0 additions & 7 deletions src/data/messages/proctorio.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,3 @@ export function notifyStartExam() {
'*', // this isn't emitting secure data so any origin is fine
);
}

export function notifyEndExam() {
window.top.postMessage(
['exam_state_change', 'exam_end'],
'*', // this isn't emitting secure data so any origin is fine
);
}
15 changes: 0 additions & 15 deletions src/data/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -582,21 +582,6 @@ describe('Data layer integration tests', () => {
await executeThunk(thunks.submitExam(), store.dispatch, store.getState);
expect(axiosMock.history.put[0].url).toEqual(updateAttemptStatusLegacyUrl);
});

it('Should notify top window on LTI exam end', async () => {
const mockPostMessage = jest.fn();
windowSpy.mockImplementation(() => ({
top: {
postMessage: mockPostMessage,
},
}));

await initWithExamAttempt();
axiosMock.onGet(fetchExamAttemptsDataUrl).reply(200, { exam: submittedExam });
axiosMock.onPut(`${createUpdateAttemptURL}/${attempt.attempt_id}`).reply(200, { exam_attempt_id: submittedAttempt.attempt_id });
await executeThunk(thunks.submitExam(), store.dispatch, store.getState);
expect(mockPostMessage).toHaveBeenCalledWith(['exam_state_change', 'exam_end'], '*');
});
});

describe('Test expireExam', () => {
Expand Down
6 changes: 1 addition & 5 deletions src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { ExamStatus, ExamType, IS_PROCTORED_STATUS } from '../constants';
import { workerPromiseForEventNames, pingApplication } from './messages/handlers';
import actionToMessageTypesMap from './messages/constants';
import { checkAppStatus, notifyEndExam, notifyStartExam } from './messages/proctorio';
import { checkAppStatus, notifyStartExam } from './messages/proctorio';

function handleAPIError(error, dispatch) {
const { message, detail } = error;
Expand Down Expand Up @@ -364,7 +364,6 @@ export function submitExam() {
const { exam, activeAttempt } = getState().examState;
const { desktop_application_js_url: workerUrl, external_id: attemptExternalId } = activeAttempt || {};
const useWorker = window.Worker && activeAttempt && workerUrl;
const examHasLtiProvider = !exam.useLegacyAttemptApi;

const handleBackendProviderSubmission = () => {
// if a backend provider is being used during the exam
Expand All @@ -376,9 +375,6 @@ export function submitExam() {
dispatch,
));
}
if (examHasLtiProvider) {
notifyEndExam();
}
};

if (!activeAttempt) {
Expand Down
13 changes: 10 additions & 3 deletions src/instructions/proctored_exam/ProctoredExamInstructions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ describe('SequenceExamWrapper', () => {
});

it('Initiates an LTI launch in a new window when the user clicks the submit button', async () => {
const windowSpy = jest.spyOn(window, 'open');
windowSpy.mockImplementation(() => ({}));
const { location } = window;
delete window.location;
const mockAssign = jest.fn();
window.location = {
assign: mockAssign,
};
const attempt = Factory.build('attempt', {
attempt_status: ExamStatus.READY_TO_SUBMIT,
use_legacy_attempt_api: false,
Expand Down Expand Up @@ -226,7 +230,10 @@ describe('SequenceExamWrapper', () => {

expect(queryByTestId('proctored-exam-instructions-title')).toHaveTextContent('Are you sure you want to end your proctored exam?');
fireEvent.click(queryByTestId('end-exam-button'));
await waitFor(() => { expect(windowSpy).toHaveBeenCalledWith('http://localhost:18740/lti/end_assessment/1', '_blank'); });
await waitFor(() => { expect(mockAssign).toHaveBeenCalledWith('http://localhost:18740/lti/end_assessment/1'); });

// restore window.location
window.location = location;
});

it('Instructions are shown when attempt status is verified', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SubmitProctoredExamInstructions = () => {

const handleSubmitClick = () => {
if (examHasLtiProvider) {
window.open(submitLtiAttemptUrl, '_blank');
window.location.assign(submitLtiAttemptUrl);
}
submitExam();
};
Expand Down

0 comments on commit 27dd196

Please sign in to comment.