I have a simple express route that GETs a user from mongo
routes.js
router.get('/users/:username', userController.read);
user.controller.js
function read(req, res) {
User.findOne({
username: req.params.username
}, function(err, user) {
if (err) res.status(404).json(err);
res.status(200).json(user);
});
}
I ran some tests through Postman and supertest
here's the supertest call
it('should retrieve user data', function(done) {
request(BASE_URL)
.get('/users/' + testUserData.username)
.expect(200)
.expect({
username: testUserData.username,
email: testUserData.email
}, done)
})
The user's data comes back fine but the status code is 201 instead of 200.