releases.spec.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. },
  83. });
  84. });
  85. it('adds derived metric fields', () => {
  86. expect(
  87. transformSessionsResponseToTable(SessionUserCountByStatusByReleaseFixture(), {
  88. ...widgetQuery,
  89. aggregates: ['count_unique(user)', 'sum(session)', 'count_crashed(session)'],
  90. })
  91. ).toEqual({
  92. data: [
  93. {
  94. 'count_crashed(session)': 34,
  95. 'count_unique(user)': 1,
  96. id: '0',
  97. release: '1',
  98. 'session.status': 'crashed',
  99. 'sum(session)': 34,
  100. },
  101. {
  102. 'count_crashed(session)': 0,
  103. 'count_unique(user)': 1,
  104. id: '1',
  105. release: '1',
  106. 'session.status': 'abnormal',
  107. 'sum(session)': 1,
  108. },
  109. {
  110. 'count_crashed(session)': 0,
  111. 'count_unique(user)': 2,
  112. id: '2',
  113. release: '1',
  114. 'session.status': 'errored',
  115. 'sum(session)': 451,
  116. },
  117. {
  118. 'count_crashed(session)': 0,
  119. 'count_unique(user)': 3,
  120. id: '3',
  121. release: '1',
  122. 'session.status': 'healthy',
  123. 'sum(session)': 5058,
  124. },
  125. {
  126. 'count_crashed(session)': 35,
  127. 'count_unique(user)': 2,
  128. id: '4',
  129. release: '2',
  130. 'session.status': 'crashed',
  131. 'sum(session)': 35,
  132. },
  133. {
  134. 'count_crashed(session)': 0,
  135. 'count_unique(user)': 1,
  136. id: '5',
  137. release: '2',
  138. 'session.status': 'abnormal',
  139. 'sum(session)': 1,
  140. },
  141. {
  142. 'count_crashed(session)': 0,
  143. 'count_unique(user)': 1,
  144. id: '6',
  145. release: '2',
  146. 'session.status': 'errored',
  147. 'sum(session)': 452,
  148. },
  149. {
  150. 'count_crashed(session)': 0,
  151. 'count_unique(user)': 10,
  152. id: '7',
  153. release: '2',
  154. 'session.status': 'healthy',
  155. 'sum(session)': 5059,
  156. },
  157. ],
  158. meta: {
  159. 'count_crashed(session)': 'integer',
  160. 'count_unique(user)': 'integer',
  161. release: 'string',
  162. 'session.status': 'string',
  163. 'sum(session)': 'integer',
  164. },
  165. });
  166. });
  167. it('strips away injected fields', () => {
  168. expect(
  169. transformSessionsResponseToTable(SessionUserCountByStatusByReleaseFixture(), {
  170. ...widgetQuery,
  171. aggregates: ['count_unique(user)', 'count_crashed(session)'],
  172. })
  173. ).toEqual({
  174. data: [
  175. {
  176. 'count_crashed(session)': 34,
  177. 'count_unique(user)': 1,
  178. id: '0',
  179. release: '1',
  180. 'session.status': 'crashed',
  181. },
  182. {
  183. 'count_crashed(session)': 0,
  184. 'count_unique(user)': 1,
  185. id: '1',
  186. release: '1',
  187. 'session.status': 'abnormal',
  188. },
  189. {
  190. 'count_crashed(session)': 0,
  191. 'count_unique(user)': 2,
  192. id: '2',
  193. release: '1',
  194. 'session.status': 'errored',
  195. },
  196. {
  197. 'count_crashed(session)': 0,
  198. 'count_unique(user)': 3,
  199. id: '3',
  200. release: '1',
  201. 'session.status': 'healthy',
  202. },
  203. {
  204. 'count_crashed(session)': 35,
  205. 'count_unique(user)': 2,
  206. id: '4',
  207. release: '2',
  208. 'session.status': 'crashed',
  209. },
  210. {
  211. 'count_crashed(session)': 0,
  212. 'count_unique(user)': 1,
  213. id: '5',
  214. release: '2',
  215. 'session.status': 'abnormal',
  216. },
  217. {
  218. 'count_crashed(session)': 0,
  219. 'count_unique(user)': 1,
  220. id: '6',
  221. release: '2',
  222. 'session.status': 'errored',
  223. },
  224. {
  225. 'count_crashed(session)': 0,
  226. 'count_unique(user)': 10,
  227. id: '7',
  228. release: '2',
  229. 'session.status': 'healthy',
  230. },
  231. ],
  232. meta: {
  233. 'count_crashed(session)': 'integer',
  234. 'count_unique(user)': 'integer',
  235. release: 'string',
  236. 'session.status': 'string',
  237. },
  238. });
  239. });
  240. });