Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
fix formData submissions by calling axios directly
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Jan 23, 2021
1 parent c0cbcc1 commit 6be6ce5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
9 changes: 7 additions & 2 deletions lib/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,13 @@ function post(path, params, callback) {
const config = (0, _Utils.mapToAxiosConfig)({ ...params,
url,
auth
});
return _languageCommon.http.post(config)(state).then(response => {
}); // NOTE: that in order to use multipart/form submissions, we call axios.post
// directly so as to avoid calling 'expandReferences' on the config (in
// language-common.http.post) once we've set up the 'form-data' module.
// Elsewhere, calling expandReferences multiple times is harmless.

return axios.post(config.url, config.data, { ...config
}).then(response => {
const nextState = (0, _languageCommon.composeNextState)(state, response.data);
if (callback) return callback(nextState);
return nextState;
Expand Down
16 changes: 9 additions & 7 deletions src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,15 @@ export function post(path, params, callback) {

const config = mapToAxiosConfig({ ...params, url, auth });

return http
.post(config)(state)
.then(response => {
const nextState = composeNextState(state, response.data);
if (callback) return callback(nextState);
return nextState;
});
// NOTE: that in order to use multipart/form submissions, we call axios.post
// directly so as to avoid calling 'expandReferences' on the config (in
// language-common.http.post) once we've set up the 'form-data' module.
// Elsewhere, calling expandReferences multiple times is harmless.
return axios.post(config.url, config.data, { ...config }).then(response => {
const nextState = composeNextState(state, response.data);
if (callback) return callback(nextState);
return nextState;
});
};
}

Expand Down
11 changes: 7 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ describe('post', () => {
)(state);

expect(finalState.data.body).to.contain(
'Content-Disposition: form-data; name="username"\r\n\r\n'
'Content-Disposition: form-data; name="username"\r\n\r\nfake'
);
expect(finalState.data.body).to.contain(
'Content-Disposition: form-data; name="password"\r\n\r\n'
'Content-Disposition: form-data; name="password"\r\n\r\nfake_pass'
);
});

Expand All @@ -482,10 +482,13 @@ describe('post', () => {
)(state);

expect(finalState.data.body).to.contain(
'Content-Disposition: form-data; name="username"\r\n\r\n'
'Content-Disposition: form-data; name="id"\r\n\r\nfake_id'
);
expect(finalState.data.body).to.contain(
'Content-Disposition: form-data; name="password"\r\n\r\n'
'Content-Disposition: form-data; name="parent"\r\n\r\nfake_parent'
);
expect(finalState.data.body).to.contain(
'Content-Disposition: form-data; name="mobile_phone"\r\n\r\nfake_phone'
);
});

Expand Down

0 comments on commit 6be6ce5

Please sign in to comment.