[FIX] web: fix httpRequest GET + add in test_env

This commit fixes the method GET in httpRequest and
adds it in test_env.

Before this commit, the GET method crashed because
of the forced body param.

closes odoo/odoo#51980

X-original-commit: 7c4fba660a13c38048020faf595bd348d1bca225
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Michael Mattiello (mcm)
2020-05-27 12:26:05 +00:00
parent cf90b56c3c
commit b110bd4cbe
2 changed files with 21 additions and 15 deletions
+18 -15
View File
@@ -22,25 +22,28 @@ odoo.define("web.env", function (require) {
}
function httpRequest(route, params = {}, readMethod = 'json') {
const formData = new FormData();
for (const key in params) {
if (key === 'method') {
continue;
}
const value = params[key];
if (Array.isArray(value) && value.length) {
for (const val of value) {
formData.append(key, val);
const info = {
method: params.method || 'POST',
};
if (params.method !== 'GET') {
const formData = new FormData();
for (const key in params) {
if (key === 'method') {
continue;
}
const value = params[key];
if (Array.isArray(value) && value.length) {
for (const val of value) {
formData.append(key, val);
}
} else {
formData.append(key, value);
}
} else {
formData.append(key, value);
}
info.body = formData;
}
return fetch(route, {
method: params.method || 'POST',
body: formData,
}).then(response => response[readMethod]());
return fetch(route, info).then(response => response[readMethod]());
}
function navigate(url, params) {
@@ -49,6 +49,9 @@ odoo.define('web.test_env', async function (require) {
},
},
getCookie() { },
httpRequest() {
return Promise.resolve('');
},
rpc(params, options) {
const query = buildQuery(params);
return testEnv.session.rpc(query.route, query.params, options);