Skip to content

Instantly share code, notes, and snippets.

@abrkn
Created June 3, 2012 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abrkn/2864160 to your computer and use it in GitHub Desktop.
Save abrkn/2864160 to your computer and use it in GitHub Desktop.
stubby
describe('post /impressions/add', function() {
it('succeeds', function() {
var inputs = {
link: 'link' + Math.floor(Math.random() * 1000),
user: 'user' + Math.floor(Math.random() * 1000),
seconds: Math.floor(Math.random() * 1000)
};
var impressionsStub = sinon.stub(impressions, 'add', function(db, user, link, facts, callback) {
debug('stub add called');
expect(db).to.eql(config.db);
expect(user).to.eql(inputs.user);
expect(link).to.eql(inputs.link);
expect(facts).to.be.ok();
expect(facts.seconds).to.eql(inputs.seconds);
expect(callback).to.be.ok();
callback();
});
var handler;
var app = require('express').createServer();
sinon.stub(app, 'post', function(path, fn) {
if (path === '/api/impressions/add') {
handler = fn;
}
});
// should call app.post to configure the handler
impressions.configure(app, undefined, config);
expect(handler).to.be.ok();
var res = { end: function(body) {
expect(body).to.eql({});
}};
var resSpy = sinon.spy(res, 'end');
handler({
session: { user: { _id: inputs.user } },
body: { link: inputs.link, seconds: inputs.seconds }
}, res);
resSpy.calledWith({});
impressionsStub.restore();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment