mapSeriesToChart.spec.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. };
  69. describe('mapSeriesToChart func', function () {
  70. it("should return correct chart tooltip's reasons", function () {
  71. const mappedSeries = mapSeriesToChart({
  72. orgStats: mockSeries,
  73. chartDateInterval: '1h',
  74. chartDateUtc: true,
  75. dataCategory: 'transactions',
  76. endpointQuery: {},
  77. });
  78. expect(mappedSeries.chartSubLabels).toEqual([
  79. {
  80. parentLabel: 'Filtered',
  81. label: 'Other',
  82. data: [
  83. {name: '2021-01-01T00:00:00Z', value: 0},
  84. {name: '2021-01-02T00:00:00Z', value: 1},
  85. {name: '2021-01-03T00:00:00Z', value: 3},
  86. ],
  87. },
  88. {
  89. parentLabel: 'Invalid',
  90. label: 'Invalid Data',
  91. data: [
  92. {name: '2021-01-01T00:00:00Z', value: 2},
  93. {name: '2021-01-02T00:00:00Z', value: 2},
  94. {name: '2021-01-03T00:00:00Z', value: 2},
  95. ],
  96. },
  97. {
  98. parentLabel: 'Invalid',
  99. label: 'Internal',
  100. data: [
  101. {name: '2021-01-01T00:00:00Z', value: 2},
  102. {name: '2021-01-02T00:00:00Z', value: 3},
  103. {name: '2021-01-03T00:00:00Z', value: 4},
  104. ],
  105. },
  106. ]);
  107. });
  108. });