123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- import {mapSeriesToChart} from './mapSeriesToChart';
- import type {UsageSeries} from './types';
- const mockSeries: UsageSeries = {
- start: '2021-01-01T00:00:00Z',
- end: '2021-01-07T00:00:00Z',
- intervals: ['2021-01-01T00:00:00Z', '2021-01-02T00:00:00Z', '2021-01-03T00:00:00Z'],
- groups: [
- {
- by: {
- outcome: 'accepted',
- },
- totals: {
- 'sum(quantity)': 6,
- },
- series: {
- 'sum(quantity)': [1, 2, 3],
- },
- },
- {
- by: {
- outcome: 'filtered',
- reason: 'other',
- },
- totals: {
- 'sum(quantity)': 4,
- },
- series: {
- 'sum(quantity)': [0, 1, 3],
- },
- },
- {
- by: {
- outcome: 'invalid',
- reason: 'invalid_transaction',
- },
- totals: {
- 'sum(quantity)': 6,
- },
- series: {
- 'sum(quantity)': [2, 2, 2],
- },
- },
- {
- by: {
- outcome: 'invalid',
- reason: 'other_reason_a',
- },
- totals: {
- 'sum(quantity)': 6,
- },
- series: {
- 'sum(quantity)': [1, 2, 3],
- },
- },
- {
- by: {
- outcome: 'invalid',
- reason: 'other_reason_b',
- },
- totals: {
- 'sum(quantity)': 3,
- },
- series: {
- 'sum(quantity)': [1, 1, 1],
- },
- },
- ],
- };
- describe('mapSeriesToChart func', function () {
- it("should return correct chart tooltip's reasons", function () {
- const mappedSeries = mapSeriesToChart({
- orgStats: mockSeries,
- chartDateInterval: '1h',
- chartDateUtc: true,
- dataCategory: 'transactions',
- endpointQuery: {},
- });
- expect(mappedSeries.chartSubLabels).toEqual([
- {
- parentLabel: 'Filtered',
- label: 'Other',
- data: [
- {name: '2021-01-01T00:00:00Z', value: 0},
- {name: '2021-01-02T00:00:00Z', value: 1},
- {name: '2021-01-03T00:00:00Z', value: 3},
- ],
- },
- {
- parentLabel: 'Invalid',
- label: 'Invalid Data',
- data: [
- {name: '2021-01-01T00:00:00Z', value: 2},
- {name: '2021-01-02T00:00:00Z', value: 2},
- {name: '2021-01-03T00:00:00Z', value: 2},
- ],
- },
- {
- parentLabel: 'Invalid',
- label: 'Internal',
- data: [
- {name: '2021-01-01T00:00:00Z', value: 2},
- {name: '2021-01-02T00:00:00Z', value: 3},
- {name: '2021-01-03T00:00:00Z', value: 4},
- ],
- },
- ]);
- });
- it('should correctly sum up the rate limited count', function () {
- const mappedSeries = mapSeriesToChart({
- orgStats: {
- start: '2021-01-01T00:00:00Z',
- end: '2021-01-07T00:00:00Z',
- intervals: [
- '2021-01-01T00:00:00Z',
- '2021-01-02T00:00:00Z',
- '2021-01-03T00:00:00Z',
- ],
- groups: [
- {
- by: {
- outcome: 'accepted',
- },
- totals: {
- 'sum(quantity)': 99,
- },
- series: {
- 'sum(quantity)': [99],
- },
- },
- {
- by: {
- outcome: 'rate_limited',
- },
- totals: {
- 'sum(quantity)': 6,
- },
- series: {
- 'sum(quantity)': [1, 2, 3],
- },
- },
- {
- by: {
- outcome: 'abuse',
- },
- totals: {
- 'sum(quantity)': 2,
- },
- series: {
- 'sum(quantity)': [1, 1],
- },
- },
- {
- by: {
- outcome: 'cardinality_limited',
- },
- totals: {
- 'sum(quantity)': 3,
- },
- series: {
- 'sum(quantity)': [1, 2],
- },
- },
- ],
- },
- chartDateInterval: '1h',
- chartDateUtc: true,
- dataCategory: 'transactions',
- endpointQuery: {},
- });
- // sums up rate limited, abuse, and cardinality limited
- expect(mappedSeries.cardStats.rateLimited).toEqual('11');
- });
- });
|