Skip to content

Commit f4aa4f9

Browse files
authored
fix: expose the body in the detailed response under the field result
1 parent ec83d60 commit f4aa4f9

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

lib/requestwrapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export class RequestWrapper {
226226
delete res.config;
227227
delete res.request;
228228
// the other sdks use the interface `result` for the body
229+
res.result = res.data;
229230
_callback(null, res.data, res);
230231
})
231232
.catch(error => {

test/unit/requestWrapper.test.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ describe('sendRequest', () => {
3030
mockAxiosInstance.mockReset();
3131
});
3232

33+
const axiosResolveValue = {
34+
data: 'test',
35+
config: 'test',
36+
request: 'test',
37+
statusText: 'test',
38+
status: 200,
39+
headers: 'test',
40+
};
41+
42+
const expectedResult = {
43+
data: 'test',
44+
result: 'test',
45+
statusText: 'test',
46+
status: 200,
47+
headers: 'test',
48+
};
49+
3350
it('should send a request with default parameters', done => {
3451
const parameters = {
3552
defaultOptions: {
@@ -46,7 +63,7 @@ describe('sendRequest', () => {
4663
},
4764
};
4865

49-
mockAxiosInstance.mockResolvedValue('res');
66+
mockAxiosInstance.mockResolvedValue(axiosResolveValue);
5067

5168
requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
5269
// assert results
@@ -62,7 +79,7 @@ describe('sendRequest', () => {
6279
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual(
6380
parameters.defaultOptions.responseType
6481
);
65-
expect(res).toEqual('res');
82+
expect(res).toEqual(expectedResult);
6683
expect(mockAxiosInstance.mock.calls.length).toBe(1);
6784
done();
6885
});
@@ -130,7 +147,7 @@ describe('sendRequest', () => {
130147
mockAxiosInstance.mockImplementation(requestParams => {
131148
// This runs the paramsSerializer code in the payload we send with axios
132149
serializedParams = requestParams.paramsSerializer(requestParams.params);
133-
return Promise.resolve('res');
150+
return Promise.resolve(axiosResolveValue);
134151
});
135152

136153
requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
@@ -150,7 +167,7 @@ describe('sendRequest', () => {
150167
version: '2018-10-15',
151168
});
152169
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual('json');
153-
expect(res).toEqual('res');
170+
expect(res).toEqual(expectedResult);
154171
expect(mockAxiosInstance.mock.calls.length).toBe(1);
155172
done();
156173
});
@@ -200,7 +217,7 @@ describe('sendRequest', () => {
200217

201218
mockAxiosInstance.mockImplementation(requestParams => {
202219
requestParams.paramsSerializer(requestParams.params);
203-
return Promise.resolve('res');
220+
return Promise.resolve(axiosResolveValue);
204221
});
205222

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

238-
expect(res).toEqual('res');
255+
expect(res).toEqual(expectedResult);
239256
expect(mockAxiosInstance.mock.calls.length).toBe(1);
240257
done();
241258
});
@@ -274,7 +291,7 @@ describe('sendRequest', () => {
274291

275292
mockAxiosInstance.mockImplementation(requestParams => {
276293
requestParams.paramsSerializer(requestParams.params);
277-
return Promise.resolve('res');
294+
return Promise.resolve(axiosResolveValue);
278295
});
279296

280297
requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
@@ -292,7 +309,7 @@ describe('sendRequest', () => {
292309
expect(mockAxiosInstance.mock.calls[0][0].method).toEqual(parameters.options.method);
293310
expect(mockAxiosInstance.mock.calls[0][0].params).toEqual(parameters.options.qs);
294311
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual('json');
295-
expect(res).toEqual('res');
312+
expect(res).toEqual(expectedResult);
296313
expect(mockAxiosInstance.mock.calls.length).toBe(1);
297314
done();
298315
});
@@ -325,7 +342,7 @@ describe('sendRequest', () => {
325342
// requestWrapperInstance.sendRequest(parameters, (err, body, res) => {
326343
// // assert results
327344
// expect(mockAxiosInstance.mock.calls[0][0].otherParam).toEqual(500);
328-
// expect(res).toEqual('res');
345+
// expect(res).toEqual(expectedResult);
329346
// expect(mockAxiosInstance.mock.calls.length).toBe(1);
330347
// done();
331348
// });

0 commit comments

Comments
 (0)