events.spec.tsx 3.0 KB

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