diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/BaseService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/BaseService.java index 8e584bccc2..7715ba1e97 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/BaseService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/BaseService.java @@ -23,6 +23,7 @@ import reactor.core.scheduler.Scheduler; import javax.validation.Validator; import java.io.Serializable; +import java.time.Instant; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -82,6 +83,8 @@ public abstract class BaseService & AppsmithRepo resource.setPolicies(null); } + resource.setUpdatedAt(Instant.now()); + DBObject update = getDbObject(resource); Update updateObj = new Update(); 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 059a4cc2cd..35e5e31330 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 @@ -521,4 +521,42 @@ public class ActionCollectionServiceTest { .verifyComplete(); } + + /** + * For a given collection testActionCollection, + * When the collection is updated after creation, + * The updatedAt field should have a greater value than the updatedAt value when it was created. + */ + @Test + @WithUserDetails(value = "api_user") + public void testUpdateActionCollection_verifyUpdatedAtFieldUpdated() { + ActionCollectionDTO actionCollectionDTO = new ActionCollectionDTO(); + actionCollectionDTO.setName("testActionCollection"); + actionCollectionDTO.setApplicationId(testApp.getId()); + actionCollectionDTO.setOrganizationId(testApp.getOrganizationId()); + actionCollectionDTO.setPageId(testPage.getId()); + actionCollectionDTO.setPluginId(datasource.getPluginId()); + actionCollectionDTO.setPluginType(PluginType.JS); + + ActionCollection createdActionCollection = layoutCollectionService.createCollection(actionCollectionDTO) + .flatMap(createdCollection -> { + // Delay after creating(before updating) record to get different updatedAt time + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return actionCollectionService.findById(createdCollection.getId(), READ_ACTIONS); + }).block(); + + + Mono updatedActionCollectionMono = layoutCollectionService.updateUnpublishedActionCollection(createdActionCollection.getId(), actionCollectionDTO, null) + .flatMap(createdCollection -> actionCollectionService.findById(createdCollection.getId(), READ_ACTIONS)); + + StepVerifier.create(updatedActionCollectionMono) + .assertNext(updatedActionCollection -> { + assertThat(updatedActionCollection.getUpdatedAt().isAfter(createdActionCollection.getUpdatedAt())).isTrue(); + }) + .verifyComplete(); + } }