chore: set the view mode when fetching actions for action collection (#34535)

## 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"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9691919440>
> Commit: f3b7bdd5a23ffcc891fffb51aaed39266f8d2dad
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9691919440&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS,@tag.Sanity`

<!-- end of auto-generated comment: Cypress test results  -->



## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
This commit is contained in:
Nilesh Sarupriya 2024-06-27 15:46:28 -05:00 committed by GitHub
parent 32147ddfdb
commit b6920830ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View File

@ -255,7 +255,7 @@ public class ActionCollectionServiceCEImpl extends BaseService<ActionCollectionR
actionCollectionViewDTO.setDefaultResources(defaults);
return newActionService
.findByCollectionIdAndViewMode(actionCollection.getId(), viewMode, aclPermission)
.map(action -> newActionService.generateActionByViewMode(action, false))
.map(action -> newActionService.generateActionByViewMode(action, viewMode))
.collectList()
.map(actionDTOList -> {
actionCollectionViewDTO.setActions(actionDTOList);

View File

@ -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<List<ActionCollectionViewDTO>> 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<List<ActionCollectionViewDTO>> 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());