releases.spec.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import {SessionUserCountByStatusByReleaseFixture} from 'sentry-fixture/sessions';
  2. import {transformSessionsResponseToTable} from 'sentry/views/dashboards/datasetConfig/releases';
  3. describe('transformSessionsResponseToTable', function () {
  4. const widgetQuery = {
  5. name: '',
  6. fields: ['count_unique(user)', 'sum(session)', 'release', 'session.status'],
  7. columns: ['release', 'session.status'],
  8. aggregates: ['count_unique(user)', 'sum(session)'],
  9. conditions: '',
  10. orderby: '',
  11. };
  12. it('transforms sessions into table', () => {
  13. expect(
  14. transformSessionsResponseToTable(
  15. SessionUserCountByStatusByReleaseFixture(),
  16. widgetQuery
  17. )
  18. ).toEqual({
  19. data: [
  20. {
  21. 'count_unique(user)': 1,
  22. id: '0',
  23. release: '1',
  24. 'session.status': 'crashed',
  25. 'sum(session)': 34,
  26. },
  27. {
  28. 'count_unique(user)': 1,
  29. id: '1',
  30. release: '1',
  31. 'session.status': 'abnormal',
  32. 'sum(session)': 1,
  33. },
  34. {
  35. 'count_unique(user)': 2,
  36. id: '2',
  37. release: '1',
  38. 'session.status': 'errored',
  39. 'sum(session)': 451,
  40. },
  41. {
  42. 'count_unique(user)': 3,
  43. id: '3',
  44. release: '1',
  45. 'session.status': 'healthy',
  46. 'sum(session)': 5058,
  47. },
  48. {
  49. 'count_unique(user)': 2,
  50. id: '4',
  51. release: '2',
  52. 'session.status': 'crashed',
  53. 'sum(session)': 35,
  54. },
  55. {
  56. 'count_unique(user)': 1,
  57. id: '5',
  58. release: '2',
  59. 'session.status': 'abnormal',
  60. 'sum(session)': 1,
  61. },
  62. {
  63. 'count_unique(user)': 1,
  64. id: '6',
  65. release: '2',
  66. 'session.status': 'errored',
  67. 'sum(session)': 452,
  68. },
  69. {
  70. 'count_unique(user)': 10,
  71. id: '7',
  72. release: '2',
  73. 'session.status': 'healthy',
  74. 'sum(session)': 5059,
  75. },
  76. ],
  77. meta: {
  78. 'count_unique(user)': 'integer',
  79. release: 'string',
  80. 'session.status': 'string',
  81. 'sum(session)': 'integer',
  82. fields: {
  83. 'count_unique(user)': 'integer',
  84. release: 'string',
  85. 'session.status': 'string',
  86. 'sum(session)': 'integer',
  87. },
  88. },
  89. });
  90. });
  91. it('adds derived metric fields', () => {
  92. expect(
  93. transformSessionsResponseToTable(SessionUserCountByStatusByReleaseFixture(), {
  94. ...widgetQuery,
  95. aggregates: ['count_unique(user)', 'sum(session)', 'count_crashed(session)'],
  96. })
  97. ).toEqual({
  98. data: [
  99. {
  100. 'count_crashed(session)': 34,
  101. 'count_unique(user)': 1,
  102. id: '0',
  103. release: '1',
  104. 'session.status': 'crashed',
  105. 'sum(session)': 34,
  106. },
  107. {
  108. 'count_crashed(session)': 0,
  109. 'count_unique(user)': 1,
  110. id: '1',
  111. release: '1',
  112. 'session.status': 'abnormal',
  113. 'sum(session)': 1,
  114. },
  115. {
  116. 'count_crashed(session)': 0,
  117. 'count_unique(user)': 2,
  118. id: '2',
  119. release: '1',
  120. 'session.status': 'errored',
  121. 'sum(session)': 451,
  122. },
  123. {
  124. 'count_crashed(session)': 0,
  125. 'count_unique(user)': 3,
  126. id: '3',
  127. release: '1',
  128. 'session.status': 'healthy',
  129. 'sum(session)': 5058,
  130. },
  131. {
  132. 'count_crashed(session)': 35,
  133. 'count_unique(user)': 2,
  134. id: '4',
  135. release: '2',
  136. 'session.status': 'crashed',
  137. 'sum(session)': 35,
  138. },
  139. {
  140. 'count_crashed(session)': 0,
  141. 'count_unique(user)': 1,
  142. id: '5',
  143. release: '2',
  144. 'session.status': 'abnormal',
  145. 'sum(session)': 1,
  146. },
  147. {
  148. 'count_crashed(session)': 0,
  149. 'count_unique(user)': 1,
  150. id: '6',
  151. release: '2',
  152. 'session.status': 'errored',
  153. 'sum(session)': 452,
  154. },
  155. {
  156. 'count_crashed(session)': 0,
  157. 'count_unique(user)': 10,
  158. id: '7',
  159. release: '2',
  160. 'session.status': 'healthy',
  161. 'sum(session)': 5059,
  162. },
  163. ],
  164. meta: {
  165. 'count_crashed(session)': 'integer',
  166. 'count_unique(user)': 'integer',
  167. release: 'string',
  168. 'session.status': 'string',
  169. 'sum(session)': 'integer',
  170. fields: {
  171. 'count_crashed(session)': 'integer',
  172. 'count_unique(user)': 'integer',
  173. release: 'string',
  174. 'session.status': 'string',
  175. 'sum(session)': 'integer',
  176. },
  177. },
  178. });
  179. });
  180. it('strips away injected fields', () => {
  181. expect(
  182. transformSessionsResponseToTable(SessionUserCountByStatusByReleaseFixture(), {
  183. ...widgetQuery,
  184. aggregates: ['count_unique(user)', 'count_crashed(session)'],
  185. })
  186. ).toEqual({
  187. data: [
  188. {
  189. 'count_crashed(session)': 34,
  190. 'count_unique(user)': 1,
  191. id: '0',
  192. release: '1',
  193. 'session.status': 'crashed',
  194. },
  195. {
  196. 'count_crashed(session)': 0,
  197. 'count_unique(user)': 1,
  198. id: '1',
  199. release: '1',
  200. 'session.status': 'abnormal',
  201. },
  202. {
  203. 'count_crashed(session)': 0,
  204. 'count_unique(user)': 2,
  205. id: '2',
  206. release: '1',
  207. 'session.status': 'errored',
  208. },
  209. {
  210. 'count_crashed(session)': 0,
  211. 'count_unique(user)': 3,
  212. id: '3',
  213. release: '1',
  214. 'session.status': 'healthy',
  215. },
  216. {
  217. 'count_crashed(session)': 35,
  218. 'count_unique(user)': 2,
  219. id: '4',
  220. release: '2',
  221. 'session.status': 'crashed',
  222. },
  223. {
  224. 'count_crashed(session)': 0,
  225. 'count_unique(user)': 1,
  226. id: '5',
  227. release: '2',
  228. 'session.status': 'abnormal',
  229. },
  230. {
  231. 'count_crashed(session)': 0,
  232. 'count_unique(user)': 1,
  233. id: '6',
  234. release: '2',
  235. 'session.status': 'errored',
  236. },
  237. {
  238. 'count_crashed(session)': 0,
  239. 'count_unique(user)': 10,
  240. id: '7',
  241. release: '2',
  242. 'session.status': 'healthy',
  243. },
  244. ],
  245. meta: {
  246. 'count_crashed(session)': 'integer',
  247. 'count_unique(user)': 'integer',
  248. release: 'string',
  249. 'session.status': 'string',
  250. fields: {
  251. 'count_crashed(session)': 'integer',
  252. 'count_unique(user)': 'integer',
  253. release: 'string',
  254. 'session.status': 'string',
  255. },
  256. },
  257. });
  258. });
  259. });