title: NodeJS Mock 3rd party service
body: <p>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</p>
  
  <pre><code>it('should handle malfunctional 3rd party service', done =&gt; {
    Frisby.post(Endpoints.randomEndpoint, {
      email: 'johndoe@gmail.com',
      firstName: 'John',
      lastName: 'Doe'
    })
    .expect('status', 400)
    .expect('jsonTypes', Common.Types.ErrorModel)
    .done(done);
  });
  </code></pre>
  
  <p>On my server side, I have something like..</p>
  
  <pre><code>app.post('randomEndpoint', (req, res) =&gt; {
    request('http://3rdpaty.com/api')
      .then(data =&gt; {
        res.send(200);
      })
      .catch(err =&gt; {
        res.send(500);
      })
  })
  </code></pre>
  
  <p>My goal is tomock the response from the thrid pary service. Any ideas?</p>