getSeriesRequestData.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
  3. import {WidgetFixture} from 'sentry-fixture/widget';
  4. import {WidgetQueryFixture} from 'sentry-fixture/widgetQuery';
  5. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  6. import {getSeriesRequestData} from 'sentry/views/dashboards/datasetConfig/utils/getSeriesRequestData';
  7. import {DisplayType} from 'sentry/views/dashboards/types';
  8. describe('utils', () => {
  9. describe('getSeriesRequestData', () => {
  10. it('returns the correct request data for simple line chart timeseries', () => {
  11. const widget = WidgetFixture({
  12. displayType: DisplayType.LINE,
  13. queries: [
  14. WidgetQueryFixture({
  15. fields: ['count()', 'count_unique(user)'],
  16. aggregates: ['count()', 'count_unique(user)'],
  17. columns: [],
  18. }),
  19. ],
  20. });
  21. const pageFilters = PageFiltersFixture();
  22. const organization = OrganizationFixture();
  23. const requestData = getSeriesRequestData(
  24. widget,
  25. 0,
  26. organization,
  27. pageFilters,
  28. DiscoverDatasets.ERRORS,
  29. 'test-referrer'
  30. );
  31. expect(requestData).toEqual({
  32. // Baggage
  33. organization,
  34. dataset: DiscoverDatasets.ERRORS,
  35. referrer: 'test-referrer',
  36. // Meta settings on what should be included in the response
  37. includePrevious: false,
  38. includeAllArgs: true,
  39. partial: true,
  40. // Page filters
  41. environment: [],
  42. project: [],
  43. start: null,
  44. end: null,
  45. period: null,
  46. // Actual query data
  47. yAxis: ['count()', 'count_unique(user)'],
  48. query: 'tag:value',
  49. orderby: '',
  50. interval: '30m',
  51. });
  52. });
  53. it('returns the correct request data for line chart timeseries with grouping', () => {
  54. // This is essentially a TOP_N request because we group by the columns
  55. // and surface the top results
  56. const widget = WidgetFixture({
  57. displayType: DisplayType.LINE,
  58. queries: [
  59. WidgetQueryFixture({
  60. fields: ['title', 'count()'],
  61. aggregates: ['count()'],
  62. columns: ['title'],
  63. }),
  64. ],
  65. });
  66. const pageFilters = PageFiltersFixture();
  67. const organization = OrganizationFixture();
  68. const requestData = getSeriesRequestData(
  69. widget,
  70. 0,
  71. organization,
  72. pageFilters,
  73. DiscoverDatasets.ERRORS,
  74. 'test-referrer'
  75. );
  76. expect(requestData).toEqual({
  77. // Baggage
  78. organization,
  79. dataset: DiscoverDatasets.ERRORS,
  80. referrer: 'test-referrer',
  81. // Meta settings on what should be included in the response
  82. includePrevious: false,
  83. includeAllArgs: true,
  84. partial: true,
  85. excludeOther: false,
  86. // Page filters
  87. environment: [],
  88. project: [],
  89. start: null,
  90. end: null,
  91. period: null,
  92. // Actual query data
  93. field: ['title', 'count()'],
  94. yAxis: ['count()'],
  95. query: 'tag:value',
  96. orderby: '',
  97. interval: '30m',
  98. topEvents: 5,
  99. });
  100. });
  101. it('returns the correct request data for top-N chart timeseries with grouping', () => {
  102. // This is essentially a TOP_N request because we group by the columns
  103. // and surface the top results
  104. const widget = WidgetFixture({
  105. displayType: DisplayType.TOP_N,
  106. queries: [
  107. WidgetQueryFixture({
  108. fields: ['title', 'count()'],
  109. aggregates: ['count()'],
  110. columns: ['title'],
  111. }),
  112. ],
  113. });
  114. const pageFilters = PageFiltersFixture();
  115. const organization = OrganizationFixture();
  116. const requestData = getSeriesRequestData(
  117. widget,
  118. 0,
  119. organization,
  120. pageFilters,
  121. DiscoverDatasets.ERRORS,
  122. 'test-referrer'
  123. );
  124. expect(requestData).toEqual({
  125. // Baggage
  126. organization,
  127. dataset: DiscoverDatasets.ERRORS,
  128. referrer: 'test-referrer',
  129. // Meta settings on what should be included in the response
  130. includePrevious: false,
  131. includeAllArgs: true,
  132. partial: true,
  133. // Page filters
  134. environment: [],
  135. project: [],
  136. start: null,
  137. end: null,
  138. period: null,
  139. // Actual query data
  140. field: ['title', 'count()'],
  141. yAxis: 'count()',
  142. query: 'tag:value',
  143. interval: '30m',
  144. topEvents: 5,
  145. });
  146. });
  147. });
  148. });