Skip to content

Instantly share code, notes, and snippets.

@abrkn abrkn/gist:2864160
Created Jun 3, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.