releases.spec.tsx 6.1 KB

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