kibana/x-pack/plugins/global_search/server/mocks.ts
Pierre Gayvallet a02c00b8a3
Change ContextContainer to lazily initialize providers (#129896)
* Change ContextContainer to lazily initialize providers

* Introduce CustomRequestHandlerContext, start adapting usages

* adapt IContextProvider's return type

* start fixing violations

* fixing violations - 2

* adapt home routes

* fix remaining core violation

* fix violations on core tests

* fixing more violations

* fixing more violations

* update generated doc...

* fix more violations

* adapt remaining RequestHandlerContext

* fix more violations

* fix non-async method

* more fixes

* fix another await in non async method

* add yet another missing async

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* add yet yet another missing async

* update fleet's endpoints

* fix telemetry endpoints

* fix event_log endpoints

* fix some security unit tests

* adapt canvas routes

* adapt alerting routes

* adapt more so_tagging routes

* fix data_enhanced routes

* fix license_management routes

* fix file_upload routes

* fix index_management routes

* fix lists routes

* fix snapshot_restore routes

* fix rule_registry routes

* fix ingest_pipelines routes

* fix remote_clusters routes

* fix index_lifecycle_management routes

* improve and fix the lazy implementation

* fix triggers_actions_ui endpoints

* start fixing unit tests

* fix cases routes

* fix transform routes

* fix upgrade_assistant routes

* fix uptime route wrapper

* fix uptime route wrapper bis

* update osquery routes

* update cross_cluster_replication routes

* fix some ML routes / wrappers

* adapt maps routes

* adapt rollup routes

* fix some canvas unit tests

* fix more canvas unit tests

* fix observability wrapper

* fix (?) infra type hell

* start fixing monitoring

* fix a few test plugins

* woups

* fix yet more violations

* fixing UA  tests

* fix logstash handlers

* fix fleet unit tests

* lint?

* one more batch

* update security_solution endpoints

* start fixing security_solution mocks

* start fixing security_solution tests

* fix more security_solution tests

* fix more security_solution tests

* just one more

* fix last (?) security_solution tests

* fix timelion javascript file

* fix more test plugins

* fix transforms context type

* fix ml context type

* fix context tests

* fix securitySolution withEndpointAuthz tests

* fix features unit tests

* fix actions unit tests

* fix imports

* fix duplicate import

* fix some merge problems

* fix new usage

* fix new test

* introduces context.resolve

* down the rabbit hole again

* start fixing test type failures

* more test type failures fixes

* move import comment back to correct place

* more test type failures fixes, bis

* use context.resolve for security solution rules routes

* fix new violations due to master merge

* remove comment

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-04-22 13:15:58 +02:00

67 lines
2 KiB
TypeScript

/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { of } from 'rxjs';
import { coreMock } from '@kbn/core/server/mocks';
import {
GlobalSearchPluginSetup,
GlobalSearchPluginStart,
RouteHandlerGlobalSearchContext,
GlobalSearchRequestHandlerContext,
} from './types';
import { searchServiceMock } from './services/search_service.mock';
import { contextMock } from './services/context.mock';
const createSetupMock = (): jest.Mocked<GlobalSearchPluginSetup> => {
const searchMock = searchServiceMock.createSetupContract();
return {
registerResultProvider: searchMock.registerResultProvider,
};
};
const createStartMock = (): jest.Mocked<GlobalSearchPluginStart> => {
const searchMock = searchServiceMock.createStartContract();
return {
find: searchMock.find,
getSearchableTypes: searchMock.getSearchableTypes,
};
};
const createRouteHandlerContextMock = (): jest.Mocked<RouteHandlerGlobalSearchContext> => {
const handlerContextMock = {
find: jest.fn(),
getSearchableTypes: jest.fn(),
};
handlerContextMock.find.mockReturnValue(of([]));
return handlerContextMock;
};
const createRequestHandlerContextMock = (): jest.Mocked<GlobalSearchRequestHandlerContext> => {
const handlerContextMock = {
find: jest.fn(),
getSearchableTypes: jest.fn(),
};
handlerContextMock.find.mockReturnValue(of([]));
return coreMock.createCustomRequestHandlerContext({
core: coreMock.createRequestHandlerContext(),
globalSearch: handlerContextMock,
});
};
export const globalSearchPluginMock = {
createSetupContract: createSetupMock,
createStartContract: createStartMock,
createRouteHandlerContext: createRouteHandlerContextMock,
createProviderContext: contextMock.create,
createRequestHandlerContext: createRequestHandlerContextMock,
};