-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add the ability to override runtime_mappings Closes: #107855 * runtime_mappings not correctly logged in Inspect panel.
- Loading branch information
Showing
5 changed files
with
116 additions
and
21 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/plugins/vis_type_vega/public/data_model/search_api.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { extendSearchParamsWithRuntimeFields } from './search_api'; | ||
import { dataPluginMock } from '../../../data/public/mocks'; | ||
|
||
import { getSearchParamsFromRequest, DataPublicPluginStart } from '../../../data/public'; | ||
|
||
const mockComputedFields = ( | ||
dataStart: DataPublicPluginStart, | ||
index: string, | ||
runtimeFields: Record<string, unknown> | ||
) => { | ||
dataStart.indexPatterns.find = jest.fn().mockReturnValue([ | ||
{ | ||
title: index, | ||
getComputedFields: () => ({ | ||
runtimeFields, | ||
}), | ||
}, | ||
]); | ||
}; | ||
|
||
describe('extendSearchParamsWithRuntimeFields', () => { | ||
let dataStart: DataPublicPluginStart; | ||
|
||
beforeEach(() => { | ||
dataStart = dataPluginMock.createStartContract(); | ||
}); | ||
|
||
test('should inject default runtime_mappings for known indexes', async () => { | ||
const requestParams = {}; | ||
const runtimeFields = { foo: {} }; | ||
|
||
mockComputedFields(dataStart, 'index', runtimeFields); | ||
|
||
expect( | ||
await extendSearchParamsWithRuntimeFields(dataStart.indexPatterns, requestParams, 'index') | ||
).toMatchInlineSnapshot(` | ||
Object { | ||
"body": Object { | ||
"runtime_mappings": Object { | ||
"foo": Object {}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
test('should use runtime mappings from spec if it is specified', async () => { | ||
const requestParams = ({ | ||
body: { | ||
runtime_mappings: { | ||
test: {}, | ||
}, | ||
}, | ||
} as unknown) as ReturnType<typeof getSearchParamsFromRequest>; | ||
const runtimeFields = { foo: {} }; | ||
|
||
mockComputedFields(dataStart, 'index', runtimeFields); | ||
|
||
expect( | ||
await extendSearchParamsWithRuntimeFields(dataStart.indexPatterns, requestParams, 'index') | ||
).toMatchInlineSnapshot(` | ||
Object { | ||
"body": Object { | ||
"runtime_mappings": Object { | ||
"test": Object {}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters