health.spec.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import {Client} from 'app/api';
  2. import {doHealthRequest} from 'app/actionCreators/health';
  3. describe('Health ActionCreator', function() {
  4. const api = new Client();
  5. const organization = TestStubs.Organization();
  6. const project = TestStubs.Project();
  7. let mock;
  8. it('requests timeseries w/o tag', function() {
  9. mock = MockApiClient.addMockResponse({
  10. url: '/organizations/org-slug/health/graph/',
  11. });
  12. doHealthRequest(api, {
  13. timeseries: true,
  14. organization,
  15. projects: [project.id],
  16. environments: [],
  17. topk: 5,
  18. includePrevious: false,
  19. period: '7d',
  20. });
  21. expect(mock).toHaveBeenCalled();
  22. expect(mock).toHaveBeenLastCalledWith(
  23. '/organizations/org-slug/health/graph/',
  24. expect.objectContaining({
  25. query: expect.objectContaining({
  26. project: [project.id],
  27. environment: [],
  28. topk: 5,
  29. includePrevious: false,
  30. statsPeriod: '7d',
  31. }),
  32. })
  33. );
  34. });
  35. it('requests timeseries w/ tag', function() {
  36. mock = MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/health/graph/',
  38. });
  39. doHealthRequest(api, {
  40. timeseries: true,
  41. organization,
  42. projects: [project.id],
  43. environments: [],
  44. tag: 'release',
  45. topk: 5,
  46. includePrevious: false,
  47. period: '7d',
  48. });
  49. expect(mock).toHaveBeenCalled();
  50. expect(mock).toHaveBeenLastCalledWith(
  51. '/organizations/org-slug/health/graph/',
  52. expect.objectContaining({
  53. query: expect.objectContaining({
  54. project: [project.id],
  55. environment: [],
  56. tag: 'release',
  57. topk: 5,
  58. includePrevious: false,
  59. statsPeriod: '7d',
  60. }),
  61. })
  62. );
  63. });
  64. it('requests top', function() {
  65. mock = MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/health/top/',
  67. });
  68. doHealthRequest(api, {
  69. timeseries: false,
  70. organization,
  71. projects: [project.id],
  72. environments: [],
  73. tag: 'release',
  74. includePrevious: false,
  75. period: '7d',
  76. });
  77. expect(mock).toHaveBeenCalled();
  78. expect(mock).toHaveBeenLastCalledWith(
  79. '/organizations/org-slug/health/top/',
  80. expect.objectContaining({
  81. query: expect.objectContaining({
  82. project: [project.id],
  83. environment: [],
  84. tag: 'release',
  85. includePrevious: false,
  86. statsPeriod: '7d',
  87. }),
  88. })
  89. );
  90. });
  91. it('requests timeseries w/ tag and previous period', function() {
  92. mock = MockApiClient.addMockResponse({
  93. url: '/organizations/org-slug/health/graph/',
  94. });
  95. doHealthRequest(api, {
  96. timeseries: true,
  97. organization,
  98. projects: [project.id],
  99. environments: [],
  100. tag: 'release',
  101. topk: 5,
  102. includePrevious: true,
  103. period: '7d',
  104. });
  105. expect(mock).toHaveBeenCalled();
  106. expect(mock).toHaveBeenLastCalledWith(
  107. '/organizations/org-slug/health/graph/',
  108. expect.objectContaining({
  109. query: expect.objectContaining({
  110. statsPeriod: '14d',
  111. }),
  112. })
  113. );
  114. });
  115. it('requests non-timeseries and previous period', function() {
  116. mock = MockApiClient.addMockResponse({
  117. url: '/organizations/org-slug/health/top/',
  118. });
  119. doHealthRequest(api, {
  120. timeseries: false,
  121. organization,
  122. projects: [project.id],
  123. environments: [],
  124. tag: 'release',
  125. topk: 5,
  126. includePrevious: true,
  127. period: '7d',
  128. });
  129. expect(mock).toHaveBeenCalled();
  130. expect(mock).toHaveBeenLastCalledWith(
  131. '/organizations/org-slug/health/top/',
  132. expect.objectContaining({
  133. query: expect.objectContaining({
  134. statsPeriod: '7d',
  135. }),
  136. })
  137. );
  138. });
  139. });