I have an example endpoint, when a request is submitted to it, I do another request to a third party service which turns out to be malfunctional at times. I want to simulate this service being malfunctional so my tests can be relevant. Here is some example code
it('should handle malfunctional 3rd party service', done => {
Frisby.post(Endpoints.randomEndpoint, {
email: 'johndoe@gmail.com',
firstName: 'John',
lastName: 'Doe'
})
.expect('status', 400)
.expect('jsonTypes', Common.Types.ErrorModel)
.done(done);
});
On my server side, I have something like..
app.post('randomEndpoint', (req, res) => {
request('http://3rdpaty.com/api')
.then(data => {
res.send(200);
})
.catch(err => {
res.send(500);
})
})
My goal is tomock the response from the thrid pary service. Any ideas?
Aucun commentaire:
Enregistrer un commentaire