events.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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;
  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. });
  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. });
  52. expect(mock).toHaveBeenLastCalledWith(
  53. '/organizations/org-slug/events-stats/',
  54. expect.objectContaining({
  55. query: expect.objectContaining({
  56. project: [project.id],
  57. environment: [],
  58. statsPeriod: '14d',
  59. }),
  60. })
  61. );
  62. });
  63. it('requests events stats with absolute period', async function () {
  64. const start = new Date('2017-10-12T12:00:00.000Z');
  65. const end = new Date('2017-10-17T00:00:00.000Z');
  66. doEventsRequest(api, {
  67. ...opts,
  68. includePrevious: false,
  69. start,
  70. end,
  71. });
  72. expect(mock).toHaveBeenCalledTimes(1);
  73. expect(mock).toHaveBeenLastCalledWith(
  74. '/organizations/org-slug/events-stats/',
  75. expect.objectContaining({
  76. query: expect.objectContaining({
  77. project: [project.id],
  78. environment: [],
  79. start: '2017-10-12T12:00:00',
  80. end: '2017-10-17T00:00:00',
  81. }),
  82. })
  83. );
  84. });
  85. it('requests events stats with absolute period including previous period', async function () {
  86. const start = new Date('2017-10-12T12:00:00.000Z');
  87. const end = new Date('2017-10-17T00:00:00.000Z');
  88. await doEventsRequest(api, {
  89. ...opts,
  90. includePrevious: true,
  91. start,
  92. end,
  93. });
  94. expect(mock).toHaveBeenLastCalledWith(
  95. '/organizations/org-slug/events-stats/',
  96. expect.objectContaining({
  97. query: expect.objectContaining({
  98. project: [project.id],
  99. environment: [],
  100. start: '2017-10-08T00:00:00',
  101. end: '2017-10-17T00:00:00',
  102. }),
  103. })
  104. );
  105. });
  106. });