From b6920830ff285de55cc8c31192e429981c4e5b02 Mon Sep 17 00:00:00 2001 From: Nilesh Sarupriya Date: Thu, 27 Jun 2024 15:46:28 -0500 Subject: [PATCH] chore: set the view mode when fetching actions for action collection (#34535) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description > Fetch the correct actions for action collection based on view mode. Fixes [[Bug]: When triggering a workflow, unpublished js object is being used instead of a published one.](https://github.com/appsmithorg/appsmith/issues/34520) ## Automation /ok-to-test tags="@tag.JS,@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: f3b7bdd5a23ffcc891fffb51aaed39266f8d2dad > Cypress dashboard. > Tags: `@tag.JS,@tag.Sanity` ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of action collections in view mode for better accuracy. - **Tests** - Enhanced tests for action collections, ensuring better validation of collection IDs and metadata. Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> --- .../base/ActionCollectionServiceCEImpl.java | 2 +- .../services/ActionCollectionServiceTest.java | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java index 8018b14e23..909a7a3ed1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java @@ -255,7 +255,7 @@ public class ActionCollectionServiceCEImpl extends BaseService newActionService.generateActionByViewMode(action, false)) + .map(action -> newActionService.generateActionByViewMode(action, viewMode)) .collectList() .map(actionDTOList -> { actionCollectionViewDTO.setActions(actionDTOList); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java index 661c0bcea9..cf4b007d23 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java @@ -617,14 +617,25 @@ public class ActionCollectionServiceTest { actionCollectionDTO.setActions(List.of(action1)); actionCollectionDTO.setPluginType(PluginType.JS); - final ActionCollectionDTO createdActionCollectionDTO = layoutCollectionService + ActionCollectionDTO createdActionCollectionDTO = layoutCollectionService .createCollection(actionCollectionDTO, null) .block(); assert createdActionCollectionDTO != null; + assert createdActionCollectionDTO.getId() != null; + String createdActionCollectionId = createdActionCollectionDTO.getId(); - final Mono> viewModeCollectionsMono = applicationPageService - .publish(testApp.getId(), true) - .thenMany(actionCollectionService.getActionCollectionsForViewMode(testApp.getId(), null)) + applicationPageService.publish(testApp.getId(), true).block(); + + actionCollectionDTO.getActions().get(0).getActionConfiguration().setBody("updatedBody"); + + ActionCollectionDTO updatedActionCollectionDTO = layoutCollectionService + .updateUnpublishedActionCollection(createdActionCollectionId, actionCollectionDTO, null) + .block(); + assert updatedActionCollectionDTO != null; + assert updatedActionCollectionDTO.getId() != null; + + final Mono> viewModeCollectionsMono = actionCollectionService + .getActionCollectionsForViewMode(testApp.getId(), null) .collectList(); StepVerifier.create(viewModeCollectionsMono) @@ -645,7 +656,7 @@ public class ActionCollectionServiceTest { assertThat(variables.get(0).getValue()).isEqualTo("test"); // Metadata - assertThat(actionCollectionViewDTO.getId()).isEqualTo(createdActionCollectionDTO.getId()); + assertThat(actionCollectionViewDTO.getId()).isEqualTo(createdActionCollectionId); assertThat(actionCollectionViewDTO.getName()).isEqualTo("testCollection1"); assertThat(actionCollectionViewDTO.getApplicationId()).isEqualTo(testApp.getId()); assertThat(actionCollectionViewDTO.getPageId()).isEqualTo(testPage.getId());