Merge pull request #1674 from appsmithorg/fix/switch-content-type

Fix incorrect bodyFormData values being sent
This commit is contained in:
Nikhil Nandagopal 2020-11-10 19:20:11 +05:30 committed by GitHub
commit 3c37645d12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 9 deletions

View File

@ -44,16 +44,10 @@ export const transformRestAction = (data: any): any => {
contentType = contentTypeHeader.value;
}
}
let body: any = "";
if (
contentType !== POST_BODY_FORMAT_OPTIONS[1].value &&
contentType !== POST_BODY_FORMAT_OPTIONS[2].value
) {
action.actionConfiguration.bodyFormData = undefined;
if (action.actionConfiguration.body)
body = action.actionConfiguration.body || undefined;
}
let body: any = "";
if (action.actionConfiguration.body)
body = action.actionConfiguration.body || undefined;
if (!_.isString(body)) body = JSON.stringify(body);
action = {

View File

@ -102,6 +102,60 @@ describe("Api action transformer", () => {
expect(result).toEqual(output);
});
it("bodyFormData should not be reset for non xxx-form-encoded-data type", () => {
const input = {
...BASE_ACTION,
actionConfiguration: {
...BASE_ACTION.actionConfiguration,
httpMethod: "POST",
headers: [{ key: "content-type", value: "application/json" }],
body: "{ name: 'test' }",
bodyFormData: [{ key: "key", value: "value" }],
},
};
const output = {
...BASE_ACTION,
actionConfiguration: {
...BASE_ACTION.actionConfiguration,
httpMethod: "POST",
headers: [{ key: "content-type", value: "application/json" }],
body: "{ name: 'test' }",
bodyFormData: [{ key: "key", value: "value" }],
},
};
const result = transformRestAction(input);
expect(result).toEqual(output);
});
it("body should not be reset for xxx-form-encoded-data type", () => {
const input = {
...BASE_ACTION,
actionConfiguration: {
...BASE_ACTION.actionConfiguration,
httpMethod: "POST",
headers: [
{ key: "content-type", value: POST_BODY_FORMAT_OPTIONS[1].value },
],
bodyFormData: [{ key: "key", value: "value" }],
body: "{ name: 'test' }",
},
};
const output = {
...BASE_ACTION,
actionConfiguration: {
...BASE_ACTION.actionConfiguration,
httpMethod: "POST",
headers: [
{ key: "content-type", value: POST_BODY_FORMAT_OPTIONS[1].value },
],
body: "{ name: 'test' }",
bodyFormData: [{ key: "key", value: "value" }],
},
};
const result = transformRestAction(input);
expect(result).toEqual(output);
});
it("Sets the correct body for xxx-form-encoded-data display type", () => {
const input = {
...BASE_ACTION,