Skip to content

Commit

Permalink
fix: expose the body in the detailed response under the field result
Browse files Browse the repository at this point in the history
  • Loading branch information
dpopp07 committed Jun 6, 2019
1 parent ec83d60 commit f4aa4f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/requestwrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class RequestWrapper {
delete res.config;
delete res.request;
// the other sdks use the interface `result` for the body
res.result = res.data;
_callback(null, res.data, res);
})
.catch(error => {
Expand Down
35 changes: 26 additions & 9 deletions test/unit/requestWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ describe('sendRequest', () => {
mockAxiosInstance.mockReset();
});

const axiosResolveValue = {
data: 'test',
config: 'test',
request: 'test',
statusText: 'test',
status: 200,
headers: 'test',
};

const expectedResult = {
data: 'test',
result: 'test',
statusText: 'test',
status: 200,
headers: 'test',
};

it('should send a request with default parameters', done => {
const parameters = {
defaultOptions: {
Expand All @@ -46,7 +63,7 @@ describe('sendRequest', () => {
},
};

mockAxiosInstance.mockResolvedValue('res');
mockAxiosInstance.mockResolvedValue(axiosResolveValue);

requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
// assert results
Expand All @@ -62,7 +79,7 @@ describe('sendRequest', () => {
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual(
parameters.defaultOptions.responseType
);
expect(res).toEqual('res');
expect(res).toEqual(expectedResult);
expect(mockAxiosInstance.mock.calls.length).toBe(1);
done();
});
Expand Down Expand Up @@ -130,7 +147,7 @@ describe('sendRequest', () => {
mockAxiosInstance.mockImplementation(requestParams => {
// This runs the paramsSerializer code in the payload we send with axios
serializedParams = requestParams.paramsSerializer(requestParams.params);
return Promise.resolve('res');
return Promise.resolve(axiosResolveValue);
});

requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
Expand All @@ -150,7 +167,7 @@ describe('sendRequest', () => {
version: '2018-10-15',
});
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual('json');
expect(res).toEqual('res');
expect(res).toEqual(expectedResult);
expect(mockAxiosInstance.mock.calls.length).toBe(1);
done();
});
Expand Down Expand Up @@ -200,7 +217,7 @@ describe('sendRequest', () => {

mockAxiosInstance.mockImplementation(requestParams => {
requestParams.paramsSerializer(requestParams.params);
return Promise.resolve('res');
return Promise.resolve(axiosResolveValue);
});

requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
Expand Down Expand Up @@ -235,7 +252,7 @@ describe('sendRequest', () => {
'Content-Disposition: form-data; name=\\"no_data\\"'
);

expect(res).toEqual('res');
expect(res).toEqual(expectedResult);
expect(mockAxiosInstance.mock.calls.length).toBe(1);
done();
});
Expand Down Expand Up @@ -274,7 +291,7 @@ describe('sendRequest', () => {

mockAxiosInstance.mockImplementation(requestParams => {
requestParams.paramsSerializer(requestParams.params);
return Promise.resolve('res');
return Promise.resolve(axiosResolveValue);
});

requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
Expand All @@ -292,7 +309,7 @@ describe('sendRequest', () => {
expect(mockAxiosInstance.mock.calls[0][0].method).toEqual(parameters.options.method);
expect(mockAxiosInstance.mock.calls[0][0].params).toEqual(parameters.options.qs);
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual('json');
expect(res).toEqual('res');
expect(res).toEqual(expectedResult);
expect(mockAxiosInstance.mock.calls.length).toBe(1);
done();
});
Expand Down Expand Up @@ -325,7 +342,7 @@ describe('sendRequest', () => {
// requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
// // assert results
// expect(mockAxiosInstance.mock.calls[0][0].otherParam).toEqual(500);
// expect(res).toEqual('res');
// expect(res).toEqual(expectedResult);
// expect(mockAxiosInstance.mock.calls.length).toBe(1);
// done();
// });
Expand Down

0 comments on commit f4aa4f9

Please sign in to comment.