-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: avoiding unnecessary update page layouts in js action update #37062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
7769933
08baaa7
6f27a7b
1a91165
3b5e6c7
95cc7e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| import com.appsmith.server.dtos.WorkspacePluginStatus; | ||
| import com.appsmith.server.helpers.MockPluginExecutor; | ||
| import com.appsmith.server.helpers.PluginExecutorHelper; | ||
| import com.appsmith.server.layouts.UpdateLayoutService; | ||
| import com.appsmith.server.newactions.base.NewActionService; | ||
| import com.appsmith.server.newpages.base.NewPageService; | ||
| import com.appsmith.server.plugins.base.PluginService; | ||
|
|
@@ -134,6 +135,9 @@ public class ActionCollectionServiceTest { | |
| @MockBean | ||
| PluginExecutor pluginExecutor; | ||
|
|
||
| @MockBean | ||
| UpdateLayoutService updateLayoutService; | ||
|
|
||
| Application testApp = null; | ||
|
|
||
| PageDTO testPage = null; | ||
|
|
@@ -700,4 +704,73 @@ public void testDeleteActionCollection_afterApplicationPublish_clearsActionColle | |
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| @WithUserDetails(value = "api_user") | ||
| public void testUpdateUnpublishedActionCollection_withValidCollection_callsPageLayoutOnlyOnce() { | ||
| Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(pluginExecutor)); | ||
| Mockito.when(pluginExecutor.getHintMessages(Mockito.any(), Mockito.any())) | ||
| .thenReturn(Mono.zip(Mono.just(new HashSet<>()), Mono.just(new HashSet<>()))); | ||
|
|
||
| ActionCollectionDTO actionCollectionDTO = new ActionCollectionDTO(); | ||
| actionCollectionDTO.setName("testCollection1"); | ||
| actionCollectionDTO.setPageId(testPage.getId()); | ||
| actionCollectionDTO.setApplicationId(testApp.getId()); | ||
| actionCollectionDTO.setWorkspaceId(workspaceId); | ||
| actionCollectionDTO.setPluginId(datasource.getPluginId()); | ||
| actionCollectionDTO.setVariables(List.of(new JSValue("test", "String", "test", true))); | ||
| actionCollectionDTO.setBody("collectionBody"); | ||
| actionCollectionDTO.setPluginType(PluginType.JS); | ||
|
|
||
| // Create actions | ||
| ActionDTO action1 = new ActionDTO(); | ||
| action1.setName("testAction1"); | ||
| action1.setActionConfiguration(new ActionConfiguration()); | ||
| action1.getActionConfiguration().setBody("mockBody"); | ||
| action1.getActionConfiguration().setIsValid(false); | ||
|
|
||
| ActionDTO action2 = new ActionDTO(); | ||
| action2.setName("testAction2"); | ||
| action2.setActionConfiguration(new ActionConfiguration()); | ||
| action2.getActionConfiguration().setBody("mockBody"); | ||
| action2.getActionConfiguration().setIsValid(false); | ||
|
|
||
| ActionDTO action3 = new ActionDTO(); | ||
| action3.setName("testAction3"); | ||
| action3.setActionConfiguration(new ActionConfiguration()); | ||
| action3.getActionConfiguration().setBody("mockBody"); | ||
| action3.getActionConfiguration().setIsValid(false); | ||
|
|
||
| actionCollectionDTO.setActions(List.of(action1, action2, action3)); | ||
|
|
||
| Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString())) | ||
| .thenAnswer(invocationOnMock -> { | ||
| return Mono.just(testPage.getId()); | ||
| }); | ||
|
|
||
| ActionCollectionDTO createdActionCollectionDTO = | ||
| layoutCollectionService.createCollection(actionCollectionDTO).block(); | ||
| assert createdActionCollectionDTO != null; | ||
| assert createdActionCollectionDTO.getId() != null; | ||
| String createdActionCollectionId = createdActionCollectionDTO.getId(); | ||
|
|
||
| applicationPageService.publish(testApp.getId(), true).block(); | ||
|
|
||
| actionCollectionDTO.getActions().get(0).getActionConfiguration().setBody("updatedBody"); | ||
|
|
||
| final Mono<ActionCollectionDTO> updatedActionCollectionDTO = | ||
| layoutCollectionService.updateUnpublishedActionCollection( | ||
| createdActionCollectionId, actionCollectionDTO); | ||
|
|
||
| StepVerifier.create(updatedActionCollectionDTO) | ||
| .assertNext(actionCollectionDTO1 -> { | ||
| assertEquals(createdActionCollectionId, actionCollectionDTO1.getId()); | ||
|
|
||
| // This invocation will happen here twice, once during create collection and once during update | ||
| // collection as expected | ||
| Mockito.verify(updateLayoutService, Mockito.times(2)) | ||
| .updatePageLayoutsByPageId(Mockito.anyString()); | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
Comment on lines
+708
to
+771
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider extracting test setup to improve readability. The test is well-structured but contains repetitive action setup code. Consider extracting the action creation logic into a helper method. + private ActionDTO createTestAction(String name, String body) {
+ ActionDTO action = new ActionDTO();
+ action.setName(name);
+ action.setActionConfiguration(new ActionConfiguration());
+ action.getActionConfiguration().setBody(body);
+ action.getActionConfiguration().setIsValid(false);
+ return action;
+ }Then use it in the test: - ActionDTO action1 = new ActionDTO();
- action1.setName("testAction1");
- action1.setActionConfiguration(new ActionConfiguration());
- action1.getActionConfiguration().setBody("mockBody");
- action1.getActionConfiguration().setIsValid(false);
+ ActionDTO action1 = createTestAction("testAction1", "mockBody");
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider using Mockito's answer method for cleaner mock setup.
The mock setup can be simplified using Mockito's answer method.
📝 Committable suggestion