diff --git a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.test.ts b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.test.ts index 3d0a3181f8ab8..d8cb24b34496b 100644 --- a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.test.ts +++ b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.test.ts @@ -93,6 +93,17 @@ describe('EnterpriseSearchRequestHandler', () => { }); }); + it('passes request params', async () => { + const requestHandler = enterpriseSearchRequestHandler.createRequest({ + path: '/api/example', + }); + await makeAPICall(requestHandler, { query: { someQuery: false } }); + + EnterpriseSearchAPI.shouldHaveBeenCalledWith( + 'http://localhost:3002/api/example?someQuery=false' + ); + }); + it('passes custom params set by the handler, which override request params', async () => { const requestHandler = enterpriseSearchRequestHandler.createRequest({ path: '/api/example', @@ -104,6 +115,17 @@ describe('EnterpriseSearchRequestHandler', () => { 'http://localhost:3002/api/example?someQuery=true' ); }); + + it('correctly encodes paths and query string parameters', async () => { + const requestHandler = enterpriseSearchRequestHandler.createRequest({ + path: '/api/some example', + }); + await makeAPICall(requestHandler, { query: { 'page[current]': 1 } }); + + EnterpriseSearchAPI.shouldHaveBeenCalledWith( + 'http://localhost:3002/api/some%20example?page%5Bcurrent%5D=1' + ); + }); }); describe('response passing', () => { diff --git a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.ts b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.ts index 6b65c16c832fd..cb28cd2b90f4d 100644 --- a/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.ts +++ b/x-pack/plugins/enterprise_search/server/lib/enterprise_search_request_handler.ts @@ -69,7 +69,7 @@ export class EnterpriseSearchRequestHandler { const queryString = !this.isEmptyObj(queryParams) ? `?${querystring.stringify(queryParams)}` : ''; - const url = encodeURI(this.enterpriseSearchUrl + path + queryString); + const url = encodeURI(this.enterpriseSearchUrl + path) + queryString; // Set up API options const { method } = request.route;