mapSeriesToChart.spec.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {mapSeriesToChart} from './mapSeriesToChart';
  2. import type {UsageSeries} from './types';
  3. const mockSeries: UsageSeries = {
  4. start: '2021-01-01T00:00:00Z',
  5. end: '2021-01-07T00:00:00Z',
  6. intervals: ['2021-01-01T00:00:00Z', '2021-01-02T00:00:00Z', '2021-01-03T00:00:00Z'],
  7. groups: [
  8. {
  9. by: {
  10. outcome: 'accepted',
  11. },
  12. totals: {
  13. 'sum(quantity)': 6,
  14. },
  15. series: {
  16. 'sum(quantity)': [1, 2, 3],
  17. },
  18. },
  19. {
  20. by: {
  21. outcome: 'filtered',
  22. reason: 'other',
  23. },
  24. totals: {
  25. 'sum(quantity)': 4,
  26. },
  27. series: {
  28. 'sum(quantity)': [0, 1, 3],
  29. },
  30. },
  31. {
  32. by: {
  33. outcome: 'invalid',
  34. reason: 'invalid_transaction',
  35. },
  36. totals: {
  37. 'sum(quantity)': 6,
  38. },
  39. series: {
  40. 'sum(quantity)': [2, 2, 2],
  41. },
  42. },
  43. {
  44. by: {
  45. outcome: 'invalid',
  46. reason: 'other_reason_a',
  47. },
  48. totals: {
  49. 'sum(quantity)': 6,
  50. },
  51. series: {
  52. 'sum(quantity)': [1, 2, 3],
  53. },
  54. },
  55. {
  56. by: {
  57. outcome: 'invalid',
  58. reason: 'other_reason_b',
  59. },
  60. totals: {
  61. 'sum(quantity)': 3,
  62. },
  63. series: {
  64. 'sum(quantity)': [1, 1, 1],
  65. },
  66. },
  67. {
  68. by: {
  69. outcome: 'filtered',
  70. reason: 'react-hydration-errors',
  71. },
  72. totals: {
  73. 'sum(quantity)': 6,
  74. },
  75. series: {
  76. 'sum(quantity)': [5, 0, 1],
  77. },
  78. },
  79. {
  80. by: {
  81. outcome: 'filtered',
  82. reason: 'chunk-load-error',
  83. },
  84. totals: {
  85. 'sum(quantity)': 2,
  86. },
  87. series: {
  88. 'sum(quantity)': [1, 0, 1],
  89. },
  90. },
  91. ],
  92. };
  93. describe('mapSeriesToChart func', function () {
  94. it("should return correct chart tooltip's reasons", function () {
  95. const mappedSeries = mapSeriesToChart({
  96. orgStats: mockSeries,
  97. chartDateInterval: '1h',
  98. chartDateUtc: true,
  99. dataCategory: 'transactions',
  100. endpointQuery: {},
  101. });
  102. expect(mappedSeries.chartSubLabels).toEqual([
  103. {
  104. parentLabel: 'Filtered',
  105. label: 'Other',
  106. data: [
  107. {name: '2021-01-01T00:00:00Z', value: 0},
  108. {name: '2021-01-02T00:00:00Z', value: 1},
  109. {name: '2021-01-03T00:00:00Z', value: 3},
  110. ],
  111. },
  112. {
  113. parentLabel: 'Invalid',
  114. label: 'Invalid Data',
  115. data: [
  116. {name: '2021-01-01T00:00:00Z', value: 2},
  117. {name: '2021-01-02T00:00:00Z', value: 2},
  118. {name: '2021-01-03T00:00:00Z', value: 2},
  119. ],
  120. },
  121. {
  122. parentLabel: 'Invalid',
  123. label: 'Internal',
  124. data: [
  125. {name: '2021-01-01T00:00:00Z', value: 2},
  126. {name: '2021-01-02T00:00:00Z', value: 3},
  127. {name: '2021-01-03T00:00:00Z', value: 4},
  128. ],
  129. },
  130. {
  131. parentLabel: 'Filtered',
  132. label: 'React Hydration Errors',
  133. data: [
  134. {name: '2021-01-01T00:00:00Z', value: 5},
  135. {name: '2021-01-02T00:00:00Z', value: 0},
  136. {name: '2021-01-03T00:00:00Z', value: 1},
  137. ],
  138. },
  139. {
  140. parentLabel: 'Filtered',
  141. label: 'Chunk Load Error',
  142. data: [
  143. {name: '2021-01-01T00:00:00Z', value: 1},
  144. {name: '2021-01-02T00:00:00Z', value: 0},
  145. {name: '2021-01-03T00:00:00Z', value: 1},
  146. ],
  147. },
  148. ]);
  149. });
  150. it('should correctly sum up the rate limited count', function () {
  151. const mappedSeries = mapSeriesToChart({
  152. orgStats: {
  153. start: '2021-01-01T00:00:00Z',
  154. end: '2021-01-07T00:00:00Z',
  155. intervals: [
  156. '2021-01-01T00:00:00Z',
  157. '2021-01-02T00:00:00Z',
  158. '2021-01-03T00:00:00Z',
  159. ],
  160. groups: [
  161. {
  162. by: {
  163. outcome: 'accepted',
  164. },
  165. totals: {
  166. 'sum(quantity)': 99,
  167. },
  168. series: {
  169. 'sum(quantity)': [99],
  170. },
  171. },
  172. {
  173. by: {
  174. outcome: 'rate_limited',
  175. },
  176. totals: {
  177. 'sum(quantity)': 6,
  178. },
  179. series: {
  180. 'sum(quantity)': [1, 2, 3],
  181. },
  182. },
  183. {
  184. by: {
  185. outcome: 'abuse',
  186. },
  187. totals: {
  188. 'sum(quantity)': 2,
  189. },
  190. series: {
  191. 'sum(quantity)': [1, 1],
  192. },
  193. },
  194. {
  195. by: {
  196. outcome: 'cardinality_limited',
  197. },
  198. totals: {
  199. 'sum(quantity)': 3,
  200. },
  201. series: {
  202. 'sum(quantity)': [1, 2],
  203. },
  204. },
  205. ],
  206. },
  207. chartDateInterval: '1h',
  208. chartDateUtc: true,
  209. dataCategory: 'transactions',
  210. endpointQuery: {},
  211. });
  212. // sums up rate limited, abuse, and cardinality limited
  213. expect(mappedSeries.cardStats.rateLimited).toBe('11');
  214. });
  215. });