events.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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('requests events stats with relative period including previous period', function () {
  49. doEventsRequest(api, {
  50. ...opts,
  51. includePrevious: true,
  52. period: '7d',
  53. partial: true,
  54. });
  55. expect(mock).toHaveBeenLastCalledWith(
  56. '/organizations/org-slug/events-stats/',
  57. expect.objectContaining({
  58. query: expect.objectContaining({
  59. project: [parseInt(project.id, 10)],
  60. environment: [],
  61. statsPeriod: '14d',
  62. }),
  63. })
  64. );
  65. });
  66. it('requests events stats with absolute period', function () {
  67. const start = new Date('2017-10-12T12:00:00.000Z');
  68. const end = new Date('2017-10-17T00:00:00.000Z');
  69. doEventsRequest(api, {
  70. ...opts,
  71. includePrevious: false,
  72. start,
  73. end,
  74. partial: true,
  75. });
  76. expect(mock).toHaveBeenCalledTimes(1);
  77. expect(mock).toHaveBeenLastCalledWith(
  78. '/organizations/org-slug/events-stats/',
  79. expect.objectContaining({
  80. query: expect.objectContaining({
  81. project: [parseInt(project.id, 10)],
  82. environment: [],
  83. start: '2017-10-12T12:00:00',
  84. end: '2017-10-17T00:00:00',
  85. }),
  86. })
  87. );
  88. });
  89. it('requests events stats with absolute period including previous period', async function () {
  90. const start = new Date('2017-10-12T12:00:00.000Z');
  91. const end = new Date('2017-10-17T00:00:00.000Z');
  92. await doEventsRequest(api, {
  93. ...opts,
  94. includePrevious: true,
  95. start,
  96. end,
  97. partial: true,
  98. });
  99. expect(mock).toHaveBeenLastCalledWith(
  100. '/organizations/org-slug/events-stats/',
  101. expect.objectContaining({
  102. query: expect.objectContaining({
  103. project: [parseInt(project.id, 10)],
  104. environment: [],
  105. start: '2017-10-08T00:00:00',
  106. end: '2017-10-17T00:00:00',
  107. }),
  108. })
  109. );
  110. });
  111. it('spreads query extras', async function () {
  112. await doEventsRequest(api, {
  113. ...opts,
  114. queryExtras: {useOnDemandMetrics: 'true'},
  115. partial: true,
  116. });
  117. expect(mock).toHaveBeenLastCalledWith(
  118. '/organizations/org-slug/events-stats/',
  119. expect.objectContaining({
  120. query: expect.objectContaining({
  121. project: [parseInt(project.id, 10)],
  122. environment: [],
  123. useOnDemandMetrics: 'true',
  124. }),
  125. })
  126. );
  127. });
  128. });