feat(api-server): endpoint for classroom mode flag (#51708)

This commit is contained in:
Mrugesh Mohapatra
2023-10-11 14:30:50 +05:30
committed by GitHub
parent dd05517242
commit 3ce08ba8aa
4 changed files with 49 additions and 2 deletions

View File

@@ -110,6 +110,10 @@
"type": "boolean",
"default": false
},
"isClassroomAccount": {
"type": "boolean",
"default": false
},
"currentChallengeId": {
"type": "string",
"description": "The challenge last visited by the user",

View File

@@ -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',

View File

@@ -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);
});
});
});

View File

@@ -739,7 +739,8 @@
"err-4": "Something went wrong trying to verify your trophy. Please check and try again.",
"verified": "Your trophy from Microsoft's learning platform was verified."
}
}
},
"classroom-mode-updated": "We have updated your classroom mode settings"
},
"validation": {
"max-characters": "There is a maximum limit of 288 characters, you have {{charsLeft}} left",