Skip to content

Commit

Permalink
fix(api-core): format postGet payload to standard
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSharpieOne committed Jun 19, 2018
1 parent db547f8 commit 5b885cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/api-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"qs": "^6.5.2"
}
}
10 changes: 10 additions & 0 deletions packages/api-core/src/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AvLocalStorage from '@availity/localstorage-core';
import qs from 'qs';

import API_OPTIONS from './options';

Expand Down Expand Up @@ -212,11 +213,20 @@ export default class AvApi {
config.method = 'POST';
config.headers = config.headers || {};
config.headers['X-HTTP-Method-Override'] = 'GET';
config.headers['Content-Type'] = config.headers['Content-Type'] || 'application/x-www-form-urlencoded';
config.url = this.getUrl(config);
config.data = data;
if (this.beforePostGet) {
config.data = this.beforePostGet(config.data);
}
if (typeof config.data !== 'string' && config.headers['Content-Type'] === 'application/x-www-form-urlencoded') {
config.data = qs.stringify(config.data, {
encode: false,
arrayFormat: 'repeat',
indices: false,
allowDots: true,
});
}
return this.request(config, this.afterPostGet);
}

Expand Down
6 changes: 4 additions & 2 deletions packages/api-core/src/tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,11 @@ describe('AvApi', () => {
url: testUrl,
headers: {
'X-HTTP-Method-Override': 'GET',
'Content-Type': 'application/x-www-form-urlencoded',
},
},
config,
{ data }
{ data: 'testData=data' }
);
api.postGet(data, config);
expect(api.getUrl).toHaveBeenLastCalledWith(expectedConfig);
Expand All @@ -789,10 +790,11 @@ describe('AvApi', () => {
url: testUrl,
headers: {
'X-HTTP-Method-Override': 'GET',
'Content-Type': 'application/x-www-form-urlencoded',
},
},
config,
{ data }
{ data: 'testData=data' }
);
api.beforePostGet = jest.fn(thisData => thisData);
api.postGet(data, config);
Expand Down

0 comments on commit 5b885cf

Please sign in to comment.