transformSessionsResponseToTable.spec.tsx 5.8 KB

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