events.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {Client} from 'app/api';
  2. import {doEventsRequest} from 'app/actionCreators/events';
  3. describe('Events ActionCreator', function() {
  4. const api = new Client();
  5. const organization = TestStubs.Organization();
  6. const project = TestStubs.Project();
  7. const opts = {
  8. organization,
  9. project: [project.id],
  10. environment: [],
  11. };
  12. let mock;
  13. beforeEach(function() {
  14. MockApiClient.clearMockResponses();
  15. mock = MockApiClient.addMockResponse({
  16. url: '/organizations/org-slug/events-stats/',
  17. body: {data: [[123, []], [123, []], [123, []], [123, []], [123, []], [123, []]]},
  18. });
  19. });
  20. it('requests events stats with relative period', function() {
  21. doEventsRequest(api, {
  22. ...opts,
  23. includePrevious: false,
  24. period: '7d',
  25. });
  26. expect(mock).toHaveBeenLastCalledWith(
  27. '/organizations/org-slug/events-stats/',
  28. expect.objectContaining({
  29. query: expect.objectContaining({
  30. project: [project.id],
  31. environment: [],
  32. statsPeriod: '7d',
  33. }),
  34. })
  35. );
  36. });
  37. it('requests events stats with relative period including previous period', function() {
  38. doEventsRequest(api, {
  39. ...opts,
  40. includePrevious: true,
  41. period: '7d',
  42. });
  43. expect(mock).toHaveBeenLastCalledWith(
  44. '/organizations/org-slug/events-stats/',
  45. expect.objectContaining({
  46. query: expect.objectContaining({
  47. project: [project.id],
  48. environment: [],
  49. statsPeriod: '14d',
  50. }),
  51. })
  52. );
  53. });
  54. it('requests events stats with absolute period', async function() {
  55. const start = new Date('2017-10-12T12:00:00.000Z');
  56. const end = new Date('2017-10-17T00:00:00.000Z');
  57. doEventsRequest(api, {
  58. ...opts,
  59. includePrevious: false,
  60. start,
  61. end,
  62. });
  63. expect(mock).toHaveBeenCalledTimes(1);
  64. expect(mock).toHaveBeenLastCalledWith(
  65. '/organizations/org-slug/events-stats/',
  66. expect.objectContaining({
  67. query: expect.objectContaining({
  68. project: [project.id],
  69. environment: [],
  70. start: '2017-10-12T12:00:00',
  71. end: '2017-10-17T00:00:00',
  72. }),
  73. })
  74. );
  75. });
  76. it('requests events stats with absolute period including previous period', async function() {
  77. const start = new Date('2017-10-12T12:00:00.000Z');
  78. const end = new Date('2017-10-17T00:00:00.000Z');
  79. await doEventsRequest(api, {
  80. ...opts,
  81. includePrevious: true,
  82. start,
  83. end,
  84. });
  85. expect(mock).toHaveBeenLastCalledWith(
  86. '/organizations/org-slug/events-stats/',
  87. expect.objectContaining({
  88. query: expect.objectContaining({
  89. project: [project.id],
  90. environment: [],
  91. start: '2017-10-08T00:00:00',
  92. end: '2017-10-17T00:00:00',
  93. }),
  94. })
  95. );
  96. });
  97. });