Skip to content

Commit

Permalink
feat: allow staff users to bypass exam interstitials (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharis278 authored Aug 4, 2021
1 parent 4e4f35a commit 4cb25ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/exam/ExamWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import ExamStateContext from '../context';
const ExamWrapper = ({ children, ...props }) => {
const state = useContext(ExamStateContext);
const { authenticatedUser } = useContext(AppContext);
const { sequence, courseId } = props;
const { sequence, courseId, isStaff } = props;
const { getExamAttemptsData, getAllowProctoringOptOut } = state;
const loadInitialData = async () => {
await getExamAttemptsData(courseId, sequence.id);
await getAllowProctoringOptOut(sequence.allowProctoringOptOut);
};

// if the user is browsing public content (not logged in) they cannot be in an exam
// if the user is staff they may view exam content without an exam attempt
// any requests for exam state will 403 so just short circuit this component here
if (!authenticatedUser) {
if (!authenticatedUser || isStaff) {
return children;
}

Expand All @@ -42,6 +43,11 @@ ExamWrapper.propTypes = {
}).isRequired,
courseId: PropTypes.string.isRequired,
children: PropTypes.element.isRequired,
isStaff: PropTypes.bool,
};

ExamWrapper.defaultProps = {
isStaff: false,
};

export default ExamWrapper;
21 changes: 20 additions & 1 deletion src/exam/ExamWrapper.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('SequenceExamWrapper', () => {
};
const courseId = 'course-v1:test+test+test';

it('is successfully rendered and shows instructions', () => {
it('is successfully rendered and shows instructions if the user is not staff', () => {
store.getState = () => ({
examState: Factory.build('examState'),
});
Expand Down Expand Up @@ -121,4 +121,23 @@ describe('SequenceExamWrapper', () => {
);
expect(getByTestId('sequence-content')).toHaveTextContent('children');
});

it('renders exam content without an active attempt if the user is staff', () => {
store.getState = () => ({
examState: Factory.build('examState', {
exam: Factory.build('exam', {
type: ExamType.PROCTORED,
}),
}),
});
const { queryByTestId } = render(
<ExamStateProvider>
<SequenceExamWrapper sequence={sequence} courseId={courseId} isStaff>
<div data-testid="sequence-content">children</div>
</SequenceExamWrapper>
</ExamStateProvider>,
{ store },
);
expect(queryByTestId('sequence-content')).toHaveTextContent('children');
});
});

0 comments on commit 4cb25ea

Please sign in to comment.