Merge pull request #1674 from appsmithorg/fix/switch-content-type
Fix incorrect bodyFormData values being sent
This commit is contained in:
commit
3c37645d12
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user