Skip to content

Commit

Permalink
test optimizeEsAggs contract
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Jun 14, 2022
1 parent 970a78b commit 5d61742
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
FormulaIndexPatternColumn,
RangeIndexPatternColumn,
FiltersIndexPatternColumn,
PercentileIndexPatternColumn,
} from './operations';
import { createMockedFullReference } from './operations/mocks';
import { cloneDeep } from 'lodash';
Expand Down Expand Up @@ -948,6 +949,66 @@ describe('IndexPattern Data Source', () => {
expect(ast.chain[1].arguments.timeFields).not.toContain('timefield');
});

it('should call optimizeEsAggs once per operation for which it is available', () => {
const queryBaseState: DataViewBaseState = {
currentIndexPatternId: '1',
layers: {
first: {
indexPatternId: '1',
columns: {
col1: {
label: 'timestamp',
dataType: 'date',
operationType: 'date_histogram',
sourceField: 'timestamp',
isBucketed: true,
scale: 'interval',
params: {
interval: 'auto',
includeEmptyRows: true,
dropPartials: false,
},
} as DateHistogramIndexPatternColumn,
col2: {
label: '95th percentile of bytes',
dataType: 'number',
operationType: 'percentile',
sourceField: 'bytes',
isBucketed: false,
scale: 'ratio',
params: {
percentile: 95,
},
} as PercentileIndexPatternColumn,
col3: {
label: '95th percentile of bytes',
dataType: 'number',
operationType: 'percentile',
sourceField: 'bytes',
isBucketed: false,
scale: 'ratio',
params: {
percentile: 95,
},
} as PercentileIndexPatternColumn,
},
columnOrder: ['col1', 'col2', 'col3'],
incompleteColumns: {},
},
},
};

const state = enrichBaseState(queryBaseState);

const optimizeMock = jest.spyOn(operationDefinitionMap.percentile, 'optimizeEsAggs');

indexPatternDatasource.toExpression(state, 'first');

expect(operationDefinitionMap.percentile.optimizeEsAggs).toHaveBeenCalledTimes(1);

optimizeMock.mockRestore();
});

describe('references', () => {
beforeEach(() => {
// @ts-expect-error we are inserting an invalid type
Expand Down

0 comments on commit 5d61742

Please sign in to comment.