diff --git a/lib/Adaptor.js b/lib/Adaptor.js index 592cc70..011c3fc 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -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; diff --git a/src/Adaptor.js b/src/Adaptor.js index c9de949..4a70732 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -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; + }); }; } diff --git a/test/index.js b/test/index.js index a5a09cc..d61c3a4 100644 --- a/test/index.js +++ b/test/index.js @@ -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' ); }); @@ -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' ); });