diff --git a/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.test.ts b/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.test.ts index a308cf150f804..8578e271f37b3 100644 --- a/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.test.ts +++ b/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.test.ts @@ -98,4 +98,36 @@ describe('sendRequestToES', () => { expect(mockedSendRequestToES).toHaveBeenCalledTimes(1); } }); + describe('successful response value', () => { + describe('with text', () => { + it('should return value with lines separated', async () => { + mockedSendRequestToES.mockResolvedValue('\ntest_index-1 [] \ntest_index-2 []\n'); + const response = await sendRequestToES({ + http: mockContextValue.services.http, + requests: [{ method: 'GET', url: 'test-1', data: [] }], + }); + + expect(response).toMatchInlineSnapshot(` + " + test_index-1 [] + test_index-2 [] + " + `); + expect(mockedSendRequestToES).toHaveBeenCalledTimes(1); + }); + }); + + describe('with parsed json', () => { + it('should stringify value', async () => { + mockedSendRequestToES.mockResolvedValue(JSON.stringify({ test: 'some value' })); + const response = await sendRequestToES({ + http: mockContextValue.services.http, + requests: [{ method: 'GET', url: 'test-2', data: [] }], + }); + + expect(typeof response).toBe('string'); + expect(mockedSendRequestToES).toHaveBeenCalledTimes(1); + }); + }); + }); }); diff --git a/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.ts b/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.ts index 94e184748908c..451198aaf2d2b 100644 --- a/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.ts +++ b/src/plugins/console/public/application/hooks/use_send_current_request_to_es/send_request_to_es.ts @@ -93,7 +93,7 @@ export function sendRequestToES(args: EsRequestArgs): Promise if (body instanceof ArrayBuffer) { value = body; } else { - value = JSON.stringify(body, null, 2); + value = typeof body === 'string' ? body : JSON.stringify(body, null, 2); } const warnings = response.headers.get('warning');