Open
Description
Here is the route I want to test:
app.post('/api/user', (req, res) => {
dbService.replaceUserOnDuplicate(req.body, function returnResponse(insertedId) {
if (insertedId === 0 || insertedId === req.body.id) {
return res.sendStatus(200);
}
// TODO_MINH: Send an appropriate error to handle by the front-end
return res.send({});
});
});
I can use chai-http to do something like this (psuedo-code):
it('test', function (done) {
chai.request(server)
.post('/api/user')
.send({ user: SomeUserObject })
.end(function (err, res) {
res.should.have.status(200);
done();
});
});
However, the api/users route makes a Database call. How would I use sinon to stub this method (replaceUserOnDuplicate) so that it returns a dummy response (like 0, or anything)?
Is it possible? I'm looking at the Chai-HTTP syntax and I see no room to insert any Sinon stubbed methods.
Thanks for your help!
Metadata
Metadata
Assignees
Labels
No labels