Created
June 13, 2021 00:37
-
-
Save ahayes91/72e23f76ea795b4c0cd2dd56ad104c9b to your computer and use it in GitHub Desktop.
Snippet to show how you can emulate server-side logic in a Mock Service Worker handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rest.post(`/assignment`, async (req, res, ctx) => { | |
// The newly created assignment in this test should have only 1 class and 3 students assigned | |
const numberOfClassesAssigned = req.body.assignments.length; | |
const numberOfStudentsAssigned = req.body.assignments[0].students.length; | |
if (numberOfClassesAssigned === 1 && numberOfStudentsAssigned === 3) { | |
return res( | |
ctx.status(200), | |
ctx.json({ assignments: [{ refId: 'mockRefId' }] }), | |
); | |
} | |
return res(ctx.status(404)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment