mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-07 18:03:49 -05:00
feat(api-server): endpoint for classroom mode flag (#51708)
This commit is contained in:
committed by
GitHub
parent
dd05517242
commit
3ce08ba8aa
@@ -51,6 +51,7 @@ export default function settingsController(app) {
|
||||
);
|
||||
api.put('/update-my-honesty', ifNoUser401, updateMyHonesty);
|
||||
api.put('/update-my-quincy-email', ifNoUser401, updateMyQuincyEmail);
|
||||
api.put('/update-my-classroom-mode', ifNoUser401, updateMyClassroomMode);
|
||||
|
||||
app.use(api);
|
||||
}
|
||||
@@ -319,6 +320,17 @@ function updateMyQuincyEmail(...args) {
|
||||
)(...args);
|
||||
}
|
||||
|
||||
export function updateMyClassroomMode(...args) {
|
||||
const buildUpdate = body => _.pick(body, 'isClassroomAccount');
|
||||
const validate = ({ isClassroomAccount }) =>
|
||||
typeof isClassroomAccount === 'boolean';
|
||||
createUpdateUserProperties(
|
||||
buildUpdate,
|
||||
validate,
|
||||
'flash.classroom-mode-updated'
|
||||
)(...args);
|
||||
}
|
||||
|
||||
function handleInvalidUpdate(res) {
|
||||
res.status(403).json({
|
||||
type: 'danger',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { updateMySocials } from '../boot/settings';
|
||||
import { updateMySocials, updateMyClassroomMode } from '../boot/settings';
|
||||
|
||||
export const mockReq = opts => {
|
||||
const req = {};
|
||||
@@ -108,4 +108,34 @@ describe('boot/settings', () => {
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateMyClassroomMode', () => {
|
||||
it('does not allow invalid classroomMode', () => {
|
||||
const req = mockReq({
|
||||
user: {},
|
||||
body: {
|
||||
isClassroomAccount: 'invalid'
|
||||
}
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
updateMyClassroomMode(req, res, next);
|
||||
expect(res.status).toHaveBeenCalledWith(403);
|
||||
});
|
||||
|
||||
it('allows valid classroomMode', () => {
|
||||
const req = mockReq({
|
||||
user: {
|
||||
updateAttributes: (_, cb) => cb()
|
||||
},
|
||||
body: {
|
||||
isClassroomAccount: true
|
||||
}
|
||||
});
|
||||
const res = mockRes();
|
||||
const next = jest.fn();
|
||||
updateMyClassroomMode(req, res, next);
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user