diff --git a/src/core/server/http/http_server.mocks.ts b/src/core/server/http/http_server.mocks.ts index 81d756f47d760..c586cf6a9825f 100644 --- a/src/core/server/http/http_server.mocks.ts +++ b/src/core/server/http/http_server.mocks.ts @@ -28,12 +28,13 @@ import { LifecycleResponseFactory, RouteMethod, KibanaResponseFactory, + RouteValidationSpec, } from './router'; import { OnPreResponseToolkit } from './lifecycle/on_pre_response'; import { OnPostAuthToolkit } from './lifecycle/on_post_auth'; import { OnPreAuthToolkit } from './lifecycle/on_pre_auth'; -interface RequestFixtureOptions { +interface RequestFixtureOptions

{ headers?: Record; params?: Record; body?: Record; @@ -42,9 +43,14 @@ interface RequestFixtureOptions { method?: RouteMethod; socket?: Socket; routeTags?: string[]; + validation?: { + params?: RouteValidationSpec

; + query?: RouteValidationSpec; + body?: RouteValidationSpec; + }; } -function createKibanaRequestMock({ +function createKibanaRequestMock

({ path = '/path', headers = { accept: 'something/html' }, params = {}, @@ -53,10 +59,11 @@ function createKibanaRequestMock({ method = 'get', socket = new Socket(), routeTags, -}: RequestFixtureOptions = {}) { + validation = {}, +}: RequestFixtureOptions = {}) { const queryString = stringify(query, { sort: false }); - return KibanaRequest.from( + return KibanaRequest.from( createRawRequestMock({ headers, params, @@ -76,9 +83,9 @@ function createKibanaRequestMock({ }, }), { - params: schema.object({}, { allowUnknowns: true }), - body: schema.object({}, { allowUnknowns: true }), - query: schema.object({}, { allowUnknowns: true }), + params: validation.params || schema.any(), + body: validation.body || schema.any(), + query: validation.query || schema.any(), } ); }