Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- });
- });
Add Comment
Please, Sign In to add comment