transformSessionsResponseToTable.spec.tsx 5.8 KB

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