using nodejs, mocha, chai and sinon i would like to stub a function that is called in a route
<p>I have a pretty simple app that is nodejs, express and mysql
I am new to unit testing and i think this app is a great way to do better.
what i am trying to accomplish ( and i think sinon is the answer) is to mock or stub <em>mysql.insertEventIntoDB</em> and <em>rabbit.addToRabbitMQ</em></p>

<p>in my app i have </p>

<pre><code>app.use('/sendgrid', sendgrid(pool, config, logger) );
</code></pre>

<p>in my sendgrid.js i have</p>

<pre><code>var express = require('express');
var mysql = require('../app/utils/mysql');
var rabbit = require('../app/utils/rabbitMQ');

module.exports = function (dbpool, config, logger) {
  var router = express.Router();

  router.post('/callback', function (req, res) {
    for (var x=0 ; x &lt; req.body.length ; x++ ){
       mysql.insertEventIntoDB(dbpool, req.body[x], logger);
       rabbit.addToRabbitMQ(config,req.body[x], logger)
    }
    res.json({ status: 'OK' });
  });

  return router;
}
</code></pre>

<p>i have seen lots of example of stubs and spys but just can not figure out how to do it from these test. this is an example of one of my tests</p>

<pre><code>it('should get an OK for delivered POST', function(done) {
 chai.request(server)
  .post('/sendgrid/callback')
  .send(delivered)
  .end(function(err, res){
    res.should.have.status(200);
    res.should.be.json;
    res.body.should.be.a('object');
    res.body.should.have.property('status');
    res.body.status.should.equal('OK');
    done();
  });
 });
</code></pre>

<p>thanks for any help/direction</p>