Guest User

Untitled

a guest
Oct 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. describe('post /impressions/add', function() {
  2. it('succeeds', function() {
  3. var inputs = {
  4. link: 'link' + Math.floor(Math.random() * 1000),
  5. user: 'user' + Math.floor(Math.random() * 1000),
  6. seconds: Math.floor(Math.random() * 1000)
  7. };
  8.  
  9. var impressionsStub = sinon.stub(impressions, 'add', function(db, user, link, facts, callback) {
  10. debug('stub add called');
  11. expect(db).to.eql(config.db);
  12. expect(user).to.eql(inputs.user);
  13. expect(link).to.eql(inputs.link);
  14. expect(facts).to.be.ok();
  15. expect(facts.seconds).to.eql(inputs.seconds);
  16. expect(callback).to.be.ok();
  17. callback();
  18. });
  19.  
  20. var handler;
  21. var app = require('express').createServer();
  22. sinon.stub(app, 'post', function(path, fn) {
  23. if (path === '/api/impressions/add') {
  24. handler = fn;
  25. }
  26. });
  27.  
  28. // should call app.post to configure the handler
  29. impressions.configure(app, undefined, config);
  30. expect(handler).to.be.ok();
  31.  
  32. var res = { end: function(body) {
  33. expect(body).to.eql({});
  34. }};
  35. var resSpy = sinon.spy(res, 'end');
  36.  
  37. handler({
  38. session: { user: { _id: inputs.user } },
  39. body: { link: inputs.link, seconds: inputs.seconds }
  40. }, res);
  41.  
  42. resSpy.calledWith({});
  43. impressionsStub.restore();
  44. });
  45. });
Add Comment
Please, Sign In to add comment