From 4c346def9be5f4b613b775a23aa217537b97c8bd Mon Sep 17 00:00:00 2001 From: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:04:53 +0100 Subject: [PATCH] fix: Fix Evaluated value paths for objects (#24407) This issue fixes the evaluated value for path fields that holds objects, booleans or arrays. #### PR fixes following issue(s) Fixes #24397 #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- .../ServerSide/ApiTests/API_EvaluatedValue_spec.ts | 10 ++++++++++ app/client/cypress/support/Pages/ApiPage.ts | 6 +++++- .../form/fields/EmbeddedDatasourcePathField.tsx | 10 ++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_EvaluatedValue_spec.ts diff --git a/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_EvaluatedValue_spec.ts b/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_EvaluatedValue_spec.ts new file mode 100644 index 0000000000..57813f9388 --- /dev/null +++ b/app/client/cypress/e2e/Regression/ServerSide/ApiTests/API_EvaluatedValue_spec.ts @@ -0,0 +1,10 @@ +import { ObjectsRegistry } from "../../../../support/Objects/Registry"; + +const apiPage = ObjectsRegistry.ApiPage; + +describe("Validate API URL Evaluated value", () => { + it("1. Check if url object does not crash App", () => { + apiPage.CreateApi("FirstAPI"); + apiPage.EnterURL(`{{{"key": "value"}}}`, true, `{"key":"value"}`); + }); +}); diff --git a/app/client/cypress/support/Pages/ApiPage.ts b/app/client/cypress/support/Pages/ApiPage.ts index d5bf3a03a6..cdfdcd9697 100644 --- a/app/client/cypress/support/Pages/ApiPage.ts +++ b/app/client/cypress/support/Pages/ApiPage.ts @@ -129,13 +129,17 @@ export class ApiPage { cy.get(this._apiRunBtn).should(query); } - EnterURL(url: string) { + EnterURL(url: string, validateEvaluatedValue = false, evaluatedValue = "") { this.agHelper.EnterValue(url, { propFieldName: this._resourceUrl, directInput: true, inputFieldName: "", }); this.agHelper.AssertAutoSave(); + + if (validateEvaluatedValue) { + this.agHelper.VerifyEvaluatedValue(evaluatedValue); + } } EnterHeader(hKey: string, hValue: string, index = 0) { diff --git a/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx b/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx index 9b3d7807d7..b1b172a2bf 100644 --- a/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx +++ b/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx @@ -57,6 +57,7 @@ import LazyCodeEditor from "components/editorComponents/LazyCodeEditor"; import { getCodeMirrorNamespaceFromEditor } from "utils/getCodeMirrorNamespace"; import { isDynamicValue } from "utils/DynamicBindingUtils"; import { DEFAULT_DATASOURCE_NAME } from "constants/ApiEditorConstants/ApiEditorConstants"; +import { isString } from "lodash"; type ReduxStateProps = { workspaceId: string; @@ -397,9 +398,14 @@ class EmbeddedDatasourcePathComponent extends React.Component< if ("ENTITY_TYPE" in entity && entity.ENTITY_TYPE === ENTITY_TYPE.ACTION) { let evaluatedPath = "path" in entity.config ? entity.config.path : ""; - if (evaluatedPath && evaluatedPath.indexOf("?") > -1) { - evaluatedPath = extractApiUrlPath(evaluatedPath); + if (evaluatedPath) { + if (isString(evaluatedPath) && evaluatedPath.indexOf("?") > -1) { + evaluatedPath = extractApiUrlPath(evaluatedPath); + } else { + evaluatedPath = JSON.stringify(evaluatedPath); + } } + const evaluatedQueryParameters = entity?.config?.queryParameters ?.filter((p: KeyValuePair) => !!p?.key) .map(