annoy.spec.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const { expect } = require('chai');
  2. const itEach = require('it-each');
  3. const moment = require('moment');
  4. const {
  5. getPreviousWeekPeriod
  6. } = require('server/routes/annoy');
  7. describe('Annoy route', () => {
  8. describe('getPreviousWeekPeriod', () => {
  9. itEach();
  10. it.each([
  11. {
  12. key: 'Monday-1',
  13. now: '2019-01-14T06:00Z',
  14. start: '2019-01-07T00:00:00.000Z',
  15. end: '2019-01-13T23:59:59.999Z'
  16. },
  17. {
  18. key: 'Tuesday-1',
  19. now: '2019-01-15T06:00Z',
  20. start: '2019-01-07T00:00:00.000Z',
  21. end: '2019-01-13T23:59:59.999Z'
  22. },
  23. {
  24. key: 'Wednesday-1',
  25. now: '2019-01-16T06:00Z',
  26. start: '2019-01-07T00:00:00.000Z',
  27. end: '2019-01-13T23:59:59.999Z'
  28. },
  29. {
  30. key: 'Thursday-1',
  31. now: '2019-01-17T06:00Z',
  32. start: '2019-01-07T00:00:00.000Z',
  33. end: '2019-01-13T23:59:59.999Z'
  34. },
  35. {
  36. key: 'Friday-1',
  37. now: '2019-01-18T06:00Z',
  38. start: '2019-01-07T00:00:00.000Z',
  39. end: '2019-01-13T23:59:59.999Z'
  40. },
  41. {
  42. key: 'Saturday-1',
  43. now: '2019-01-19T06:00Z',
  44. start: '2019-01-07T00:00:00.000Z',
  45. end: '2019-01-13T23:59:59.999Z'
  46. },
  47. {
  48. key: 'Sunday-1',
  49. now: '2019-01-20T06:00Z',
  50. start: '2019-01-07T00:00:00.000Z',
  51. end: '2019-01-13T23:59:59.999Z'
  52. },
  53. {
  54. key: 'Monday-2',
  55. now: '2019-01-21T06:00Z',
  56. start: '2019-01-14T00:00:00.000Z',
  57. end: '2019-01-20T23:59:59.999Z'
  58. },
  59. {
  60. key: 'Tuesday-2',
  61. now: '2019-01-21T06:00Z',
  62. start: '2019-01-14T00:00:00.000Z',
  63. end: '2019-01-20T23:59:59.999Z'
  64. }
  65. ], 'should fetch the start and end of the previous working week', ({ now, start, end }) => {
  66. const {
  67. start: startResult,
  68. end: endResult
  69. } = getPreviousWeekPeriod(moment(now));
  70. expect(startResult.toISOString()).to.equal(start);
  71. expect(endResult.toISOString()).to.equal(end);
  72. });
  73. });
  74. });