Skip to content

Commit

Permalink
Fix request with disabled aggregation (#85696)
Browse files Browse the repository at this point in the history
* Fix request with disabled aggregation

* Update unit tests

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Daniil and kibanamachine authored Dec 21, 2020
1 parent 0d9b40d commit f67f1ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ describe('esaggs expression function - public', () => {
});
});

test('calls agg.postFlightRequest if it exiests', async () => {
test('calls agg.postFlightRequest if it exiests and agg is enabled', async () => {
mockParams.aggs.aggs[0].enabled = true;
await handleRequest(mockParams);
expect(mockParams.aggs.aggs[0].type.postFlightRequest).toHaveBeenCalledTimes(1);

Expand All @@ -160,6 +161,12 @@ describe('esaggs expression function - public', () => {
expect(async () => await handleRequest(mockParams)).not.toThrowError();
});

test('should skip agg.postFlightRequest call if the agg is disabled', async () => {
mockParams.aggs.aggs[0].enabled = false;
await handleRequest(mockParams);
expect(mockParams.aggs.aggs[0].type.postFlightRequest).toHaveBeenCalledTimes(0);
});

test('tabifies response data', async () => {
await handleRequest(mockParams);
expect(tabifyAggResponse).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const handleRequest = async ({
// response data incorrectly in the inspector.
let response = (searchSource as any).rawResponse;
for (const agg of aggs.aggs) {
if (typeof agg.type.postFlightRequest === 'function') {
if (agg.enabled && typeof agg.type.postFlightRequest === 'function') {
response = await agg.type.postFlightRequest(
response,
aggs,
Expand Down

0 comments on commit f67f1ec

Please sign in to comment.