transactions.spec.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
  3. import {WidgetFixture} from 'sentry-fixture/widget';
  4. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  5. import {MEPState} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  6. import {TransactionsConfig} from 'sentry/views/dashboards/datasetConfig/transactions';
  7. describe('TransactionsConfig', function () {
  8. describe('getEventsRequest', function () {
  9. let api, organization, mockEventsRequest, mockEventsStatsRequest;
  10. beforeEach(function () {
  11. MockApiClient.clearMockResponses();
  12. api = new MockApiClient();
  13. organization = OrganizationFixture({
  14. features: ['on-demand-metrics-extraction', 'on-demand-metrics-ui-widgets'],
  15. });
  16. mockEventsRequest = MockApiClient.addMockResponse({
  17. url: '/organizations/org-slug/events/',
  18. body: {
  19. data: [],
  20. },
  21. });
  22. mockEventsStatsRequest = MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/events-stats/',
  24. body: {
  25. data: [],
  26. },
  27. });
  28. });
  29. it('makes table request to the transactions dataset', function () {
  30. const pageFilters = PageFiltersFixture();
  31. const widget = WidgetFixture();
  32. TransactionsConfig.getTableRequest!(
  33. api,
  34. widget,
  35. {
  36. fields: ['count()'],
  37. aggregates: ['count()'],
  38. columns: [],
  39. conditions: '',
  40. name: '',
  41. orderby: '',
  42. },
  43. organization,
  44. pageFilters
  45. );
  46. expect(mockEventsRequest).toHaveBeenCalledWith(
  47. '/organizations/org-slug/events/',
  48. expect.objectContaining({
  49. query: expect.objectContaining({
  50. dataset: DiscoverDatasets.TRANSACTIONS,
  51. useOnDemandMetrics: false,
  52. }),
  53. })
  54. );
  55. });
  56. it('makes table request to the metrics enhanced dataset with the correct mep state', function () {
  57. const pageFilters = PageFiltersFixture();
  58. const widget = WidgetFixture();
  59. TransactionsConfig.getTableRequest!(
  60. api,
  61. widget,
  62. {
  63. fields: ['count()'],
  64. aggregates: ['count()'],
  65. columns: [],
  66. conditions: '',
  67. name: '',
  68. orderby: '',
  69. },
  70. organization,
  71. pageFilters,
  72. undefined,
  73. undefined,
  74. undefined,
  75. undefined,
  76. MEPState.AUTO
  77. );
  78. expect(mockEventsRequest).toHaveBeenCalledWith(
  79. '/organizations/org-slug/events/',
  80. expect.objectContaining({
  81. query: expect.objectContaining({
  82. dataset: DiscoverDatasets.METRICS_ENHANCED,
  83. useOnDemandMetrics: false,
  84. }),
  85. })
  86. );
  87. });
  88. it('makes table request with on demand', function () {
  89. const pageFilters = PageFiltersFixture();
  90. const widget = WidgetFixture();
  91. TransactionsConfig.getTableRequest!(
  92. api,
  93. widget,
  94. {
  95. fields: ['count()'],
  96. aggregates: ['count()'],
  97. columns: [],
  98. conditions: '',
  99. name: '',
  100. orderby: '',
  101. },
  102. organization,
  103. pageFilters,
  104. {
  105. setForceOnDemand: () => {},
  106. forceOnDemand: true,
  107. isControlEnabled: true,
  108. },
  109. undefined,
  110. undefined,
  111. undefined,
  112. MEPState.AUTO
  113. );
  114. expect(mockEventsRequest).toHaveBeenCalledWith(
  115. '/organizations/org-slug/events/',
  116. expect.objectContaining({
  117. query: expect.objectContaining({
  118. dataset: DiscoverDatasets.METRICS_ENHANCED,
  119. useOnDemandMetrics: true,
  120. onDemandType: 'dynamic_query',
  121. }),
  122. })
  123. );
  124. });
  125. it('makes series request to the transactions dataset', function () {
  126. const pageFilters = PageFiltersFixture();
  127. const widget = WidgetFixture();
  128. TransactionsConfig.getSeriesRequest!(api, widget, 0, organization, pageFilters);
  129. expect(mockEventsStatsRequest).toHaveBeenCalledWith(
  130. '/organizations/org-slug/events-stats/',
  131. expect.objectContaining({
  132. query: expect.objectContaining({
  133. dataset: DiscoverDatasets.TRANSACTIONS,
  134. }),
  135. })
  136. );
  137. });
  138. it('makes series request to the metrics enhanced dataset', function () {
  139. const pageFilters = PageFiltersFixture();
  140. const widget = WidgetFixture();
  141. TransactionsConfig.getSeriesRequest!(
  142. api,
  143. widget,
  144. 0,
  145. organization,
  146. pageFilters,
  147. undefined,
  148. undefined,
  149. MEPState.AUTO
  150. );
  151. expect(mockEventsStatsRequest).toHaveBeenCalledWith(
  152. '/organizations/org-slug/events-stats/',
  153. expect.objectContaining({
  154. query: expect.objectContaining({
  155. dataset: DiscoverDatasets.METRICS_ENHANCED,
  156. }),
  157. })
  158. );
  159. });
  160. it('makes series request with on demand', function () {
  161. const pageFilters = PageFiltersFixture();
  162. const widget = WidgetFixture();
  163. TransactionsConfig.getSeriesRequest!(
  164. api,
  165. widget,
  166. 0,
  167. organization,
  168. pageFilters,
  169. {
  170. setForceOnDemand: () => {},
  171. forceOnDemand: true,
  172. isControlEnabled: true,
  173. },
  174. undefined,
  175. MEPState.AUTO
  176. );
  177. expect(mockEventsStatsRequest).toHaveBeenCalledWith(
  178. '/organizations/org-slug/events-stats/',
  179. expect.objectContaining({
  180. query: expect.objectContaining({
  181. dataset: DiscoverDatasets.METRICS_ENHANCED,
  182. onDemandType: 'dynamic_query',
  183. useOnDemandMetrics: true,
  184. }),
  185. })
  186. );
  187. });
  188. });
  189. });