From 45e6d68fe04e2c66baddbd0e0da77e78da9d421d Mon Sep 17 00:00:00 2001 From: Muhammad Ibragimov Date: Wed, 20 Apr 2022 05:51:02 -0700 Subject: [PATCH] Add tests --- .../send_request_to_es.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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); + }); + }); + }); });