events.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {doEventsRequest} from 'sentry/actionCreators/events';
  4. describe('Events ActionCreator', function () {
  5. const api = new MockApiClient();
  6. const organization = OrganizationFixture();
  7. const project = ProjectFixture();
  8. const opts = {
  9. organization,
  10. project: [parseInt(project.id, 10)],
  11. environment: [],
  12. };
  13. let mock: jest.Mock;
  14. beforeEach(function () {
  15. MockApiClient.clearMockResponses();
  16. mock = MockApiClient.addMockResponse({
  17. url: '/organizations/org-slug/events-stats/',
  18. body: {
  19. data: [
  20. [123, []],
  21. [123, []],
  22. [123, []],
  23. [123, []],
  24. [123, []],
  25. [123, []],
  26. ],
  27. },
  28. });
  29. });
  30. it('requests events stats with relative period', function () {
  31. doEventsRequest(api, {
  32. ...opts,
  33. includePrevious: false,
  34. period: '7d',
  35. partial: true,
  36. });
  37. expect(mock).toHaveBeenLastCalledWith(
  38. '/organizations/org-slug/events-stats/',
  39. expect.objectContaining({
  40. query: expect.objectContaining({
  41. project: [parseInt(project.id, 10)],
  42. environment: [],
  43. statsPeriod: '7d',
  44. }),
  45. })
  46. );
  47. });
  48. it('sets useRpc param', function () {
  49. doEventsRequest(api, {
  50. ...opts,
  51. includePrevious: false,
  52. period: '7d',
  53. partial: true,
  54. useRpc: true,
  55. });
  56. expect(mock).toHaveBeenLastCalledWith(
  57. '/organizations/org-slug/events-stats/',
  58. expect.objectContaining({
  59. query: expect.objectContaining({
  60. project: [parseInt(project.id, 10)],
  61. environment: [],
  62. statsPeriod: '7d',
  63. }),
  64. })
  65. );
  66. });
  67. it('requests events stats with relative period including previous period', function () {
  68. doEventsRequest(api, {
  69. ...opts,
  70. includePrevious: true,
  71. period: '7d',
  72. partial: true,
  73. });
  74. expect(mock).toHaveBeenLastCalledWith(
  75. '/organizations/org-slug/events-stats/',
  76. expect.objectContaining({
  77. query: expect.objectContaining({
  78. project: [parseInt(project.id, 10)],
  79. environment: [],
  80. statsPeriod: '14d',
  81. }),
  82. })
  83. );
  84. });
  85. it('requests events stats with absolute period', function () {
  86. const start = new Date('2017-10-12T12:00:00.000Z');
  87. const end = new Date('2017-10-17T00:00:00.000Z');
  88. doEventsRequest(api, {
  89. ...opts,
  90. includePrevious: false,
  91. start,
  92. end,
  93. partial: true,
  94. });
  95. expect(mock).toHaveBeenCalledTimes(1);
  96. expect(mock).toHaveBeenLastCalledWith(
  97. '/organizations/org-slug/events-stats/',
  98. expect.objectContaining({
  99. query: expect.objectContaining({
  100. project: [parseInt(project.id, 10)],
  101. environment: [],
  102. start: '2017-10-12T12:00:00',
  103. end: '2017-10-17T00:00:00',
  104. }),
  105. })
  106. );
  107. });
  108. it('requests events stats with absolute period including previous period', async function () {
  109. const start = new Date('2017-10-12T12:00:00.000Z');
  110. const end = new Date('2017-10-17T00:00:00.000Z');
  111. await doEventsRequest(api, {
  112. ...opts,
  113. includePrevious: true,
  114. start,
  115. end,
  116. partial: true,
  117. });
  118. expect(mock).toHaveBeenLastCalledWith(
  119. '/organizations/org-slug/events-stats/',
  120. expect.objectContaining({
  121. query: expect.objectContaining({
  122. project: [parseInt(project.id, 10)],
  123. environment: [],
  124. start: '2017-10-08T00:00:00',
  125. end: '2017-10-17T00:00:00',
  126. }),
  127. })
  128. );
  129. });
  130. it('spreads query extras', async function () {
  131. await doEventsRequest(api, {
  132. ...opts,
  133. queryExtras: {useOnDemandMetrics: 'true'},
  134. partial: true,
  135. });
  136. expect(mock).toHaveBeenLastCalledWith(
  137. '/organizations/org-slug/events-stats/',
  138. expect.objectContaining({
  139. query: expect.objectContaining({
  140. project: [parseInt(project.id, 10)],
  141. environment: [],
  142. useOnDemandMetrics: 'true',
  143. }),
  144. })
  145. );
  146. });
  147. });