From bac616292167bb5adfde2b2423c3ffce79c54523 Mon Sep 17 00:00:00 2001 From: Nayan Date: Wed, 13 Jul 2022 00:07:18 +0600 Subject: [PATCH] feat: Add new field for the page meta data in templates (#14784) In order to import a specific page or browse to that page, the templates FE need page names and page ids. This PR replaces the list of page names with a list of objects that contains the page names and page ids. --- .../server/dtos/ApplicationTemplate.java | 2 +- .../ApplicationTemplateServiceTest.java | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationTemplate.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationTemplate.java index 078b3e1087..5793dc870e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationTemplate.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationTemplate.java @@ -21,7 +21,7 @@ public class ApplicationTemplate extends BaseDomain { private List functions; private List useCases; private List datasources; - private List pageNames; + private List pages; private String minVersion; private String minVersionPadded; private Long downloadCount; diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationTemplateServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationTemplateServiceTest.java index f23e6fc4ed..08c70e417d 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationTemplateServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ApplicationTemplateServiceTest.java @@ -3,12 +3,16 @@ package com.appsmith.server.services; import com.appsmith.server.configurations.CloudServicesConfig; import com.appsmith.server.domains.UserData; import com.appsmith.server.dtos.ApplicationTemplate; +import com.appsmith.server.dtos.PageNameIdDTO; import com.appsmith.server.solutions.ImportExportApplicationService; import com.appsmith.server.solutions.ReleaseNotesService; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import org.json.JSONArray; +import org.json.JSONObject; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -23,7 +27,6 @@ import reactor.test.StepVerifier; import java.io.IOException; import java.util.List; -import static com.appsmith.server.migrations.DatabaseChangelog.objectMapper; import static org.assertj.core.api.Assertions.assertThat; /** @@ -32,15 +35,20 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) public class ApplicationTemplateServiceTest { ApplicationTemplateService applicationTemplateService; + private static ObjectMapper objectMapper = new ObjectMapper(); @MockBean private UserDataService userDataService; + @MockBean private CloudServicesConfig cloudServicesConfig; + @MockBean private ReleaseNotesService releaseNotesService; + @MockBean private ImportExportApplicationService importExportApplicationService; + @MockBean private AnalyticsService analyticsService; @@ -135,4 +143,45 @@ public class ApplicationTemplateServiceTest { assertThat(queryParameterValues).contains("id-two"); assertThat(queryParameterValues.size()).isEqualTo(2); } + + @Test + public void get_WhenPageMetaDataExists_PageMetaDataParsedProperly() throws JsonProcessingException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "1234567890"); + jsonObject.put("name", "My Page"); + jsonObject.put("isDefault", true); + JSONArray pages = new JSONArray(); + pages.put(jsonObject); + + JSONObject templateObj = new JSONObject(); + templateObj.put("title", "My Template"); + templateObj.put("pages", pages); + + JSONArray templates = new JSONArray(); + templates.put(templateObj); + + // mock the server to return a template when it's called + mockCloudServices + .enqueue(new MockResponse() + .setBody(templates.toString()) + .addHeader("Content-Type", "application/json")); + + // mock the user data to set recently used template ids + UserData mockUserData = new UserData(); + mockUserData.setRecentlyUsedTemplateIds(List.of()); + Mockito.when(userDataService.getForCurrentUser()).thenReturn(Mono.just(mockUserData)); + + // make sure we've received the response returned by the mockCloudServices + StepVerifier.create(applicationTemplateService.getActiveTemplates(null)) + .assertNext(applicationTemplates -> { + assertThat(applicationTemplates.size()).isEqualTo(1); + ApplicationTemplate applicationTemplate = applicationTemplates.get(0); + assertThat(applicationTemplate.getPages()).hasSize(1); + PageNameIdDTO pageNameIdDTO = applicationTemplate.getPages().get(0); + assertThat(pageNameIdDTO.getId()).isEqualTo("1234567890"); + assertThat(pageNameIdDTO.getName()).isEqualTo("My Page"); + assertThat(pageNameIdDTO.getIsDefault()).isTrue(); + }) + .verifyComplete(); + } } \ No newline at end of file