forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00a22d6
commit ba50e95
Showing
18 changed files
with
351 additions
and
42 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/plugins/search/public/es_search/es_search_strategy.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,52 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { coreMock } from '../../../../core/public/mocks'; | ||
import { esSearchStrategyProvider } from './es_search_strategy'; | ||
import { CoreSetup } from 'kibana/public'; | ||
import { ES_SEARCH_STRATEGY } from '../../common/es_search'; | ||
|
||
describe('ES search strategy', () => { | ||
let mockCoreSetup: MockedKeys<CoreSetup>; | ||
const mockSearch = jest.fn(); | ||
|
||
beforeEach(() => { | ||
mockCoreSetup = coreMock.createSetup(); | ||
mockSearch.mockClear(); | ||
}); | ||
|
||
it('returns a strategy with `search` that calls the sync search `search`', () => { | ||
const request = { params: {} }; | ||
const options = {}; | ||
|
||
const esSearch = esSearchStrategyProvider( | ||
{ | ||
core: mockCoreSetup, | ||
}, | ||
mockSearch | ||
); | ||
esSearch.search(request, options); | ||
|
||
expect(mockSearch.mock.calls[0][0]).toEqual({ | ||
...request, | ||
serverStrategy: ES_SEARCH_STRATEGY, | ||
}); | ||
expect(mockSearch.mock.calls[0][1]).toBe(options); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { coreMock } from '../../../../core/public/mocks'; | ||
import { EsSearchService } from './plugin'; | ||
import { CoreSetup } from '../../../../core/public'; | ||
import { searchSetupMock } from '../mocks'; | ||
|
||
describe('ES search strategy service', () => { | ||
let service: EsSearchService; | ||
let mockCoreSetup: MockedKeys<CoreSetup>; | ||
const opaqueId = Symbol(); | ||
|
||
beforeEach(() => { | ||
service = new EsSearchService({ opaqueId }); | ||
mockCoreSetup = coreMock.createSetup(); | ||
}); | ||
|
||
describe('setup()', () => { | ||
it('registers the ES search strategy', async () => { | ||
service.setup(mockCoreSetup, { | ||
search: searchSetupMock, | ||
}); | ||
expect(searchSetupMock.registerSearchStrategyProvider).toBeCalled(); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export const searchSetupMock = { | ||
registerSearchStrategyContext: jest.fn(), | ||
registerSearchStrategyProvider: jest.fn(), | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { coreMock } from '../../../core/public/mocks'; | ||
import { SYNC_SEARCH_STRATEGY, syncSearchStrategyProvider } from './sync_search_strategy'; | ||
import { CoreSetup } from '../../../core/public'; | ||
|
||
describe('Sync search strategy', () => { | ||
let mockCoreSetup: MockedKeys<CoreSetup>; | ||
const mockSearch = jest.fn(); | ||
|
||
beforeEach(() => { | ||
mockCoreSetup = coreMock.createSetup(); | ||
}); | ||
|
||
it('returns a strategy with `search` that calls the backend API', () => { | ||
mockCoreSetup.http.fetch.mockImplementationOnce(() => Promise.resolve()); | ||
|
||
const syncSearch = syncSearchStrategyProvider( | ||
{ | ||
core: mockCoreSetup, | ||
}, | ||
mockSearch | ||
); | ||
syncSearch.search( | ||
{ | ||
serverStrategy: SYNC_SEARCH_STRATEGY, | ||
}, | ||
{} | ||
); | ||
expect(mockCoreSetup.http.fetch.mock.calls[0][0]).toBe(`/api/search/${SYNC_SEARCH_STRATEGY}`); | ||
expect(mockCoreSetup.http.fetch.mock.calls[0][1]).toEqual({ | ||
body: JSON.stringify({ | ||
serverStrategy: 'SYNC_SEARCH_STRATEGY', | ||
}), | ||
method: 'POST', | ||
signal: undefined, | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { createApi } from './create_api'; | ||
|
||
import { TSearchStrategiesMap } from './i_search_strategy'; | ||
import { IRouteHandlerSearchContext } from './i_route_handler_search_context'; | ||
import { DEFAULT_SEARCH_STRATEGY } from '../common'; | ||
|
||
// let mockCoreSetup: MockedKeys<CoreSetup>; | ||
|
||
const mockDefaultSearch = jest.fn(() => Promise.resolve({ percentComplete: 0 })); | ||
const mockDefaultSearchStrategyProvider = jest.fn(() => | ||
Promise.resolve({ | ||
search: mockDefaultSearch, | ||
}) | ||
); | ||
const mockStrategies: TSearchStrategiesMap = { | ||
[DEFAULT_SEARCH_STRATEGY]: mockDefaultSearchStrategyProvider, | ||
}; | ||
|
||
describe('createApi', () => { | ||
let api: IRouteHandlerSearchContext; | ||
|
||
beforeEach(() => { | ||
api = createApi({ | ||
caller: jest.fn(), | ||
searchStrategies: mockStrategies, | ||
}); | ||
mockDefaultSearchStrategyProvider.mockClear(); | ||
}); | ||
|
||
it('should default to DEFAULT_SEARCH_STRATEGY if none is provided', async () => { | ||
await api.search({ | ||
params: {}, | ||
}); | ||
expect(mockDefaultSearchStrategyProvider).toBeCalled(); | ||
expect(mockDefaultSearch).toBeCalled(); | ||
}); | ||
|
||
it('should throw if no provider is found for the given name', () => { | ||
expect(api.search({}, 'noneByThisName')).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"No strategy found for noneByThisName"` | ||
); | ||
}); | ||
}); |
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
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,27 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { plugin } from '.'; | ||
import { coreMock } from '../../../core/server/mocks'; | ||
|
||
it('search service is instantiated', () => { | ||
const context = coreMock.createPluginInitializerContext({}); | ||
const searchPlugin = plugin(context); | ||
expect(searchPlugin).toBeDefined(); | ||
}); |
Oops, something went wrong.