Created
June 3, 2012 17:00
-
-
Save abrkn/2864160 to your computer and use it in GitHub Desktop.
stubby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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