Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Oct 14, 2020
1 parent 10a1f68 commit bff6f16
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/plugins/data/common/search/aggs/buckets/terms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { AggConfigs } from '../agg_configs';
import { METRIC_TYPES } from '../metrics';
import { mockAggTypesRegistry } from '../test_helpers';
import { BUCKET_TYPES } from './bucket_agg_types';

Expand Down Expand Up @@ -133,5 +134,49 @@ describe('Terms Agg', () => {
expect(params.include).toStrictEqual([1.1, 2, 3.33]);
expect(params.exclude).toStrictEqual([4, 5.555, 6]);
});

test('uses correct bucket path for sorting by median', () => {
const indexPattern = {
id: '1234',
title: 'logstash-*',
fields: {
getByName: () => field,
filter: () => [field],
},
} as any;

const field = {
name: 'field',
indexPattern,
};

const aggConfigs = new AggConfigs(
indexPattern,
[
{
id: 'test',
params: {
field: {
name: 'string_field',
type: 'string',
},
orderAgg: {
type: METRIC_TYPES.MEDIAN,
params: {
field: {
name: 'number_field',
type: 'number',
},
},
},
},
type: BUCKET_TYPES.TERMS,
},
],
{ typesRegistry: mockAggTypesRegistry() }
);
const { [BUCKET_TYPES.TERMS]: params } = aggConfigs.aggs[0].toDsl();
expect(params.order).toEqual({ 'test-orderAgg.50': 'desc' });
});
});
});
6 changes: 6 additions & 0 deletions src/plugins/data/common/search/aggs/metrics/median.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ describe('AggTypeMetricMedianProvider class', () => {
expect(dsl.median.percentiles.percents).toEqual([50]);
});

it('points to right value within multi metric for value bucket path', () => {
expect(aggConfigs.byId(METRIC_TYPES.MEDIAN)!.getValueBucketPath()).toEqual(
`${METRIC_TYPES.MEDIAN}.50`
);
});

it('converts the response', () => {
const agg = aggConfigs.getResponseAggs()[0];

Expand Down

0 comments on commit bff6f16

Please sign in to comment.