Skip to content

Commit

Permalink
[Dev Tools] Fix cat APIs returning as escaped string (#130638)
Browse files Browse the repository at this point in the history
* Fix escaped strings

* Add tests

Co-authored-by: Muhammad Ibragimov <[email protected]>
  • Loading branch information
mibragimov and Muhammad Ibragimov authored Apr 21, 2022
1 parent bb9fc4b commit 6e8d198
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function sendRequestToES(args: EsRequestArgs): Promise<ESRequestResult[]>
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');
Expand Down

0 comments on commit 6e8d198

Please sign in to comment.