Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. 'use strict';
  2.  
  3. let expect = require('chai').expect;
  4. let assert = require('chai').assert;
  5. let should = require('chai').should();
  6.  
  7. let sinon = require('sinon');
  8.  
  9.  
  10. describe('paging', () => {
  11. context('correct logic', () => {
  12. it('should try to save cache only once', () => {
  13. let cache = require('../lib/cache');
  14. let paging = require('../lib/paging');
  15. let cacheMock = sinon.mock(cache);
  16. cacheMock.expects('put').withArgs('paging').once();
  17.  
  18. let result = paging(100, 10, 3, cache);
  19.  
  20. cacheMock.verify();
  21. });
  22.  
  23. it('should return correct values on page 1', () => {
  24.  
  25. let cache = {
  26. put: sinon.fake.returns(true),
  27. has: sinon.fake.returns(false)
  28. }
  29.  
  30. let paging = require('../lib/paging');
  31. let result = paging(100, 10, 3, cache);
  32.  
  33. expect(result).to.be.an('array');
  34.  
  35. let labels = result.map((item) => {
  36. return item.label;
  37. });
  38.  
  39. expect(labels).to.have.ordered.members([1,2,3,4,9,10]);
  40. });
  41.  
  42. it('should call logger', () => {
  43. let cache = require('../lib/cache');
  44. let paging = require('../lib/paging');
  45.  
  46. sinon.stub(cache,'put').returns(true);
  47. sinon.stub(cache,'has').withArgs('paging').returns(false);
  48.  
  49. let result = paging(100, 10, 3, cache);
  50.  
  51. expect(cache.put.called).to.be.equal(true);
  52.  
  53. sinon.restore();
  54. });
  55. });
  56. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement