events.spec.tsx 3.0 KB

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