Skip to content

Commit

Permalink
test: add unit test for accepting axios params
Browse files Browse the repository at this point in the history
Signed-off-by: Dustin Popp <[email protected]>
  • Loading branch information
dpopp07 committed Mar 6, 2025
1 parent c9753b7 commit cd01179
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/unit/request-wrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,43 @@ describe('sendRequest', () => {
expect(mockAxiosInstance.mock.calls).toHaveLength(1);
});

it('should include any specified axios request options', async () => {
const parameters = {
defaultOptions: {
body: 'post=body',
formData: '',
qs: {},
method: 'POST',
url: 'https://example.ibm.com/v1',
headers: {
'test-header': 'test-header-value',
},
responseType: 'buffer',
axiosOptions: {
signal: 'mock',
},
},
};

mockAxiosInstance.mockResolvedValue(axiosResolveValue);

const res = await requestWrapperInstance.sendRequest(parameters);
// assert results
expect(mockAxiosInstance.mock.calls[0][0].data).toEqual('post=body');
expect(mockAxiosInstance.mock.calls[0][0].url).toEqual('https://example.ibm.com/v1');
expect(mockAxiosInstance.mock.calls[0][0].headers).toEqual({
'Accept-Encoding': 'gzip',
'test-header': 'test-header-value',
});
expect(mockAxiosInstance.mock.calls[0][0].method).toEqual(parameters.defaultOptions.method);
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual(
parameters.defaultOptions.responseType
);
expect(mockAxiosInstance.mock.calls[0][0].signal).toEqual('mock');
expect(res).toEqual(expectedResult);
expect(mockAxiosInstance.mock.calls).toHaveLength(1);
});

it('sendRequest should strip trailing slashes', async () => {
const parameters = {
defaultOptions: {
Expand Down

0 comments on commit cd01179

Please sign in to comment.