diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java index d8ba6331e842..ea6da0f5fc4e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImpl.java @@ -316,13 +316,11 @@ public Mono updateExecutablesRunBehaviour( return featureFlagService .check(FeatureFlagEnum.release_reactive_actions_enabled) .flatMap(isReactiveActionsEnabled -> { - RunBehaviourEnum runBehaviourToCheck = - isReactiveActionsEnabled ? RunBehaviourEnum.AUTOMATIC : RunBehaviourEnum.ON_PAGE_LOAD; - // Before we update the actions, fetch all the actions which are currently set to execute on load. Mono> existingOnLoadExecutablesMono = creatorContextExecutablesFlux .flatMap(executable -> { - if (runBehaviourToCheck.equals(executable.getRunBehaviour())) { + if (RunBehaviourEnum.AUTOMATIC.equals(executable.getRunBehaviour()) + || RunBehaviourEnum.ON_PAGE_LOAD.equals(executable.getRunBehaviour())) { return Mono.just(executable); } return Mono.empty(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImplTest.java index dae9acada6b9..c110a62eb662 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/onload/internal/OnLoadExecutablesUtilCEImplTest.java @@ -476,6 +476,44 @@ public void whenNoExecutables_shouldReturnFalse() { assert executableUpdates.isEmpty(); } + @Test + public void testUpdateExecutablesRunBehaviour_WhenExistingIsOnPageLoadAndFlagEnabled_ShouldNotUpdateToAutomatic() { + // Setup + String creatorId = "testCreatorId"; + CreatorContextType creatorType = CreatorContextType.PAGE; + List executableUpdatesRef = new ArrayList<>(); + List messagesRef = new ArrayList<>(); + + // Existing action is ON_PAGE_LOAD + ActionDTO existingAction = createTestExecutable("Api1", RunBehaviourEnum.ON_PAGE_LOAD); + existingAction.setId("api1Id"); + existingAction.setUserSetOnLoad(FALSE); + + // Updated action comes in onLoadExecutables (should not trigger AUTOMATIC) + ActionDTO updatedAction = createTestExecutable("Api1", RunBehaviourEnum.ON_PAGE_LOAD); + updatedAction.setId("api1Id"); + updatedAction.setUserSetOnLoad(FALSE); + + List onLoadExecutables = List.of(updatedAction); + List allExecutables = List.of(existingAction); + + // Mock behavior + when(featureFlagService.check(FeatureFlagEnum.release_reactive_actions_enabled)) + .thenReturn(Mono.just(TRUE)); + when(executableOnLoadService.getAllExecutablesByCreatorIdFlux(anyString())) + .thenReturn(Flux.fromIterable(allExecutables)); + // Should not call updateUnpublishedExecutable at all + + // Execute + Mono result = onLoadExecutablesUtilCE.updateExecutablesRunBehaviour( + onLoadExecutables, creatorId, executableUpdatesRef, messagesRef, creatorType); + + // Verify + StepVerifier.create(result).expectNext(true).verifyComplete(); + // Should not update run behaviour to AUTOMATIC + verify(executableOnLoadService, times(0)).updateUnpublishedExecutable(anyString(), any(ActionDTO.class)); + } + // Helper methods to create test executables private List createTestExecutables(String... names) { List executables = new ArrayList<>();