* fixes rght body type not selected after curlimport * added apiContentType key in ActionConfiguration formData property This commit fixes the bug https://github.com/appsmithorg/appsmith/issues/13978 and changes two files: * appsmith-server/src/test/java/com/appsmith/server/services/CurlImporterServiceTest.java * appsmith-server/src/main/java/com/appsmith/server/services/ce/CurlImporterServiceCEImpl.java additionaly this commit fixes the Body type detection for REST APIs with GET method when imported from cURL. * Made changes to the casing of Header key 'content-type', now it is HTTPHeader.CONTENT_TYPE standard -> 'Content-Type'. changed test cases accordingly. * Made header-key check in assertHeader functions case insensitive in CurlImporterServiceTest.java * removed wildcard imports and changed some comments * changes according to PR review comments * updated imports for APIPaneUtils Co-authored-by: “sneha122” <“sneha@appsmith.com”> Co-authored-by: manish kumar <manish@appsmith.com>
72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
import { POST_BODY_FORMAT_OPTIONS } from "constants/ApiEditorConstants/CommonApiConstants";
|
|
import { getContentTypeHeaderValue, getIndextoUpdate, parseUrlForQueryParams } from "utils/ApiPaneUtils";
|
|
|
|
describe("api pane header insertion or removal", () => {
|
|
describe("index for header needs to be returned", () => {
|
|
test("it gives correct index", () => {
|
|
const headers = [
|
|
{ key: "content-type", value: "application/json" },
|
|
{ key: "", value: "" },
|
|
{ key: "", value: "" },
|
|
{ key: "", value: "" },
|
|
];
|
|
const headerIndex = 0;
|
|
expect(getIndextoUpdate(headers, headerIndex)).toEqual(headerIndex);
|
|
const headers2 = [
|
|
{ key: "", value: "" },
|
|
{ key: "", value: "" },
|
|
{ key: "", value: "" },
|
|
];
|
|
const headerIndex2 = -1;
|
|
expect(getIndextoUpdate(headers2, headerIndex2)).toEqual(0);
|
|
|
|
const headers3 = [
|
|
{ key: "abc", value: "abc" },
|
|
{ key: "def", value: "def" },
|
|
{ key: "ghi", value: "ghi" },
|
|
];
|
|
const headerIndex3 = -1;
|
|
expect(getIndextoUpdate(headers3, headerIndex3)).toEqual(headers3.length);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Api pane query parameters parsing", () => {
|
|
test("It gives correct query parameters", () => {
|
|
const url1 = "user?q=2&b='Auth=xyz'";
|
|
const params1 = [
|
|
{ key: "q", value: "2" },
|
|
{ key: "b", value: "'Auth=xyz'" },
|
|
];
|
|
expect(parseUrlForQueryParams(url1)).toEqual(params1);
|
|
const url2 = "/user?q=2&b='Auth=xyz'";
|
|
expect(parseUrlForQueryParams(url2)).toEqual(params1);
|
|
const url3 = "user?q=2&b={{Api1.data.isLatest ? 'v1' : 'v2'}}";
|
|
const params2 = [
|
|
{ key: "q", value: "2" },
|
|
{ key: "b", value: "{{Api1.data.isLatest ? 'v1' : 'v2'}}" },
|
|
];
|
|
expect(parseUrlForQueryParams(url3)).toEqual(params2);
|
|
const url4 = "";
|
|
const params3 = [
|
|
{ key: "", value: "" },
|
|
{ key: "", value: "" },
|
|
];
|
|
expect(parseUrlForQueryParams(url4)).toEqual(params3);
|
|
const url5 = "/";
|
|
expect(parseUrlForQueryParams(url5)).toEqual(params3);
|
|
});
|
|
});
|
|
|
|
describe("API Body Format Test", () => {
|
|
it("it checks whether selected body format is as per the content-type header or not", () => {
|
|
const headers = [
|
|
{
|
|
"key": "Content-Type",
|
|
"value": "application/x-www-form-urlencoded"
|
|
}
|
|
];
|
|
expect(getContentTypeHeaderValue(headers)).toEqual(POST_BODY_FORMAT_OPTIONS.FORM_URLENCODED);
|
|
});
|
|
});
|