import { RequestHandler , RequestHandlerContext } from 'src/core/server' ; import { elasticsearchServiceMock , savedObjectsClientMock , deprecationsServiceMock , } from '../../../../../../src/core/server/mocks' ; export const routeHandlerContextMock = { core : { elasticsearch : { client : elasticsearchServiceMock . createScopedClusterClient ( ) , } , savedObjects : { client : savedObjectsClientMock . create ( ) } , deprecations : { client : deprecationsServiceMock . createClient ( ) } , } , } as unknown as RequestHandlerContext ; /**
 * Creates a very crude mock of the new platform router implementation. This enables use to test
 * controller/handler logic without making HTTP requests to an actual server. This does not enable
 * us to test whether our paths actual match, only the response codes of controllers given certain
 * inputs. This should be replaced by a more wholistic solution (like functional tests) eventually.
 *
 * This also bypasses any validation installed on the route.
 */ export const createMockRouter = ( ) => { const paths = { } ; const assign = ( method ) => ( { path } , handler ) => { paths [ method ] = { ... ( paths [ method ] || { } ) , ... { [ path ] : handler } , } ; } ; return { getHandler ( { method , pathPattern } ) { return paths [ method ] [ pathPattern ] ; } , get : assign ( 'get' ) , post : assign ( 'post' ) , put : assign ( 'put' ) , patch : assign ( 'patch' ) , delete : assign ( 'delete' ) , } ; } ; export type MockRouter = ReturnType < typeof createMockRouter > ;