From ab9561159f66b8fc041843c77e69c9f094057969 Mon Sep 17 00:00:00 2001 From: muralibasani Date: Thu, 5 Oct 2023 14:34:44 +0200 Subject: [PATCH 01/14] Update schema request with kafka env Signed-off-by: muralibasani --- .../EnvsClustersTenantsController.java | 9 --- .../aiven/klaw/error/KlawErrorMessages.java | 5 ++ .../io/aiven/klaw/helpers/KwConstants.java | 2 + .../klaw/service/CommonUtilsService.java | 3 +- .../EnvsClustersTenantsControllerService.java | 4 +- .../SchemaRegistryControllerService.java | 26 +++++++- .../static/js/requestAvroSchemaUpload.js | 61 +++++-------------- .../main/resources/templates/browseAcls.html | 2 +- .../resources/templates/requestSchema.html | 17 ++---- .../io/aiven/klaw/TopicAclControllerIT.java | 29 ++++++++- .../SchemaRegistryControllerServiceTest.java | 18 +++++- openapi.yaml | 21 ------- 12 files changed, 100 insertions(+), 97 deletions(-) diff --git a/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java b/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java index 339c723b89..7da0652888 100644 --- a/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java +++ b/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java @@ -229,15 +229,6 @@ public ResponseEntity> getSchemaRegEnv( HttpStatus.OK); } - @RequestMapping( - value = "/getEnvsForSchemaRequests", - method = RequestMethod.GET, - produces = {MediaType.APPLICATION_JSON_VALUE}) - public ResponseEntity> getEnvsForSchemaRequests() { - return new ResponseEntity<>( - envsClustersTenantsControllerService.getEnvsForSchemaRequests(), HttpStatus.OK); - } - @RequestMapping( value = "/getKafkaConnectEnvs", method = RequestMethod.GET, diff --git a/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java b/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java index c18e1ffff9..e10e5d4ea2 100644 --- a/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java +++ b/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java @@ -281,6 +281,11 @@ public class KlawErrorMessages { public static final String SCHEMA_ERR_107 = "Failure. A request already exists for this topic."; + public static final String SCHEMA_ERR_108 = "Failure. There is no associated schema environment."; + + public static final String SCHEMA_ERR_109 = + "Failure. Request Schema environments not configured Settings - tenant config"; + public static final String SERVER_CONFIG_ERR_101 = "Failure. Invalid json / incorrect name values. Check tenant and env details."; diff --git a/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java b/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java index d6c46e00eb..ed0823bbf6 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java +++ b/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java @@ -108,6 +108,8 @@ public class KwConstants { public static final String ORDER_OF_TOPIC_ENVS = "ORDER_OF_ENVS"; + public static final String REQUEST_SCHEMA_OF_ENVS = "REQUEST_SCHEMA_OF_ENVS"; + public static final String ORDER_OF_KAFKA_CONNECT_ENVS = "ORDER_OF_KAFKA_CONNECT_ENVS"; public static final int DAYS_EXPIRY_DEFAULT_TENANT = 365 * 10; diff --git a/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java b/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java index 6f4a7c042b..85f81be3d9 100644 --- a/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java +++ b/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java @@ -1,6 +1,7 @@ package io.aiven.klaw.service; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_TOPIC_ENVS; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static io.aiven.klaw.helpers.KwConstants.REQUEST_TOPICS_OF_ENVS; import static io.aiven.klaw.model.enums.AuthenticationType.DATABASE; @@ -549,7 +550,7 @@ public String getEnvProperty(Integer tenantId, String envPropertyType) { requestConn.forEach(a -> intOrderEnvsList.add(Integer.parseInt(a))); } } - case "REQUEST_SCHEMA_OF_ENVS" -> { + case REQUEST_SCHEMA_OF_ENVS -> { List requestSchema = tenantModel.getRequestSchemaEnvironmentsList(); if (requestSchema != null && !requestSchema.isEmpty()) { requestSchema.forEach(a -> intOrderEnvsList.add(Integer.parseInt(a))); diff --git a/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java b/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java index 94f0eb526e..1c244965cc 100644 --- a/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java @@ -16,6 +16,7 @@ import static io.aiven.klaw.helpers.KwConstants.DEFAULT_TENANT_ID; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_KAFKA_CONNECT_ENVS; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_TOPIC_ENVS; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static io.aiven.klaw.helpers.KwConstants.REQUEST_TOPICS_OF_ENVS; import static io.aiven.klaw.helpers.KwConstants.SUPERADMIN_ROLE; import static io.aiven.klaw.model.enums.RolesType.SUPERADMIN; @@ -498,8 +499,7 @@ public List getSchemaRegEnvs() { public List getEnvsForSchemaRequests() { int tenantId = getUserDetails(getUserName()).getTenantId(); - String requestSchemasEnvs = - commonUtilsService.getEnvProperty(tenantId, "REQUEST_SCHEMA_OF_ENVS"); + String requestSchemasEnvs = commonUtilsService.getEnvProperty(tenantId, REQUEST_SCHEMA_OF_ENVS); if (requestSchemasEnvs == null) { return new ArrayList<>(); } diff --git a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java index 0ab0cd88e8..cefb2ef1b5 100644 --- a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java @@ -7,6 +7,9 @@ import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_105; import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_106; import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_107; +import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_108; +import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_109; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static io.aiven.klaw.model.enums.MailType.*; import static org.springframework.beans.BeanUtils.copyProperties; @@ -439,8 +442,7 @@ private SchemaRequestModel buildSchemaRequestFromPromotionRequest( schemaRequest.setSchemaversion(schemaPromotion.getSchemaVersion()); schemaRequest.setTopicname(schemaPromotion.getTopicName()); schemaRequest.setForceRegister(schemaPromotion.isForceRegister()); - Optional env = getSchemaEnvFromKafkaEnvId(schemaPromotion.getTargetEnvironment()); - schemaRequest.setEnvironment(env.isPresent() ? env.get().getId() : null); + schemaRequest.setEnvironment(schemaPromotion.getTargetEnvironment()); return schemaRequest; } @@ -455,6 +457,24 @@ public ApiResponse uploadSchema( return ApiResponse.NOT_AUTHORIZED; } + int tenantId = commonUtilsService.getTenantId(getUserName()); + Optional schemaEnv = getSchemaEnvFromKafkaEnvId(schemaRequest.getEnvironment()); + if (schemaEnv.isPresent()) { + schemaRequest.setEnvironment(schemaEnv.get().getId()); + + String requestSchemasEnvs = + commonUtilsService.getEnvProperty(tenantId, REQUEST_SCHEMA_OF_ENVS); + if (requestSchemasEnvs == null) { + return ApiResponse.notOk(SCHEMA_ERR_109); + } + String[] reqSchemaEnvs = requestSchemasEnvs.split(","); + if (!Arrays.stream(reqSchemaEnvs).toList().contains(schemaEnv.get().getId())) { + return ApiResponse.notOk(SCHEMA_ERR_109); + } + } else { + return ApiResponse.notOk(SCHEMA_ERR_108); + } + // If force register is not set validate the schema if (validateCompatiblityOnSave && (schemaRequest.getForceRegister() == null || !schemaRequest.getForceRegister())) { @@ -475,7 +495,7 @@ public ApiResponse uploadSchema( Integer userTeamId = commonUtilsService.getTeamId(userName); schemaRequest.setTeamId(userTeamId); - int tenantId = commonUtilsService.getTenantId(getUserName()); + if (!userAndTopicOwnerAreOnTheSameTeam(schemaRequest.getTopicname(), userTeamId, tenantId)) { return ApiResponse.notOk(SCHEMA_ERR_106); } diff --git a/core/src/main/resources/static/js/requestAvroSchemaUpload.js b/core/src/main/resources/static/js/requestAvroSchemaUpload.js index cbb67bd959..dbbfc52ba1 100644 --- a/core/src/main/resources/static/js/requestAvroSchemaUpload.js +++ b/core/src/main/resources/static/js/requestAvroSchemaUpload.js @@ -68,48 +68,35 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2000); } - $scope.getSchemaEnvs = function() { - - $http({ - method: "GET", - url: "getEnvsForSchemaRequests", - headers : { 'Content-Type' : 'application/json' } - }).success(function(output) { - $scope.allschemaenvs = output; - }).error( - function(error) - { - $scope.alert = error; - } - ); - } $scope.loadParams = function() { - var topicSelected; - var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); - if (sParameterName[0] == "topicname") + if (sParameterName[0] === "topicname") { $scope.topicSelectedFromUrl = sParameterName[1]; $scope.addSchema.topicname = $scope.topicSelectedFromUrl; $scope.validatedSchema=false; - $scope.getAllTopics(); + } + if (sParameterName[0] === "envId") + { + $scope.addSchema.envId = sParameterName[1]; + $scope.getEnvDetails($scope.addSchema.envId); } } } - $scope.getEnvs = function() { - + $scope.getEnvDetails = function(envSelected) { $http({ method: "GET", - url: "getEnvs", - headers : { 'Content-Type' : 'application/json' } + url: "getEnvDetails", + headers : { 'Content-Type' : 'application/json' }, + params: {'envSelected' : envSelected, 'envType' : 'kafka' }, }).success(function(output) { - $scope.allenvs = output; + $scope.environmentDetails = output; }).error( function(error) { @@ -118,24 +105,6 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) ); } - $scope.getAllTopics = function() { - - $scope.alltopics = null; - $http({ - method: "GET", - url: "getTopicsOnly", - headers : { 'Content-Type' : 'application/json' }, - params: {'isMyTeamTopics' : 'true' }, - }).success(function(output) { - $scope.alltopics = output; - }).error( - function(error) - { - $scope.alert = error; - } - ); - } - $scope.cancelRequest = function() { $window.location.href = $window.location.origin + $scope.dashboardDetails.contextPath + "/browseTopics"; } @@ -146,9 +115,9 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) $scope.addSchema = function() { - if(!$scope.addSchema.envName) + if(!$scope.addSchema.envId) { - $scope.alertnote = "Please select an environment"; + $scope.alertnote = "Please select a valid environment"; $scope.showAlertToast(); return; } @@ -161,7 +130,7 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) }else { $scope.addSchema.topicname = $scope.addSchema.topicname.trim(); - if($scope.addSchema.topicname.length==0){ + if($scope.addSchema.topicname.length === 0){ $scope.alertnote = "Please fill in topic name."; $scope.showAlertToast(); return; @@ -179,7 +148,7 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) $scope.alert = null; $scope.alertnote = null; - serviceInput['environment'] = $scope.addSchema.envName; + serviceInput['environment'] = $scope.addSchema.envId; serviceInput['topicname'] = $scope.addSchema.topicname; serviceInput['appname'] = "App"; serviceInput['remarks'] = $scope.addSchema.remarks; diff --git a/core/src/main/resources/templates/browseAcls.html b/core/src/main/resources/templates/browseAcls.html index 850f5383bb..2088704e15 100644 --- a/core/src/main/resources/templates/browseAcls.html +++ b/core/src/main/resources/templates/browseAcls.html @@ -907,7 +907,7 @@
Team
{{ aclRequest.teamname }}
- + diff --git a/core/src/main/resources/templates/requestSchema.html b/core/src/main/resources/templates/requestSchema.html index de973c80bd..68a4721563 100644 --- a/core/src/main/resources/templates/requestSchema.html +++ b/core/src/main/resources/templates/requestSchema.html @@ -453,7 +453,7 @@

Shortcuts

-
+
@@ -474,30 +474,25 @@

Shortcuts


-
- - + +
- - - + +
+
-
diff --git a/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java b/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java index 8b9694f434..db4b7ad4a9 100644 --- a/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java +++ b/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java @@ -1232,6 +1232,33 @@ public void createSREnv() throws Exception { ApiResponse response1 = OBJECT_MAPPER.readValue(response, new TypeReference<>() {}); assertThat(response1.isSuccess()).isTrue(); + KwPropertiesModel kwPropertiesModel = new KwPropertiesModel(); + kwPropertiesModel.setKwKey(TENANT_CONFIG_PROPERTY); + kwPropertiesModel.setKwValue( + """ + { + "tenantModel": + { + "tenantName": "default", + "baseSyncEnvironment": "DEV", + "orderOfTopicPromotionEnvsList": ["DEV"], + "requestTopicsEnvironmentsList": ["DEV"], + "requestSchemaEnvironmentsList": ["DEVSCH"] + } + }"""); + String jsonReq = OBJECT_MAPPER.writer().writeValueAsString(kwPropertiesModel); + + mvc.perform( + MockMvcRequestBuilders.post("/updateKwCustomProperty") + .with(user(superAdmin).password(superAdminPwd)) + .content(jsonReq) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + // get SR envs response = mvc.perform( @@ -1255,7 +1282,7 @@ public void createSchemaRequest() throws Exception { SchemaRequestModel schemaRequest = utilMethods.getSchemaRequests().get(0); schemaRequest.setTopicname(topicName + topicId1); schemaRequest.setRequestor(user1); - schemaRequest.setEnvironment("3"); // Schema reg env + schemaRequest.setEnvironment("1"); // Schema reg env schemaRequest.setSchemafull( "{\n" + " \"type\" : \"record\",\n" diff --git a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java index aa133550f3..77ae320918 100644 --- a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java @@ -1,5 +1,6 @@ package io.aiven.klaw.service; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -306,6 +307,8 @@ public void uploadSchemaSuccess() throws KlawException { when(commonUtilsService.getEnvsFromUserId(anyString())) .thenReturn(new HashSet<>(Collections.singletonList("1"))); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); when(handleDbRequests.requestForSchema(any())).thenReturn(ApiResultStatus.SUCCESS.value); when(commonUtilsService.getTopicsForTopicName(anyString(), anyInt())) @@ -380,6 +383,7 @@ public void promoteSchemaSuccess() throws Exception { when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "1")); @@ -397,6 +401,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV1Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "1")); @@ -418,6 +423,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV2Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "2")); @@ -439,6 +445,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV3Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "3")); @@ -461,6 +468,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV4Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "4")); @@ -475,13 +483,14 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV4Success() throws Exception @Test @Order(17) - public void promoteSchemaWithInCompaitbleSchemaReturnFailure() throws Exception { + public void promoteSchemaWithInCompatibleSchemaReturnFailure() throws Exception { mockGetEnvironment(); mockSchema(); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(false)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "4")); @@ -505,6 +514,8 @@ public void uploadSchemaIncompatibleSchemaError() throws KlawException { .thenReturn(new HashSet<>(Collections.singletonList("1"))); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); @@ -611,6 +622,8 @@ public void uploadSchema_NoValidationOnSave() throws KlawException { when(commonUtilsService.getTopicsForTopicName(anyString(), anyInt())) .thenReturn(List.of(topic)); when(commonUtilsService.getFilteredTopicsForTenant(any())).thenReturn(List.of(topic)); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); @@ -636,6 +649,8 @@ public void uploadSchema_ValidationPropertyNotSet() throws KlawException { .thenReturn(new HashSet<>(Collections.singletonList("1"))); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); NullPointerException ex = assertThrows( @@ -781,7 +796,6 @@ private static Topic createTopic() { } private void mockGetEnvironment() { - when(manageDatabase.getSchemaRegEnvList(anyInt())).thenReturn(createEnvList(8)); } diff --git a/openapi.yaml b/openapi.yaml index 20be95229a..5707581b51 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -4244,27 +4244,6 @@ } } }, - "/getEnvsForSchemaRequests" : { - "get" : { - "tags" : [ "envs-clusters-tenants-controller" ], - "operationId" : "getEnvsForSchemaRequests", - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/EnvModelResponse" - } - } - } - } - } - } - } - }, "/getEnvsBaseCluster" : { "get" : { "tags" : [ "envs-clusters-tenants-controller" ], From cd3a1d9f45e317eaf8fc5e83de62a6456efff2f9 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 5 Oct 2023 15:23:14 +0200 Subject: [PATCH 02/14] Remove unused component Signed-off-by: Mirjam Aulbach --- .../SelectSchemaRegEnvironment.test.tsx | 130 ------------------ .../components/SelectSchemaRegEnvironment.tsx | 52 ------- 2 files changed, 182 deletions(-) delete mode 100644 coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx delete mode 100644 coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx diff --git a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx b/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx deleted file mode 100644 index 47a36b21a4..0000000000 --- a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import { cleanup, screen } from "@testing-library/react"; -import { - ALL_ENVIRONMENTS_VALUE, - getEnvironmentsForSchemaRequest, -} from "src/domain/environment"; -import { mockedEnvironmentResponse } from "src/domain/environment/environment-api.msw"; -import { customRender } from "src/services/test-utils/render-with-wrappers"; -import { waitForElementToBeRemoved } from "@testing-library/react/pure"; -import userEvent from "@testing-library/user-event"; -import { createEnvironment } from "src/domain/environment/environment-test-helper"; -import { SelectSchemaRegEnvironment } from "src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment"; - -jest.mock("src/domain/environment/environment-api.ts"); - -const mockGetSchemaRegistryEnvironments = - getEnvironmentsForSchemaRequest as jest.MockedFunction< - typeof getEnvironmentsForSchemaRequest - >; - -const filterLabel = "Filter by Environment"; - -describe("SelectSchemaRegEnvironment.tsx", () => { - const mockedEnvironmentDev = createEnvironment({ - name: "DEV", - id: "1", - }); - const mockedEnvironmentTst = createEnvironment({ - name: "TST", - id: "2", - }); - - describe("renders all necessary elements", () => { - const mockedOnChange = jest.fn(); - - beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ - mockedEnvironmentDev, - mockedEnvironmentTst, - ]); - - customRender( - , - { queryClient: true } - ); - await waitForElementToBeRemoved( - screen.getByTestId("select-environment-loading") - ); - }); - - afterAll(cleanup); - - it("shows a select element for Environments", () => { - const select = screen.getByRole("combobox", { - name: filterLabel, - }); - - expect(select).toBeEnabled(); - }); - - it("renders a list of options for Environments plus a option for `All environments`", () => { - mockedEnvironmentResponse.forEach((environment) => { - const option = screen.getByRole("option", { - name: environment.name, - }); - - expect(option).toBeEnabled(); - }); - expect(screen.getAllByRole("option")).toHaveLength( - mockedEnvironmentResponse.length + 1 - ); - }); - - it("shows `All Environments` as the active option based on given value", () => { - const option = screen.getByRole("option", { - selected: true, - }); - expect(option).toHaveAccessibleName("All Environments"); - }); - - it("has `All Environments` as the active value for option", () => { - const select = screen.getByRole("combobox", { - name: filterLabel, - }); - expect(select).toHaveValue(ALL_ENVIRONMENTS_VALUE); - }); - }); - - describe("handles user selecting a environment", () => { - const mockedOnChange = jest.fn(); - - beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ - mockedEnvironmentDev, - mockedEnvironmentTst, - ]); - - customRender( - , - { queryClient: true } - ); - await waitForElementToBeRemoved( - screen.getByTestId("select-environment-loading") - ); - }); - - afterEach(() => { - jest.resetAllMocks(); - cleanup(); - }); - - it("updates state for api call when user selects a new environment", async () => { - const select = screen.getByRole("combobox", { - name: filterLabel, - }); - const option = screen.getByRole("option", { - name: mockedEnvironmentDev.name, - }); - - await userEvent.selectOptions(select, option); - - expect(mockedOnChange).toHaveBeenCalledWith(mockedEnvironmentDev.id); - }); - }); -}); diff --git a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx b/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx deleted file mode 100644 index 1591b48ab4..0000000000 --- a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { NativeSelect, Option } from "@aivenio/aquarium"; -import { - ALL_ENVIRONMENTS_VALUE, - Environment, - getEnvironmentsForSchemaRequest, -} from "src/domain/environment"; -import { useQuery } from "@tanstack/react-query"; - -type SelectSchemaRegEnvironmentProps = { - value: Environment["id"]; - onChange: (value: Environment["id"]) => void; -}; - -function SelectSchemaRegEnvironment(props: SelectSchemaRegEnvironmentProps) { - const { value, onChange } = props; - - const { data: environments, isLoading } = useQuery({ - queryKey: ["schemaRegistryEnvironments"], - queryFn: () => getEnvironmentsForSchemaRequest(), - }); - - if (isLoading || !environments) { - return ( -
- -
- ); - } else { - return ( - { - const env = event.target.value as Environment["id"]; - onChange(env); - }} - > - - - {environments.map((env: Environment) => ( - - ))} - - ); - } -} - -export { SelectSchemaRegEnvironment }; From 8ae8bca1717ba096ca7744f3a6579a95b25e8703 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 5 Oct 2023 15:24:31 +0200 Subject: [PATCH 03/14] Remove deleted endpoint. Signed-off-by: Mirjam Aulbach --- coral/src/domain/environment/environment-api.ts | 9 --------- coral/src/domain/environment/index.ts | 2 -- 2 files changed, 11 deletions(-) diff --git a/coral/src/domain/environment/environment-api.ts b/coral/src/domain/environment/environment-api.ts index 6c34ab471d..63fbee03f2 100644 --- a/coral/src/domain/environment/environment-api.ts +++ b/coral/src/domain/environment/environment-api.ts @@ -74,14 +74,6 @@ const getPaginatedEnvironmentsForSchema = async ( return transformPaginatedEnvironmentApiResponse(apiResponse); }; -const getEnvironmentsForSchemaRequest = async (): Promise => { - const apiResponse = await api.get< - KlawApiResponse<"getEnvsForSchemaRequests"> - >(API_PATHS.getEnvsForSchemaRequests); - - return transformEnvironmentApiResponse(apiResponse); -}; - const getAllEnvironmentsForConnector = async (): Promise => { const apiResponse = await api.get>( API_PATHS.getSyncConnectorsEnv @@ -122,7 +114,6 @@ export { getEnvironmentsForTopicRequest, getAllEnvironmentsForSchema, getPaginatedEnvironmentsForSchema, - getEnvironmentsForSchemaRequest, getAllEnvironmentsForConnector, getPaginatedEnvironmentsForConnector, getUpdateEnvStatus, diff --git a/coral/src/domain/environment/index.ts b/coral/src/domain/environment/index.ts index 6e2d9192dd..84801895e8 100644 --- a/coral/src/domain/environment/index.ts +++ b/coral/src/domain/environment/index.ts @@ -2,7 +2,6 @@ import { getAllEnvironmentsForConnector, getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, - getEnvironmentsForSchemaRequest, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, getPaginatedEnvironmentsForSchema, @@ -21,7 +20,6 @@ export { getAllEnvironmentsForConnector, getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, - getEnvironmentsForSchemaRequest, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, getPaginatedEnvironmentsForSchema, From 73c9e50eebc33bd02351dd7c279e841c02674cf3 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 5 Oct 2023 15:32:04 +0200 Subject: [PATCH 04/14] Use getEnvs endpoint instead of deleted one. Signed-off-by: Mirjam Aulbach --- .../TopicSchemaRequest.test.tsx | 30 +++++++++---------- .../schema-request/TopicSchemaRequest.tsx | 6 ++-- .../app/pages/topics/schema-request.test.tsx | 10 +++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx index f16ef712d9..4fdf045031 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx @@ -8,7 +8,7 @@ import { } from "@testing-library/react/pure"; import userEvent from "@testing-library/user-event"; import { TopicSchemaRequest } from "src/app/features/topics/schema-request/TopicSchemaRequest"; -import { getEnvironmentsForSchemaRequest } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { createMockEnvironmentDTO } from "src/domain/environment/environment-test-helper"; import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer"; import { requestSchemaCreation } from "src/domain/schema-request"; @@ -19,9 +19,9 @@ jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/topic/topic-api.ts"); -const mockGetSchemaRegistryEnvironments = - getEnvironmentsForSchemaRequest as jest.MockedFunction< - typeof getEnvironmentsForSchemaRequest +const mockgetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockCreateSchemaRequest = requestSchemaCreation as jest.MockedFunction< typeof requestSchemaCreation @@ -75,7 +75,7 @@ describe("TopicSchemaRequest", () => { describe("checks if topicName passed from url is part of topics user can request schemas for", () => { beforeEach(() => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -145,7 +145,7 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env ID query is part of list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -184,7 +184,7 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env name query is part of list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -223,7 +223,7 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env id query does not exist in list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -244,7 +244,7 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env name query does not exist in list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -270,7 +270,7 @@ describe("TopicSchemaRequest", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore useQuerySpy.mockReturnValue({ data: [], isLoading: true }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -308,7 +308,7 @@ describe("TopicSchemaRequest", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -441,7 +441,7 @@ describe("TopicSchemaRequest", () => { describe("shows errors when user does not fill out correctly", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -519,7 +519,7 @@ describe("TopicSchemaRequest", () => { describe("enables user to cancel the form input", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -635,7 +635,7 @@ describe("TopicSchemaRequest", () => { beforeEach(async () => { console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockRejectedValue({ @@ -740,7 +740,7 @@ describe("TopicSchemaRequest", () => { describe("enables user to send a schema request", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockResolvedValue({ diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx index 2ffc436652..331703f330 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx @@ -17,7 +17,7 @@ import { } from "src/app/features/topics/schema-request/form-schemas/topic-schema-request-form"; import { Environment, - getEnvironmentsForSchemaRequest, + getAllEnvironmentsForTopicAndAcl, } from "src/domain/environment"; import { requestSchemaCreation } from "src/domain/schema-request"; import { TopicNames, getTopicNames } from "src/domain/topic"; @@ -86,8 +86,8 @@ function TopicSchemaRequest(props: TopicSchemaRequestProps) { Environment[], Error >({ - queryKey: ["schemaRegistryEnvironments"], - queryFn: () => getEnvironmentsForSchemaRequest(), + queryKey: ["getEnvs"], + queryFn: () => getAllEnvironmentsForTopicAndAcl(), onSuccess: (environments) => { if (presetEnvironment) { const validEnv = environments.find( diff --git a/coral/src/app/pages/topics/schema-request.test.tsx b/coral/src/app/pages/topics/schema-request.test.tsx index 806ca15eca..f0381f75df 100644 --- a/coral/src/app/pages/topics/schema-request.test.tsx +++ b/coral/src/app/pages/topics/schema-request.test.tsx @@ -5,7 +5,7 @@ import { getQueryClientForTests } from "src/services/test-utils/query-client-tes import { render } from "@testing-library/react"; import { QueryClientProvider } from "@tanstack/react-query"; import { MemoryRouter, Routes, Route } from "react-router-dom"; -import { getEnvironmentsForSchemaRequest } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { requestSchemaCreation } from "src/domain/schema-request"; import { getTopicNames } from "src/domain/topic"; @@ -13,9 +13,9 @@ jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/topic/topic-api.ts"); -const mockGetSchemaRegistryEnvironments = - getEnvironmentsForSchemaRequest as jest.MockedFunction< - typeof getEnvironmentsForSchemaRequest +const mockGetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockCreateSchemaRequest = requestSchemaCreation as jest.MockedFunction< typeof requestSchemaCreation @@ -29,7 +29,7 @@ describe("SchemaRequest", () => { const topicName = "my-awesome-topic"; beforeAll(() => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([topicName]); // @TODO if we decide to go with this kind of dynamic routes, From 51caeedf92e4ed81f2ae72b032394b74c9556a76 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Fri, 6 Oct 2023 14:54:59 +0200 Subject: [PATCH 05/14] Filter getEnvs response for schema request Signed-off-by: Mirjam Aulbach --- .../TopicSchemaRequest.test.tsx | 93 ++++++++++--------- .../schema-request/TopicSchemaRequest.tsx | 5 + 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx index 4fdf045031..1ea2fd5009 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx @@ -19,7 +19,7 @@ jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/topic/topic-api.ts"); -const mockgetAllEnvironmentsForTopicAndAcl = +const mockGetAllEnvironmentsForTopicAndAcl = getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< typeof getAllEnvironmentsForTopicAndAcl >; @@ -47,15 +47,17 @@ const useQuerySpy = jest.spyOn(ReactQuery, "useQuery"); const testTopicName = "my-awesome-topic"; const mockedEnvironments = [ - { name: "DEV", id: "1" }, - { name: "TST", id: "2" }, - { name: "INFRA", id: "3" }, + { name: "DEV", id: "1", associatedEnv: { id: "3", name: "DEV_SCH" } }, + { name: "TST", id: "2", associatedEnv: { id: "9", name: "TST_SCH" } }, + { name: "INFRA", id: "3", associatedEnv: { id: "9", name: "INFRA_SCH" } }, + { name: "SOME", id: "3", associatedEnv: undefined }, ]; -const mockedGetSchemaRegistryEnvironments = transformEnvironmentApiResponse( - mockedEnvironments.map((entry) => { - return createMockEnvironmentDTO(entry); - }) -); +const mockedGetAllEnvironmentsForTopicAndAclResponse = + transformEnvironmentApiResponse( + mockedEnvironments.map((entry) => { + return createMockEnvironmentDTO(entry); + }) + ); const fileName = "my-awesome-schema.avsc"; const testFile: File = new File(["{}"], fileName, { @@ -75,8 +77,8 @@ describe("TopicSchemaRequest", () => { describe("checks if topicName passed from url is part of topics user can request schemas for", () => { beforeEach(() => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); }); @@ -145,8 +147,8 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env ID query is part of list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -184,8 +186,8 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env name query is part of list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -223,8 +225,8 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env id query does not exist in list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -244,8 +246,8 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env name query does not exist in list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -270,7 +272,7 @@ describe("TopicSchemaRequest", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore useQuerySpy.mockReturnValue({ data: [], isLoading: true }); - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -308,8 +310,8 @@ describe("TopicSchemaRequest", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -348,27 +350,34 @@ describe("TopicSchemaRequest", () => { expect(select).toBeRequired(); }); - it("renders all options for Environment based on api data", () => { + it("renders all options for Environment with associated env based on api data", () => { + const environmentsWithAssociatedEnvs = mockedEnvironments.filter( + (env) => env.associatedEnv + ); + const form = getForm(); const select = within(form).getByRole("combobox", { name: /Environment/i, }); const options = within(select).getAllByRole("option"); - expect(options).toHaveLength(mockedEnvironments.length + 1); + expect(options).toHaveLength(environmentsWithAssociatedEnvs.length + 1); }); test.each(mockedEnvironments)( - `renders a option $name with the Environments id set as value $id`, - ({ name, id }) => { - const form = getForm(); - const select = within(form).getByRole("combobox", { - name: /Environment/i, - }); - const option = within(select).getByRole("option", { name: name }); - - expect(option).toBeVisible(); - expect(option).toHaveValue(id); + `renders a option $name with the Environments id set as value $id when Environment has an associated env`, + (environment) => { + if (environment.associatedEnv) { + const { name, id } = environment; + const form = getForm(); + const select = within(form).getByRole("combobox", { + name: /Environment/i, + }); + const option = within(select).getByRole("option", { name: name }); + + expect(option).toBeVisible(); + expect(option).toHaveValue(id); + } } ); @@ -441,8 +450,8 @@ describe("TopicSchemaRequest", () => { describe("shows errors when user does not fill out correctly", () => { beforeEach(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -519,8 +528,8 @@ describe("TopicSchemaRequest", () => { describe("enables user to cancel the form input", () => { beforeEach(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -635,8 +644,8 @@ describe("TopicSchemaRequest", () => { beforeEach(async () => { console.error = jest.fn(); - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockRejectedValue({ status: "400 BAD_REQUEST", @@ -740,8 +749,8 @@ describe("TopicSchemaRequest", () => { describe("enables user to send a schema request", () => { beforeEach(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockResolvedValue({ success: true, diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx index 331703f330..01e0c84c84 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx @@ -88,6 +88,11 @@ function TopicSchemaRequest(props: TopicSchemaRequestProps) { >({ queryKey: ["getEnvs"], queryFn: () => getAllEnvironmentsForTopicAndAcl(), + // not every Kafka Environment has an associated env for schemas, + // so we only want to show those who do. + // We use name and ID related to the Kafka Environment in form and mutation. + select: (kafkaEnvironments) => + kafkaEnvironments.filter((env) => env.associatedEnv), onSuccess: (environments) => { if (presetEnvironment) { const validEnv = environments.find( From 5c57cd21e2236d6783af7dedc9b1dbfed91e163d Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Tue, 10 Oct 2023 16:42:29 +0300 Subject: [PATCH 06/14] Remove api call from environment-api Signed-off-by: Mirjam Aulbach --- coral/src/domain/environment/environment-api.ts | 9 --------- coral/src/domain/environment/index.ts | 2 -- 2 files changed, 11 deletions(-) diff --git a/coral/src/domain/environment/environment-api.ts b/coral/src/domain/environment/environment-api.ts index 63fbee03f2..e744b4755c 100644 --- a/coral/src/domain/environment/environment-api.ts +++ b/coral/src/domain/environment/environment-api.ts @@ -51,14 +51,6 @@ const getEnvironmentsForTopicRequest = async (): Promise => { return transformEnvironmentApiResponse(apiResponse); }; -const getAllEnvironmentsForSchema = async (): Promise => { - const apiResponse = await api.get>( - API_PATHS.getSchemaRegEnvs - ); - - return transformEnvironmentApiResponse(apiResponse); -}; - const getPaginatedEnvironmentsForSchema = async ( params: KlawApiRequestQueryParameters<"getSchemaRegEnvsPaginated"> ): Promise => { @@ -112,7 +104,6 @@ export { getAllEnvironmentsForTopicAndAcl, getPaginatedEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, - getAllEnvironmentsForSchema, getPaginatedEnvironmentsForSchema, getAllEnvironmentsForConnector, getPaginatedEnvironmentsForConnector, diff --git a/coral/src/domain/environment/index.ts b/coral/src/domain/environment/index.ts index 84801895e8..d9bd1bcece 100644 --- a/coral/src/domain/environment/index.ts +++ b/coral/src/domain/environment/index.ts @@ -1,6 +1,5 @@ import { getAllEnvironmentsForConnector, - getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, @@ -18,7 +17,6 @@ import { export { ALL_ENVIRONMENTS_VALUE, getAllEnvironmentsForConnector, - getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, From 84ee4edc067eecb77e96457c4efdb4dc205b0ff6 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Tue, 10 Oct 2023 17:02:04 +0300 Subject: [PATCH 07/14] Update EnvironmentFilter and components using it. Signed-off-by: Mirjam Aulbach --- .../features/approvals/acls/AclApprovals.tsx | 2 +- .../connectors/ConnectorApprovals.tsx | 2 +- .../schemas/SchemaApprovals.test.tsx | 43 +++--- .../approvals/schemas/SchemaApprovals.tsx | 5 +- .../approvals/topics/TopicApprovals.tsx | 2 +- .../filters/EnvironmentFilter.test.tsx | 145 +++++++++++++----- .../components/filters/EnvironmentFilter.tsx | 59 +++++-- .../connectors/browse/BrowseConnectors.tsx | 5 +- .../features/requests/acls/AclRequests.tsx | 2 +- .../requests/connectors/ConnectorRequests.tsx | 5 +- .../requests/schemas/SchemaRequests.test.tsx | 40 +++-- .../requests/schemas/SchemaRequests.tsx | 5 +- .../schemas/utils/mocked-api-responses.ts | 5 +- .../requests/topics/TopicRequests.tsx | 2 +- .../features/topics/browse/BrowseTopics.tsx | 2 +- .../app/pages/requests/schemas/index.test.tsx | 10 +- 16 files changed, 221 insertions(+), 113 deletions(-) diff --git a/coral/src/app/features/approvals/acls/AclApprovals.tsx b/coral/src/app/features/approvals/acls/AclApprovals.tsx index 1db622c4a8..801a6fdbd1 100644 --- a/coral/src/app/features/approvals/acls/AclApprovals.tsx +++ b/coral/src/app/features/approvals/acls/AclApprovals.tsx @@ -242,7 +242,7 @@ function AclApprovals() { filters={[ , , , diff --git a/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx b/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx index cc589fc6e1..803d0a5440 100644 --- a/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx +++ b/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx @@ -266,7 +266,7 @@ function ConnectorApprovals() { filters={[ , , , diff --git a/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx b/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx index 7bda0a99d9..c8e0e50e50 100644 --- a/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx +++ b/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx @@ -2,7 +2,7 @@ import { cleanup, screen, waitFor, within } from "@testing-library/react"; import { waitForElementToBeRemoved } from "@testing-library/react/pure"; import userEvent from "@testing-library/user-event"; import SchemaApprovals from "src/app/features/approvals/schemas/SchemaApprovals"; -import { getAllEnvironmentsForSchema } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { createMockEnvironmentDTO } from "src/domain/environment/environment-test-helper"; import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer"; import { @@ -19,9 +19,9 @@ import { customRender } from "src/services/test-utils/render-with-wrappers"; jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema +const mockGetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockGetSchemaRequestsForApprover = @@ -37,8 +37,9 @@ const mockApproveSchemaRequest = approveSchemaRequest as jest.MockedFunction< >; const mockedEnvironments = [ - { name: "DEV", id: "1" }, - { name: "TST", id: "2" }, + { name: "DEV", id: "1", associatedEnv: { name: "DEV_SCH", id: "111" } }, + { name: "TST", id: "2", associatedEnv: { name: "TST_SCH", id: "222" } }, + { name: "RANDOM", id: "3" }, ]; const mockedEnvironmentResponse = transformEnvironmentApiResponse([ @@ -132,7 +133,7 @@ describe("SchemaApprovals", () => { totalPages: 1, currentPage: 1, }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); }); afterEach(() => { @@ -176,7 +177,7 @@ describe("SchemaApprovals", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -238,7 +239,7 @@ describe("SchemaApprovals", () => { totalPages: 1, currentPage: 1, }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); }); afterEach(() => { @@ -344,7 +345,7 @@ describe("SchemaApprovals", () => { entries: [], }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); customRender(, { queryClient: true, @@ -385,7 +386,7 @@ describe("SchemaApprovals", () => { describe("shows a detail modal for schema request", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -505,7 +506,7 @@ describe("SchemaApprovals", () => { describe("handles filtering entries in the table", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue({ @@ -576,13 +577,19 @@ describe("SchemaApprovals", () => { name: "Filter by Environment", }); const environmentOption = screen.getByRole("option", { - name: mockedEnvironments[0].name, + // we're defining the test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + name: mockedEnvironments[0].associatedEnv.name, }); await userEvent.selectOptions(environmentFilter, environmentOption); expect(mockGetSchemaRequestsForApprover).toHaveBeenNthCalledWith(2, { ...defaultApiParams, - env: mockedEnvironments[0].id, + // we're defining the test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + env: mockedEnvironments[0].associatedEnv.id, }); }); @@ -613,7 +620,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -711,7 +718,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -836,7 +843,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -1006,7 +1013,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( diff --git a/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx b/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx index e5a96e808e..cc3cd1bcef 100644 --- a/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx +++ b/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx @@ -263,10 +263,7 @@ function SchemaApprovals() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/approvals/topics/TopicApprovals.tsx b/coral/src/app/features/approvals/topics/TopicApprovals.tsx index 661154e064..29d0130d6d 100644 --- a/coral/src/app/features/approvals/topics/TopicApprovals.tsx +++ b/coral/src/app/features/approvals/topics/TopicApprovals.tsx @@ -286,7 +286,7 @@ function TopicApprovals() { filters={[ , , , diff --git a/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx b/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx index 1dc03380e1..a4a54b4127 100644 --- a/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx +++ b/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx @@ -5,7 +5,6 @@ import EnvironmentFilter from "src/app/features/components/filters/EnvironmentFi import { withFiltersContext } from "src/app/features/components/filters/useFiltersContext"; import { getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema, getAllEnvironmentsForConnector, } from "src/domain/environment"; import { createEnvironment } from "src/domain/environment/environment-test-helper"; @@ -18,11 +17,6 @@ const mockGetEnvironments = typeof getAllEnvironmentsForTopicAndAcl >; -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema - >; - const mockGetSyncConnectorsEnvironments = getAllEnvironmentsForConnector as jest.MockedFunction< typeof getAllEnvironmentsForConnector @@ -42,18 +36,13 @@ const mockEnvironments = [ const filterLabel = "Filter by Environment"; const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); describe("EnvironmentFilter.tsx", () => { - describe("uses a given endpoint to fetch environments", () => { + describe("uses different endpoint to fetch environments dependent on props", () => { beforeEach(() => { mockGetEnvironments.mockResolvedValue([]); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); }); afterEach(() => { @@ -61,42 +50,35 @@ describe("EnvironmentFilter.tsx", () => { jest.resetAllMocks(); }); - it("fetches from the getAllEnvironmentsForTopicAndAcl endpoint", () => { + it("fetches environments for 'TOPIC_AND_ACL'", () => { + const WrappedEnvironmentFilter = withFiltersContext({ + element: , + }); customRender(, { memoryRouter: true, queryClient: true, }); expect(mockGetEnvironments).toHaveBeenCalled(); - expect(mockGetSchemaRegistryEnvironments).not.toHaveBeenCalled(); expect(mockGetSyncConnectorsEnvironments).not.toHaveBeenCalled(); }); - it("fetches from the getAllEnvironmentsForSchema endpoint", () => { + it("fetches environments for 'SCHEMA'", () => { const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); customRender(, { memoryRouter: true, queryClient: true, }); - expect(mockGetSchemaRegistryEnvironments).toHaveBeenCalled(); - expect(mockGetEnvironments).not.toHaveBeenCalled(); + expect(mockGetEnvironments).toHaveBeenCalled(); expect(mockGetSyncConnectorsEnvironments).not.toHaveBeenCalled(); }); - it("fetches from the getAllEnvironmentsForConnector endpoint", () => { + it("fetches environments for 'CONNECTOR'", () => { const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); customRender(, { memoryRouter: true, @@ -105,14 +87,12 @@ describe("EnvironmentFilter.tsx", () => { expect(mockGetSyncConnectorsEnvironments).toHaveBeenCalled(); expect(mockGetEnvironments).not.toHaveBeenCalled(); - expect(mockGetSchemaRegistryEnvironments).not.toHaveBeenCalled(); }); }); - describe("renders all necessary elements", () => { + describe("renders all necessary elements for 'TOPIC_AND_ACL' (same as 'CONNECTOR')", () => { beforeAll(async () => { mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { @@ -158,6 +138,104 @@ describe("EnvironmentFilter.tsx", () => { }); }); + describe("renders all necessary elements for 'SCHEMA'", () => { + const associatedEnvDev = { + id: "111", + name: "DEV_SCH", + }; + + const associatedEnvTst = { + id: "222", + name: "TST_SCH", + }; + + const mockEnvironmentsSchema = [ + createEnvironment({ + name: "DEV", + id: "1", + associatedEnv: associatedEnvDev, + }), + createEnvironment({ + name: "TST", + id: "2", + associatedEnv: associatedEnvTst, + }), + + createEnvironment({ + name: "DIV", + id: "3", + }), + ]; + + beforeAll(async () => { + mockGetEnvironments.mockResolvedValue(mockEnvironmentsSchema); + mockGetSyncConnectorsEnvironments.mockResolvedValue([]); + + const WrappedEnvironmentFilter = withFiltersContext({ + element: , + }); + + customRender(, { + memoryRouter: true, + queryClient: true, + }); + await waitForElementToBeRemoved( + screen.getByTestId("select-environment-loading") + ); + }); + + afterAll(() => { + cleanup(); + jest.resetAllMocks(); + }); + + it("shows a select element for Kafka Environments", () => { + const select = screen.getByRole("combobox", { + name: filterLabel, + }); + + expect(select).toBeEnabled(); + }); + + it("renders a list of options for environments with associated envs plus a option for `All Environments`", () => { + const filteredEnvs = mockEnvironmentsSchema.filter( + (env) => env.associatedEnv + ); + + filteredEnvs.forEach((environment) => { + const option = screen.getByRole("option", { + // associated env is not undefined in this test, + // no need for warning + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + name: environment.associatedEnv.name, + }); + + expect(option).toBeEnabled(); + }); + + expect(screen.getAllByRole("option")).toHaveLength( + filteredEnvs.length + 1 + ); + }); + + it("shows `All Environments` as the active option one", () => { + const option = screen.getByRole("option", { + selected: true, + }); + expect(option).toHaveAccessibleName("All Environments"); + }); + + it("shows the name of the associated env as option", () => { + const option = screen.getByRole("option", { + name: associatedEnvDev.name, + }); + + expect(option).toHaveAccessibleName(associatedEnvDev.name); + expect(option).toHaveValue(associatedEnvDev.id); + }); + }); + describe("sets the active environment based on a query param", () => { const mockedQueryParamDev = mockEnvironments[0].id; @@ -165,7 +243,6 @@ describe("EnvironmentFilter.tsx", () => { const routePath = `/?environment=${mockedQueryParamDev}`; mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { @@ -196,7 +273,6 @@ describe("EnvironmentFilter.tsx", () => { describe("handles user selecting a environment", () => { beforeEach(async () => { mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { @@ -230,7 +306,6 @@ describe("EnvironmentFilter.tsx", () => { describe("updates the search param to preserve environment in url", () => { beforeEach(async () => { mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { diff --git a/coral/src/app/features/components/filters/EnvironmentFilter.tsx b/coral/src/app/features/components/filters/EnvironmentFilter.tsx index dea4e9b757..c57668ca6e 100644 --- a/coral/src/app/features/components/filters/EnvironmentFilter.tsx +++ b/coral/src/app/features/components/filters/EnvironmentFilter.tsx @@ -4,35 +4,66 @@ import { useFiltersContext } from "src/app/features/components/filters/useFilter import { Environment, getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema, getAllEnvironmentsForConnector, } from "src/domain/environment"; import { HTTPError } from "src/services/api"; -type EnvironmentEndpoint = - | "getAllEnvironmentsForTopicAndAcl" - | "getAllEnvironmentsForSchema" - | "getAllEnvironmentsForConnector"; +type EnvironmentFor = "TOPIC_AND_ACL" | "SCHEMA" | "CONNECTOR"; interface EnvironmentFilterProps { - isSchemaRegistryEnvironments?: boolean; - environmentEndpoint: EnvironmentEndpoint; + environmentsFor: EnvironmentFor; } const environmentEndpointMap: { - [key in EnvironmentEndpoint]: () => Promise; + [key in EnvironmentFor]: { + apiEndpoint: () => Promise; + // we use the api function name as query usually, so we + // want to keep that pattern here, too. + queryFn: string; + }; } = { - getAllEnvironmentsForTopicAndAcl: getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema: getAllEnvironmentsForSchema, - getAllEnvironmentsForConnector: getAllEnvironmentsForConnector, + TOPIC_AND_ACL: { + apiEndpoint: getAllEnvironmentsForTopicAndAcl, + queryFn: "getAllEnvironmentsForTopicAndAcl", + }, + SCHEMA: { + apiEndpoint: getAllEnvironmentsForTopicAndAcl, + queryFn: "getAllEnvironmentsForTopicAndAcl", + }, + CONNECTOR: { + apiEndpoint: getAllEnvironmentsForConnector, + queryFn: "getAllEnvironmentsForConnector", + }, }; -function EnvironmentFilter({ environmentEndpoint }: EnvironmentFilterProps) { +function filterEnvironmentsForSchema( + environments: Environment[] +): Environment[] { + return environments + .map((env) => { + if (env.associatedEnv) { + return { + ...env, + id: env.associatedEnv.id, + name: env.associatedEnv.name, + }; + } + }) + .filter((entry) => entry !== undefined) as Environment[]; +} + +function EnvironmentFilter({ environmentsFor }: EnvironmentFilterProps) { const { environment, setFilterValue } = useFiltersContext(); const { data: environments } = useQuery( - [environmentEndpoint], + [environmentEndpointMap[environmentsFor].queryFn], { - queryFn: environmentEndpointMap[environmentEndpoint], + queryFn: environmentEndpointMap[environmentsFor].apiEndpoint, + select: (environments) => { + if (environmentsFor === "SCHEMA") { + return filterEnvironmentsForSchema(environments); + } + return environments; + }, } ); diff --git a/coral/src/app/features/connectors/browse/BrowseConnectors.tsx b/coral/src/app/features/connectors/browse/BrowseConnectors.tsx index 2fa6f14396..11d71cec07 100644 --- a/coral/src/app/features/connectors/browse/BrowseConnectors.tsx +++ b/coral/src/app/features/connectors/browse/BrowseConnectors.tsx @@ -54,10 +54,7 @@ function BrowseConnectors() { , - , + , , ]} table={ diff --git a/coral/src/app/features/requests/acls/AclRequests.tsx b/coral/src/app/features/requests/acls/AclRequests.tsx index 6bc7c92d51..6e895f50c4 100644 --- a/coral/src/app/features/requests/acls/AclRequests.tsx +++ b/coral/src/app/features/requests/acls/AclRequests.tsx @@ -170,7 +170,7 @@ function AclRequests() { filters={[ , , , diff --git a/coral/src/app/features/requests/connectors/ConnectorRequests.tsx b/coral/src/app/features/requests/connectors/ConnectorRequests.tsx index 902a0011b2..2185da2d2b 100644 --- a/coral/src/app/features/requests/connectors/ConnectorRequests.tsx +++ b/coral/src/app/features/requests/connectors/ConnectorRequests.tsx @@ -150,10 +150,7 @@ function ConnectorRequests() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx b/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx index f8eac1f4f3..d4e376c6c3 100644 --- a/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx +++ b/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx @@ -17,16 +17,16 @@ import { mockedEnvironmentResponse, } from "src/app/features/requests/schemas/utils/mocked-api-responses"; import userEvent from "@testing-library/user-event"; -import { getAllEnvironmentsForSchema } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { requestStatusNameMap } from "src/app/features/approvals/utils/request-status-helper"; import { requestOperationTypeNameMap } from "src/app/features/approvals/utils/request-operation-type-helper"; jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/schema-request/schema-request-api.ts"); -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema +const mockgetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockGetSchemaRequests = getSchemaRequests as jest.MockedFunction< @@ -60,7 +60,7 @@ describe("SchemaRequest", () => { // while making sure to not swallow other console.errors console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue({ @@ -111,7 +111,7 @@ describe("SchemaRequest", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -184,7 +184,7 @@ describe("SchemaRequest", () => { describe("renders pagination dependent on response", () => { beforeEach(() => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue({ @@ -290,7 +290,7 @@ describe("SchemaRequest", () => { describe("handles user stepping through pagination", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue({ @@ -338,7 +338,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by 'environment'", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -371,20 +371,26 @@ describe("SchemaRequest", () => { }); const environmentOption = screen.getByRole("option", { - name: mockedEnvironmentResponse[0].name, + // we created test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + name: mockedEnvironmentResponse[0].associatedEnv.name, }); await userEvent.selectOptions(environmentFilter, environmentOption); expect(mockGetSchemaRequests).toHaveBeenNthCalledWith(2, { ...defaultApiParams, - env: mockedEnvironmentResponse[0].id, + // we created test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + env: mockedEnvironmentResponse[0].associatedEnv.id, }); }); }); describe("user can filter schema requests by 'Request type'", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -431,7 +437,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by 'status'", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -478,7 +484,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by 'topic' they searched for", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -523,7 +529,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by only showing their own requests", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -568,7 +574,7 @@ describe("SchemaRequest", () => { describe("shows a detail modal for schema request", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -664,7 +670,7 @@ describe("SchemaRequest", () => { const originalConsoleError = console.error; beforeEach(async () => { console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); diff --git a/coral/src/app/features/requests/schemas/SchemaRequests.tsx b/coral/src/app/features/requests/schemas/SchemaRequests.tsx index 480362e143..a59d7752a1 100644 --- a/coral/src/app/features/requests/schemas/SchemaRequests.tsx +++ b/coral/src/app/features/requests/schemas/SchemaRequests.tsx @@ -160,10 +160,7 @@ function SchemaRequests() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts b/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts index 1ce252364c..8ac4312f33 100644 --- a/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts +++ b/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts @@ -89,8 +89,9 @@ const mockedApiResponseSchemaRequests: SchemaRequestApiResponse = transformGetSchemaRequests(mockedApiResponses); const mockedEnvironments = [ - { name: "DEV", id: "1" }, - { name: "TST", id: "2" }, + { name: "DEV", id: "1", associatedEnv: { name: "DEV_SCH", id: "111" } }, + { name: "TST", id: "2", associatedEnv: { name: "TST_SCH", id: "222" } }, + { name: "RANDOM", id: "2" }, ]; const mockedEnvironmentResponse = transformEnvironmentApiResponse([ diff --git a/coral/src/app/features/requests/topics/TopicRequests.tsx b/coral/src/app/features/requests/topics/TopicRequests.tsx index 79b408eb3e..a0e2faa9a6 100644 --- a/coral/src/app/features/requests/topics/TopicRequests.tsx +++ b/coral/src/app/features/requests/topics/TopicRequests.tsx @@ -152,7 +152,7 @@ function TopicRequests() { filters={[ , , , diff --git a/coral/src/app/features/topics/browse/BrowseTopics.tsx b/coral/src/app/features/topics/browse/BrowseTopics.tsx index 0bea56788d..7a873ae48e 100644 --- a/coral/src/app/features/topics/browse/BrowseTopics.tsx +++ b/coral/src/app/features/topics/browse/BrowseTopics.tsx @@ -57,7 +57,7 @@ function BrowseTopics() { , , , ]} diff --git a/coral/src/app/pages/requests/schemas/index.test.tsx b/coral/src/app/pages/requests/schemas/index.test.tsx index 92a013574d..8f3ce1da7d 100644 --- a/coral/src/app/pages/requests/schemas/index.test.tsx +++ b/coral/src/app/pages/requests/schemas/index.test.tsx @@ -3,14 +3,14 @@ import { customRender } from "src/services/test-utils/render-with-wrappers"; import SchemaRequestsPage from "src/app/pages/requests/schemas/index"; import { cleanup, screen, within } from "@testing-library/react"; import { waitForElementToBeRemoved } from "@testing-library/react/pure"; -import { getAllEnvironmentsForSchema } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/schema-request/schema-request-api.ts"); -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema +const mockGetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockGetSchemaRequests = getSchemaRequests as jest.MockedFunction< typeof getSchemaRequests @@ -18,7 +18,7 @@ const mockGetSchemaRequests = getSchemaRequests as jest.MockedFunction< describe("SchemaRequestPage", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockGetSchemaRequests.mockResolvedValue({ entries: [], totalPages: 1, From 108e9d5f98fb3f362bc270a3cb96e404e70dc31e Mon Sep 17 00:00:00 2001 From: muralibasani Date: Thu, 5 Oct 2023 14:34:44 +0200 Subject: [PATCH 08/14] Update schema request with kafka env Signed-off-by: muralibasani --- .../EnvsClustersTenantsController.java | 9 --- .../aiven/klaw/error/KlawErrorMessages.java | 5 ++ .../io/aiven/klaw/helpers/KwConstants.java | 2 + .../klaw/service/CommonUtilsService.java | 3 +- .../EnvsClustersTenantsControllerService.java | 4 +- .../SchemaRegistryControllerService.java | 26 +++++++- .../static/js/requestAvroSchemaUpload.js | 61 +++++-------------- .../main/resources/templates/browseAcls.html | 2 +- .../resources/templates/requestSchema.html | 17 ++---- .../io/aiven/klaw/TopicAclControllerIT.java | 29 ++++++++- .../SchemaRegistryControllerServiceTest.java | 18 +++++- openapi.yaml | 21 ------- 12 files changed, 100 insertions(+), 97 deletions(-) diff --git a/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java b/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java index 339c723b89..7da0652888 100644 --- a/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java +++ b/core/src/main/java/io/aiven/klaw/controller/EnvsClustersTenantsController.java @@ -229,15 +229,6 @@ public ResponseEntity> getSchemaRegEnv( HttpStatus.OK); } - @RequestMapping( - value = "/getEnvsForSchemaRequests", - method = RequestMethod.GET, - produces = {MediaType.APPLICATION_JSON_VALUE}) - public ResponseEntity> getEnvsForSchemaRequests() { - return new ResponseEntity<>( - envsClustersTenantsControllerService.getEnvsForSchemaRequests(), HttpStatus.OK); - } - @RequestMapping( value = "/getKafkaConnectEnvs", method = RequestMethod.GET, diff --git a/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java b/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java index b57b12dae3..4ced502d47 100644 --- a/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java +++ b/core/src/main/java/io/aiven/klaw/error/KlawErrorMessages.java @@ -281,6 +281,11 @@ public class KlawErrorMessages { public static final String SCHEMA_ERR_107 = "Failure. A request already exists for this topic."; + public static final String SCHEMA_ERR_108 = "Failure. There is no associated schema environment."; + + public static final String SCHEMA_ERR_109 = + "Failure. Request Schema environments not configured Settings - tenant config"; + public static final String SERVER_CONFIG_ERR_101 = "Failure. Invalid json / incorrect name values. Check tenant and env details."; diff --git a/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java b/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java index d6c46e00eb..ed0823bbf6 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java +++ b/core/src/main/java/io/aiven/klaw/helpers/KwConstants.java @@ -108,6 +108,8 @@ public class KwConstants { public static final String ORDER_OF_TOPIC_ENVS = "ORDER_OF_ENVS"; + public static final String REQUEST_SCHEMA_OF_ENVS = "REQUEST_SCHEMA_OF_ENVS"; + public static final String ORDER_OF_KAFKA_CONNECT_ENVS = "ORDER_OF_KAFKA_CONNECT_ENVS"; public static final int DAYS_EXPIRY_DEFAULT_TENANT = 365 * 10; diff --git a/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java b/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java index 6f4a7c042b..85f81be3d9 100644 --- a/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java +++ b/core/src/main/java/io/aiven/klaw/service/CommonUtilsService.java @@ -1,6 +1,7 @@ package io.aiven.klaw.service; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_TOPIC_ENVS; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static io.aiven.klaw.helpers.KwConstants.REQUEST_TOPICS_OF_ENVS; import static io.aiven.klaw.model.enums.AuthenticationType.DATABASE; @@ -549,7 +550,7 @@ public String getEnvProperty(Integer tenantId, String envPropertyType) { requestConn.forEach(a -> intOrderEnvsList.add(Integer.parseInt(a))); } } - case "REQUEST_SCHEMA_OF_ENVS" -> { + case REQUEST_SCHEMA_OF_ENVS -> { List requestSchema = tenantModel.getRequestSchemaEnvironmentsList(); if (requestSchema != null && !requestSchema.isEmpty()) { requestSchema.forEach(a -> intOrderEnvsList.add(Integer.parseInt(a))); diff --git a/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java b/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java index 94f0eb526e..1c244965cc 100644 --- a/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/EnvsClustersTenantsControllerService.java @@ -16,6 +16,7 @@ import static io.aiven.klaw.helpers.KwConstants.DEFAULT_TENANT_ID; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_KAFKA_CONNECT_ENVS; import static io.aiven.klaw.helpers.KwConstants.ORDER_OF_TOPIC_ENVS; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static io.aiven.klaw.helpers.KwConstants.REQUEST_TOPICS_OF_ENVS; import static io.aiven.klaw.helpers.KwConstants.SUPERADMIN_ROLE; import static io.aiven.klaw.model.enums.RolesType.SUPERADMIN; @@ -498,8 +499,7 @@ public List getSchemaRegEnvs() { public List getEnvsForSchemaRequests() { int tenantId = getUserDetails(getUserName()).getTenantId(); - String requestSchemasEnvs = - commonUtilsService.getEnvProperty(tenantId, "REQUEST_SCHEMA_OF_ENVS"); + String requestSchemasEnvs = commonUtilsService.getEnvProperty(tenantId, REQUEST_SCHEMA_OF_ENVS); if (requestSchemasEnvs == null) { return new ArrayList<>(); } diff --git a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java index 0ab0cd88e8..cefb2ef1b5 100644 --- a/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java +++ b/core/src/main/java/io/aiven/klaw/service/SchemaRegistryControllerService.java @@ -7,6 +7,9 @@ import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_105; import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_106; import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_107; +import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_108; +import static io.aiven.klaw.error.KlawErrorMessages.SCHEMA_ERR_109; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static io.aiven.klaw.model.enums.MailType.*; import static org.springframework.beans.BeanUtils.copyProperties; @@ -439,8 +442,7 @@ private SchemaRequestModel buildSchemaRequestFromPromotionRequest( schemaRequest.setSchemaversion(schemaPromotion.getSchemaVersion()); schemaRequest.setTopicname(schemaPromotion.getTopicName()); schemaRequest.setForceRegister(schemaPromotion.isForceRegister()); - Optional env = getSchemaEnvFromKafkaEnvId(schemaPromotion.getTargetEnvironment()); - schemaRequest.setEnvironment(env.isPresent() ? env.get().getId() : null); + schemaRequest.setEnvironment(schemaPromotion.getTargetEnvironment()); return schemaRequest; } @@ -455,6 +457,24 @@ public ApiResponse uploadSchema( return ApiResponse.NOT_AUTHORIZED; } + int tenantId = commonUtilsService.getTenantId(getUserName()); + Optional schemaEnv = getSchemaEnvFromKafkaEnvId(schemaRequest.getEnvironment()); + if (schemaEnv.isPresent()) { + schemaRequest.setEnvironment(schemaEnv.get().getId()); + + String requestSchemasEnvs = + commonUtilsService.getEnvProperty(tenantId, REQUEST_SCHEMA_OF_ENVS); + if (requestSchemasEnvs == null) { + return ApiResponse.notOk(SCHEMA_ERR_109); + } + String[] reqSchemaEnvs = requestSchemasEnvs.split(","); + if (!Arrays.stream(reqSchemaEnvs).toList().contains(schemaEnv.get().getId())) { + return ApiResponse.notOk(SCHEMA_ERR_109); + } + } else { + return ApiResponse.notOk(SCHEMA_ERR_108); + } + // If force register is not set validate the schema if (validateCompatiblityOnSave && (schemaRequest.getForceRegister() == null || !schemaRequest.getForceRegister())) { @@ -475,7 +495,7 @@ public ApiResponse uploadSchema( Integer userTeamId = commonUtilsService.getTeamId(userName); schemaRequest.setTeamId(userTeamId); - int tenantId = commonUtilsService.getTenantId(getUserName()); + if (!userAndTopicOwnerAreOnTheSameTeam(schemaRequest.getTopicname(), userTeamId, tenantId)) { return ApiResponse.notOk(SCHEMA_ERR_106); } diff --git a/core/src/main/resources/static/js/requestAvroSchemaUpload.js b/core/src/main/resources/static/js/requestAvroSchemaUpload.js index cbb67bd959..dbbfc52ba1 100644 --- a/core/src/main/resources/static/js/requestAvroSchemaUpload.js +++ b/core/src/main/resources/static/js/requestAvroSchemaUpload.js @@ -68,48 +68,35 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2000); } - $scope.getSchemaEnvs = function() { - - $http({ - method: "GET", - url: "getEnvsForSchemaRequests", - headers : { 'Content-Type' : 'application/json' } - }).success(function(output) { - $scope.allschemaenvs = output; - }).error( - function(error) - { - $scope.alert = error; - } - ); - } $scope.loadParams = function() { - var topicSelected; - var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); - if (sParameterName[0] == "topicname") + if (sParameterName[0] === "topicname") { $scope.topicSelectedFromUrl = sParameterName[1]; $scope.addSchema.topicname = $scope.topicSelectedFromUrl; $scope.validatedSchema=false; - $scope.getAllTopics(); + } + if (sParameterName[0] === "envId") + { + $scope.addSchema.envId = sParameterName[1]; + $scope.getEnvDetails($scope.addSchema.envId); } } } - $scope.getEnvs = function() { - + $scope.getEnvDetails = function(envSelected) { $http({ method: "GET", - url: "getEnvs", - headers : { 'Content-Type' : 'application/json' } + url: "getEnvDetails", + headers : { 'Content-Type' : 'application/json' }, + params: {'envSelected' : envSelected, 'envType' : 'kafka' }, }).success(function(output) { - $scope.allenvs = output; + $scope.environmentDetails = output; }).error( function(error) { @@ -118,24 +105,6 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) ); } - $scope.getAllTopics = function() { - - $scope.alltopics = null; - $http({ - method: "GET", - url: "getTopicsOnly", - headers : { 'Content-Type' : 'application/json' }, - params: {'isMyTeamTopics' : 'true' }, - }).success(function(output) { - $scope.alltopics = output; - }).error( - function(error) - { - $scope.alert = error; - } - ); - } - $scope.cancelRequest = function() { $window.location.href = $window.location.origin + $scope.dashboardDetails.contextPath + "/browseTopics"; } @@ -146,9 +115,9 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) $scope.addSchema = function() { - if(!$scope.addSchema.envName) + if(!$scope.addSchema.envId) { - $scope.alertnote = "Please select an environment"; + $scope.alertnote = "Please select a valid environment"; $scope.showAlertToast(); return; } @@ -161,7 +130,7 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) }else { $scope.addSchema.topicname = $scope.addSchema.topicname.trim(); - if($scope.addSchema.topicname.length==0){ + if($scope.addSchema.topicname.length === 0){ $scope.alertnote = "Please fill in topic name."; $scope.showAlertToast(); return; @@ -179,7 +148,7 @@ app.controller("requestSchemaCtrl", function($scope, $http, $location, $window) $scope.alert = null; $scope.alertnote = null; - serviceInput['environment'] = $scope.addSchema.envName; + serviceInput['environment'] = $scope.addSchema.envId; serviceInput['topicname'] = $scope.addSchema.topicname; serviceInput['appname'] = "App"; serviceInput['remarks'] = $scope.addSchema.remarks; diff --git a/core/src/main/resources/templates/browseAcls.html b/core/src/main/resources/templates/browseAcls.html index 850f5383bb..2088704e15 100644 --- a/core/src/main/resources/templates/browseAcls.html +++ b/core/src/main/resources/templates/browseAcls.html @@ -907,7 +907,7 @@
Team
{{ aclRequest.teamname }}
- + diff --git a/core/src/main/resources/templates/requestSchema.html b/core/src/main/resources/templates/requestSchema.html index de973c80bd..68a4721563 100644 --- a/core/src/main/resources/templates/requestSchema.html +++ b/core/src/main/resources/templates/requestSchema.html @@ -453,7 +453,7 @@

Shortcuts

-
+
@@ -474,30 +474,25 @@

Shortcuts


-
- - + +
- - - + +
+
-
diff --git a/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java b/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java index 86410bd612..263d2830ab 100644 --- a/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java +++ b/core/src/test/java/io/aiven/klaw/TopicAclControllerIT.java @@ -1233,6 +1233,33 @@ public void createSREnv() throws Exception { ApiResponse response1 = OBJECT_MAPPER.readValue(response, new TypeReference<>() {}); assertThat(response1.isSuccess()).isTrue(); + KwPropertiesModel kwPropertiesModel = new KwPropertiesModel(); + kwPropertiesModel.setKwKey(TENANT_CONFIG_PROPERTY); + kwPropertiesModel.setKwValue( + """ + { + "tenantModel": + { + "tenantName": "default", + "baseSyncEnvironment": "DEV", + "orderOfTopicPromotionEnvsList": ["DEV"], + "requestTopicsEnvironmentsList": ["DEV"], + "requestSchemaEnvironmentsList": ["DEVSCH"] + } + }"""); + String jsonReq = OBJECT_MAPPER.writer().writeValueAsString(kwPropertiesModel); + + mvc.perform( + MockMvcRequestBuilders.post("/updateKwCustomProperty") + .with(user(superAdmin).password(superAdminPwd)) + .content(jsonReq) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + // get SR envs response = mvc.perform( @@ -1256,7 +1283,7 @@ public void createSchemaRequest() throws Exception { SchemaRequestModel schemaRequest = utilMethods.getSchemaRequests().get(0); schemaRequest.setTopicname(topicName + topicId1); schemaRequest.setRequestor(user1); - schemaRequest.setEnvironment("3"); // Schema reg env + schemaRequest.setEnvironment("1"); // Schema reg env schemaRequest.setSchemafull( "{\n" + " \"type\" : \"record\",\n" diff --git a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java index aa133550f3..77ae320918 100644 --- a/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java +++ b/core/src/test/java/io/aiven/klaw/service/SchemaRegistryControllerServiceTest.java @@ -1,5 +1,6 @@ package io.aiven.klaw.service; +import static io.aiven.klaw.helpers.KwConstants.REQUEST_SCHEMA_OF_ENVS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -306,6 +307,8 @@ public void uploadSchemaSuccess() throws KlawException { when(commonUtilsService.getEnvsFromUserId(anyString())) .thenReturn(new HashSet<>(Collections.singletonList("1"))); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); when(handleDbRequests.requestForSchema(any())).thenReturn(ApiResultStatus.SUCCESS.value); when(commonUtilsService.getTopicsForTopicName(anyString(), anyInt())) @@ -380,6 +383,7 @@ public void promoteSchemaSuccess() throws Exception { when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "1")); @@ -397,6 +401,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV1Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "1")); @@ -418,6 +423,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV2Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "2")); @@ -439,6 +445,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV3Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "3")); @@ -461,6 +468,7 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV4Success() throws Exception when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(true)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "4")); @@ -475,13 +483,14 @@ public void promoteSchemaEnsureCorrectSchemaSelectedV4Success() throws Exception @Test @Order(17) - public void promoteSchemaWithInCompaitbleSchemaReturnFailure() throws Exception { + public void promoteSchemaWithInCompatibleSchemaReturnFailure() throws Exception { mockGetEnvironment(); mockSchema(); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(clusterApiService.validateSchema(anyString(), anyString(), anyString(), anyInt())) .thenReturn(buildValidationResponse(false)); mockSchemaCreation(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("8"); ApiResponse returnedValue = schemaRegistryControllerService.promoteSchema(buildPromoteSchemaRequest(false, "4")); @@ -505,6 +514,8 @@ public void uploadSchemaIncompatibleSchemaError() throws KlawException { .thenReturn(new HashSet<>(Collections.singletonList("1"))); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); @@ -611,6 +622,8 @@ public void uploadSchema_NoValidationOnSave() throws KlawException { when(commonUtilsService.getTopicsForTopicName(anyString(), anyInt())) .thenReturn(List.of(topic)); when(commonUtilsService.getFilteredTopicsForTenant(any())).thenReturn(List.of(topic)); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); ApiResponse resultResp = schemaRegistryControllerService.uploadSchema(schemaRequest, RequestOperationType.CREATE); @@ -636,6 +649,8 @@ public void uploadSchema_ValidationPropertyNotSet() throws KlawException { .thenReturn(new HashSet<>(Collections.singletonList("1"))); when(commonUtilsService.getTenantId(anyString())).thenReturn(101); when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); + mockGetEnvironment(); + when(commonUtilsService.getEnvProperty(eq(101), eq(REQUEST_SCHEMA_OF_ENVS))).thenReturn("1"); NullPointerException ex = assertThrows( @@ -781,7 +796,6 @@ private static Topic createTopic() { } private void mockGetEnvironment() { - when(manageDatabase.getSchemaRegEnvList(anyInt())).thenReturn(createEnvList(8)); } diff --git a/openapi.yaml b/openapi.yaml index a9f6486d7a..263b4cfd11 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -4244,27 +4244,6 @@ } } }, - "/getEnvsForSchemaRequests" : { - "get" : { - "tags" : [ "envs-clusters-tenants-controller" ], - "operationId" : "getEnvsForSchemaRequests", - "responses" : { - "200" : { - "description" : "OK", - "content" : { - "application/json" : { - "schema" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/EnvModelResponse" - } - } - } - } - } - } - } - }, "/getEnvsBaseCluster" : { "get" : { "tags" : [ "envs-clusters-tenants-controller" ], From a59729222cf321e8cfbdb5f6b8ca433952cbeb1d Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 5 Oct 2023 15:23:14 +0200 Subject: [PATCH 09/14] Remove unused component Signed-off-by: Mirjam Aulbach --- .../SelectSchemaRegEnvironment.test.tsx | 130 ------------------ .../components/SelectSchemaRegEnvironment.tsx | 52 ------- 2 files changed, 182 deletions(-) delete mode 100644 coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx delete mode 100644 coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx diff --git a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx b/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx deleted file mode 100644 index 47a36b21a4..0000000000 --- a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.test.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import { cleanup, screen } from "@testing-library/react"; -import { - ALL_ENVIRONMENTS_VALUE, - getEnvironmentsForSchemaRequest, -} from "src/domain/environment"; -import { mockedEnvironmentResponse } from "src/domain/environment/environment-api.msw"; -import { customRender } from "src/services/test-utils/render-with-wrappers"; -import { waitForElementToBeRemoved } from "@testing-library/react/pure"; -import userEvent from "@testing-library/user-event"; -import { createEnvironment } from "src/domain/environment/environment-test-helper"; -import { SelectSchemaRegEnvironment } from "src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment"; - -jest.mock("src/domain/environment/environment-api.ts"); - -const mockGetSchemaRegistryEnvironments = - getEnvironmentsForSchemaRequest as jest.MockedFunction< - typeof getEnvironmentsForSchemaRequest - >; - -const filterLabel = "Filter by Environment"; - -describe("SelectSchemaRegEnvironment.tsx", () => { - const mockedEnvironmentDev = createEnvironment({ - name: "DEV", - id: "1", - }); - const mockedEnvironmentTst = createEnvironment({ - name: "TST", - id: "2", - }); - - describe("renders all necessary elements", () => { - const mockedOnChange = jest.fn(); - - beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ - mockedEnvironmentDev, - mockedEnvironmentTst, - ]); - - customRender( - , - { queryClient: true } - ); - await waitForElementToBeRemoved( - screen.getByTestId("select-environment-loading") - ); - }); - - afterAll(cleanup); - - it("shows a select element for Environments", () => { - const select = screen.getByRole("combobox", { - name: filterLabel, - }); - - expect(select).toBeEnabled(); - }); - - it("renders a list of options for Environments plus a option for `All environments`", () => { - mockedEnvironmentResponse.forEach((environment) => { - const option = screen.getByRole("option", { - name: environment.name, - }); - - expect(option).toBeEnabled(); - }); - expect(screen.getAllByRole("option")).toHaveLength( - mockedEnvironmentResponse.length + 1 - ); - }); - - it("shows `All Environments` as the active option based on given value", () => { - const option = screen.getByRole("option", { - selected: true, - }); - expect(option).toHaveAccessibleName("All Environments"); - }); - - it("has `All Environments` as the active value for option", () => { - const select = screen.getByRole("combobox", { - name: filterLabel, - }); - expect(select).toHaveValue(ALL_ENVIRONMENTS_VALUE); - }); - }); - - describe("handles user selecting a environment", () => { - const mockedOnChange = jest.fn(); - - beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ - mockedEnvironmentDev, - mockedEnvironmentTst, - ]); - - customRender( - , - { queryClient: true } - ); - await waitForElementToBeRemoved( - screen.getByTestId("select-environment-loading") - ); - }); - - afterEach(() => { - jest.resetAllMocks(); - cleanup(); - }); - - it("updates state for api call when user selects a new environment", async () => { - const select = screen.getByRole("combobox", { - name: filterLabel, - }); - const option = screen.getByRole("option", { - name: mockedEnvironmentDev.name, - }); - - await userEvent.selectOptions(select, option); - - expect(mockedOnChange).toHaveBeenCalledWith(mockedEnvironmentDev.id); - }); - }); -}); diff --git a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx b/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx deleted file mode 100644 index 1591b48ab4..0000000000 --- a/coral/src/app/features/approvals/schemas/components/SelectSchemaRegEnvironment.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { NativeSelect, Option } from "@aivenio/aquarium"; -import { - ALL_ENVIRONMENTS_VALUE, - Environment, - getEnvironmentsForSchemaRequest, -} from "src/domain/environment"; -import { useQuery } from "@tanstack/react-query"; - -type SelectSchemaRegEnvironmentProps = { - value: Environment["id"]; - onChange: (value: Environment["id"]) => void; -}; - -function SelectSchemaRegEnvironment(props: SelectSchemaRegEnvironmentProps) { - const { value, onChange } = props; - - const { data: environments, isLoading } = useQuery({ - queryKey: ["schemaRegistryEnvironments"], - queryFn: () => getEnvironmentsForSchemaRequest(), - }); - - if (isLoading || !environments) { - return ( -
- -
- ); - } else { - return ( - { - const env = event.target.value as Environment["id"]; - onChange(env); - }} - > - - - {environments.map((env: Environment) => ( - - ))} - - ); - } -} - -export { SelectSchemaRegEnvironment }; From a99e05f6b6dd5a0015216064481a76118d0b1b58 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 5 Oct 2023 15:24:31 +0200 Subject: [PATCH 10/14] Remove deleted endpoint. Signed-off-by: Mirjam Aulbach --- coral/src/domain/environment/environment-api.ts | 9 --------- coral/src/domain/environment/index.ts | 2 -- 2 files changed, 11 deletions(-) diff --git a/coral/src/domain/environment/environment-api.ts b/coral/src/domain/environment/environment-api.ts index 6c34ab471d..63fbee03f2 100644 --- a/coral/src/domain/environment/environment-api.ts +++ b/coral/src/domain/environment/environment-api.ts @@ -74,14 +74,6 @@ const getPaginatedEnvironmentsForSchema = async ( return transformPaginatedEnvironmentApiResponse(apiResponse); }; -const getEnvironmentsForSchemaRequest = async (): Promise => { - const apiResponse = await api.get< - KlawApiResponse<"getEnvsForSchemaRequests"> - >(API_PATHS.getEnvsForSchemaRequests); - - return transformEnvironmentApiResponse(apiResponse); -}; - const getAllEnvironmentsForConnector = async (): Promise => { const apiResponse = await api.get>( API_PATHS.getSyncConnectorsEnv @@ -122,7 +114,6 @@ export { getEnvironmentsForTopicRequest, getAllEnvironmentsForSchema, getPaginatedEnvironmentsForSchema, - getEnvironmentsForSchemaRequest, getAllEnvironmentsForConnector, getPaginatedEnvironmentsForConnector, getUpdateEnvStatus, diff --git a/coral/src/domain/environment/index.ts b/coral/src/domain/environment/index.ts index 6e2d9192dd..84801895e8 100644 --- a/coral/src/domain/environment/index.ts +++ b/coral/src/domain/environment/index.ts @@ -2,7 +2,6 @@ import { getAllEnvironmentsForConnector, getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, - getEnvironmentsForSchemaRequest, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, getPaginatedEnvironmentsForSchema, @@ -21,7 +20,6 @@ export { getAllEnvironmentsForConnector, getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, - getEnvironmentsForSchemaRequest, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, getPaginatedEnvironmentsForSchema, From a025b252aadda9c620ae386c0da461bc7197689e Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Thu, 5 Oct 2023 15:32:04 +0200 Subject: [PATCH 11/14] Use getEnvs endpoint instead of deleted one. Signed-off-by: Mirjam Aulbach --- .../TopicSchemaRequest.test.tsx | 30 +++++++++---------- .../schema-request/TopicSchemaRequest.tsx | 6 ++-- .../app/pages/topics/schema-request.test.tsx | 10 +++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx index f16ef712d9..4fdf045031 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx @@ -8,7 +8,7 @@ import { } from "@testing-library/react/pure"; import userEvent from "@testing-library/user-event"; import { TopicSchemaRequest } from "src/app/features/topics/schema-request/TopicSchemaRequest"; -import { getEnvironmentsForSchemaRequest } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { createMockEnvironmentDTO } from "src/domain/environment/environment-test-helper"; import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer"; import { requestSchemaCreation } from "src/domain/schema-request"; @@ -19,9 +19,9 @@ jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/topic/topic-api.ts"); -const mockGetSchemaRegistryEnvironments = - getEnvironmentsForSchemaRequest as jest.MockedFunction< - typeof getEnvironmentsForSchemaRequest +const mockgetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockCreateSchemaRequest = requestSchemaCreation as jest.MockedFunction< typeof requestSchemaCreation @@ -75,7 +75,7 @@ describe("TopicSchemaRequest", () => { describe("checks if topicName passed from url is part of topics user can request schemas for", () => { beforeEach(() => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -145,7 +145,7 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env ID query is part of list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -184,7 +184,7 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env name query is part of list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -223,7 +223,7 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env id query does not exist in list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -244,7 +244,7 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env name query does not exist in list of environments", async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([ + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ ...mockedGetSchemaRegistryEnvironments, ]); @@ -270,7 +270,7 @@ describe("TopicSchemaRequest", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore useQuerySpy.mockReturnValue({ data: [], isLoading: true }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -308,7 +308,7 @@ describe("TopicSchemaRequest", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -441,7 +441,7 @@ describe("TopicSchemaRequest", () => { describe("shows errors when user does not fill out correctly", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -519,7 +519,7 @@ describe("TopicSchemaRequest", () => { describe("enables user to cancel the form input", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockImplementation(jest.fn()); @@ -635,7 +635,7 @@ describe("TopicSchemaRequest", () => { beforeEach(async () => { console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockRejectedValue({ @@ -740,7 +740,7 @@ describe("TopicSchemaRequest", () => { describe("enables user to send a schema request", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedGetSchemaRegistryEnvironments ); mockCreateSchemaRequest.mockResolvedValue({ diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx index 2ffc436652..331703f330 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx @@ -17,7 +17,7 @@ import { } from "src/app/features/topics/schema-request/form-schemas/topic-schema-request-form"; import { Environment, - getEnvironmentsForSchemaRequest, + getAllEnvironmentsForTopicAndAcl, } from "src/domain/environment"; import { requestSchemaCreation } from "src/domain/schema-request"; import { TopicNames, getTopicNames } from "src/domain/topic"; @@ -86,8 +86,8 @@ function TopicSchemaRequest(props: TopicSchemaRequestProps) { Environment[], Error >({ - queryKey: ["schemaRegistryEnvironments"], - queryFn: () => getEnvironmentsForSchemaRequest(), + queryKey: ["getEnvs"], + queryFn: () => getAllEnvironmentsForTopicAndAcl(), onSuccess: (environments) => { if (presetEnvironment) { const validEnv = environments.find( diff --git a/coral/src/app/pages/topics/schema-request.test.tsx b/coral/src/app/pages/topics/schema-request.test.tsx index 806ca15eca..f0381f75df 100644 --- a/coral/src/app/pages/topics/schema-request.test.tsx +++ b/coral/src/app/pages/topics/schema-request.test.tsx @@ -5,7 +5,7 @@ import { getQueryClientForTests } from "src/services/test-utils/query-client-tes import { render } from "@testing-library/react"; import { QueryClientProvider } from "@tanstack/react-query"; import { MemoryRouter, Routes, Route } from "react-router-dom"; -import { getEnvironmentsForSchemaRequest } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { requestSchemaCreation } from "src/domain/schema-request"; import { getTopicNames } from "src/domain/topic"; @@ -13,9 +13,9 @@ jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/topic/topic-api.ts"); -const mockGetSchemaRegistryEnvironments = - getEnvironmentsForSchemaRequest as jest.MockedFunction< - typeof getEnvironmentsForSchemaRequest +const mockGetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockCreateSchemaRequest = requestSchemaCreation as jest.MockedFunction< typeof requestSchemaCreation @@ -29,7 +29,7 @@ describe("SchemaRequest", () => { const topicName = "my-awesome-topic"; beforeAll(() => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([topicName]); // @TODO if we decide to go with this kind of dynamic routes, From e7204165597646ff480566c30d7b54144f6c62a8 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Fri, 6 Oct 2023 14:54:59 +0200 Subject: [PATCH 12/14] Filter getEnvs response for schema request Signed-off-by: Mirjam Aulbach --- .../TopicSchemaRequest.test.tsx | 93 ++++++++++--------- .../schema-request/TopicSchemaRequest.tsx | 5 + 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx index 4fdf045031..1ea2fd5009 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.test.tsx @@ -19,7 +19,7 @@ jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/topic/topic-api.ts"); -const mockgetAllEnvironmentsForTopicAndAcl = +const mockGetAllEnvironmentsForTopicAndAcl = getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< typeof getAllEnvironmentsForTopicAndAcl >; @@ -47,15 +47,17 @@ const useQuerySpy = jest.spyOn(ReactQuery, "useQuery"); const testTopicName = "my-awesome-topic"; const mockedEnvironments = [ - { name: "DEV", id: "1" }, - { name: "TST", id: "2" }, - { name: "INFRA", id: "3" }, + { name: "DEV", id: "1", associatedEnv: { id: "3", name: "DEV_SCH" } }, + { name: "TST", id: "2", associatedEnv: { id: "9", name: "TST_SCH" } }, + { name: "INFRA", id: "3", associatedEnv: { id: "9", name: "INFRA_SCH" } }, + { name: "SOME", id: "3", associatedEnv: undefined }, ]; -const mockedGetSchemaRegistryEnvironments = transformEnvironmentApiResponse( - mockedEnvironments.map((entry) => { - return createMockEnvironmentDTO(entry); - }) -); +const mockedGetAllEnvironmentsForTopicAndAclResponse = + transformEnvironmentApiResponse( + mockedEnvironments.map((entry) => { + return createMockEnvironmentDTO(entry); + }) + ); const fileName = "my-awesome-schema.avsc"; const testFile: File = new File(["{}"], fileName, { @@ -75,8 +77,8 @@ describe("TopicSchemaRequest", () => { describe("checks if topicName passed from url is part of topics user can request schemas for", () => { beforeEach(() => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); }); @@ -145,8 +147,8 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env ID query is part of list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -184,8 +186,8 @@ describe("TopicSchemaRequest", () => { }); it("does not redirect user if env name query is part of list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -223,8 +225,8 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env id query does not exist in list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -244,8 +246,8 @@ describe("TopicSchemaRequest", () => { }); it("redirects user if env name query does not exist in list of environments", async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ - ...mockedGetSchemaRegistryEnvironments, + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([ + ...mockedGetAllEnvironmentsForTopicAndAclResponse, ]); customRender( @@ -270,7 +272,7 @@ describe("TopicSchemaRequest", () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore useQuerySpy.mockReturnValue({ data: [], isLoading: true }); - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -308,8 +310,8 @@ describe("TopicSchemaRequest", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -348,27 +350,34 @@ describe("TopicSchemaRequest", () => { expect(select).toBeRequired(); }); - it("renders all options for Environment based on api data", () => { + it("renders all options for Environment with associated env based on api data", () => { + const environmentsWithAssociatedEnvs = mockedEnvironments.filter( + (env) => env.associatedEnv + ); + const form = getForm(); const select = within(form).getByRole("combobox", { name: /Environment/i, }); const options = within(select).getAllByRole("option"); - expect(options).toHaveLength(mockedEnvironments.length + 1); + expect(options).toHaveLength(environmentsWithAssociatedEnvs.length + 1); }); test.each(mockedEnvironments)( - `renders a option $name with the Environments id set as value $id`, - ({ name, id }) => { - const form = getForm(); - const select = within(form).getByRole("combobox", { - name: /Environment/i, - }); - const option = within(select).getByRole("option", { name: name }); - - expect(option).toBeVisible(); - expect(option).toHaveValue(id); + `renders a option $name with the Environments id set as value $id when Environment has an associated env`, + (environment) => { + if (environment.associatedEnv) { + const { name, id } = environment; + const form = getForm(); + const select = within(form).getByRole("combobox", { + name: /Environment/i, + }); + const option = within(select).getByRole("option", { name: name }); + + expect(option).toBeVisible(); + expect(option).toHaveValue(id); + } } ); @@ -441,8 +450,8 @@ describe("TopicSchemaRequest", () => { describe("shows errors when user does not fill out correctly", () => { beforeEach(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -519,8 +528,8 @@ describe("TopicSchemaRequest", () => { describe("enables user to cancel the form input", () => { beforeEach(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockImplementation(jest.fn()); mockGetTopicNames.mockResolvedValue([testTopicName]); @@ -635,8 +644,8 @@ describe("TopicSchemaRequest", () => { beforeEach(async () => { console.error = jest.fn(); - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockRejectedValue({ status: "400 BAD_REQUEST", @@ -740,8 +749,8 @@ describe("TopicSchemaRequest", () => { describe("enables user to send a schema request", () => { beforeEach(async () => { - mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( - mockedGetSchemaRegistryEnvironments + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( + mockedGetAllEnvironmentsForTopicAndAclResponse ); mockCreateSchemaRequest.mockResolvedValue({ success: true, diff --git a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx index 331703f330..01e0c84c84 100644 --- a/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx +++ b/coral/src/app/features/topics/schema-request/TopicSchemaRequest.tsx @@ -88,6 +88,11 @@ function TopicSchemaRequest(props: TopicSchemaRequestProps) { >({ queryKey: ["getEnvs"], queryFn: () => getAllEnvironmentsForTopicAndAcl(), + // not every Kafka Environment has an associated env for schemas, + // so we only want to show those who do. + // We use name and ID related to the Kafka Environment in form and mutation. + select: (kafkaEnvironments) => + kafkaEnvironments.filter((env) => env.associatedEnv), onSuccess: (environments) => { if (presetEnvironment) { const validEnv = environments.find( From cd8401afad1db1df1ccc200a7b16412ef93f39b0 Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Tue, 10 Oct 2023 16:42:29 +0300 Subject: [PATCH 13/14] Remove api call from environment-api Signed-off-by: Mirjam Aulbach --- coral/src/domain/environment/environment-api.ts | 9 --------- coral/src/domain/environment/index.ts | 2 -- 2 files changed, 11 deletions(-) diff --git a/coral/src/domain/environment/environment-api.ts b/coral/src/domain/environment/environment-api.ts index 63fbee03f2..e744b4755c 100644 --- a/coral/src/domain/environment/environment-api.ts +++ b/coral/src/domain/environment/environment-api.ts @@ -51,14 +51,6 @@ const getEnvironmentsForTopicRequest = async (): Promise => { return transformEnvironmentApiResponse(apiResponse); }; -const getAllEnvironmentsForSchema = async (): Promise => { - const apiResponse = await api.get>( - API_PATHS.getSchemaRegEnvs - ); - - return transformEnvironmentApiResponse(apiResponse); -}; - const getPaginatedEnvironmentsForSchema = async ( params: KlawApiRequestQueryParameters<"getSchemaRegEnvsPaginated"> ): Promise => { @@ -112,7 +104,6 @@ export { getAllEnvironmentsForTopicAndAcl, getPaginatedEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, - getAllEnvironmentsForSchema, getPaginatedEnvironmentsForSchema, getAllEnvironmentsForConnector, getPaginatedEnvironmentsForConnector, diff --git a/coral/src/domain/environment/index.ts b/coral/src/domain/environment/index.ts index 84801895e8..d9bd1bcece 100644 --- a/coral/src/domain/environment/index.ts +++ b/coral/src/domain/environment/index.ts @@ -1,6 +1,5 @@ import { getAllEnvironmentsForConnector, - getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, @@ -18,7 +17,6 @@ import { export { ALL_ENVIRONMENTS_VALUE, getAllEnvironmentsForConnector, - getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, From 66707b23f13a7b3142f751a7060931400ad06e9c Mon Sep 17 00:00:00 2001 From: Mirjam Aulbach Date: Tue, 10 Oct 2023 17:02:04 +0300 Subject: [PATCH 14/14] Update EnvironmentFilter and components using it. Signed-off-by: Mirjam Aulbach --- .../features/approvals/acls/AclApprovals.tsx | 2 +- .../connectors/ConnectorApprovals.tsx | 2 +- .../schemas/SchemaApprovals.test.tsx | 43 +++--- .../approvals/schemas/SchemaApprovals.tsx | 5 +- .../approvals/topics/TopicApprovals.tsx | 2 +- .../filters/EnvironmentFilter.test.tsx | 145 +++++++++++++----- .../components/filters/EnvironmentFilter.tsx | 59 +++++-- .../connectors/browse/BrowseConnectors.tsx | 5 +- .../features/requests/acls/AclRequests.tsx | 2 +- .../requests/connectors/ConnectorRequests.tsx | 5 +- .../requests/schemas/SchemaRequests.test.tsx | 40 +++-- .../requests/schemas/SchemaRequests.tsx | 5 +- .../schemas/utils/mocked-api-responses.ts | 5 +- .../requests/topics/TopicRequests.tsx | 2 +- .../features/topics/browse/BrowseTopics.tsx | 2 +- .../app/pages/requests/schemas/index.test.tsx | 10 +- 16 files changed, 221 insertions(+), 113 deletions(-) diff --git a/coral/src/app/features/approvals/acls/AclApprovals.tsx b/coral/src/app/features/approvals/acls/AclApprovals.tsx index 81c3f4d13f..3445080a71 100644 --- a/coral/src/app/features/approvals/acls/AclApprovals.tsx +++ b/coral/src/app/features/approvals/acls/AclApprovals.tsx @@ -240,7 +240,7 @@ function AclApprovals() { filters={[ , , , diff --git a/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx b/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx index 76df66da94..0a6bf10fad 100644 --- a/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx +++ b/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx @@ -264,7 +264,7 @@ function ConnectorApprovals() { filters={[ , , , diff --git a/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx b/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx index 23a3ae58e3..cd4d537095 100644 --- a/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx +++ b/coral/src/app/features/approvals/schemas/SchemaApprovals.test.tsx @@ -2,7 +2,7 @@ import { cleanup, screen, waitFor, within } from "@testing-library/react"; import { waitForElementToBeRemoved } from "@testing-library/react/pure"; import userEvent from "@testing-library/user-event"; import SchemaApprovals from "src/app/features/approvals/schemas/SchemaApprovals"; -import { getAllEnvironmentsForSchema } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { createMockEnvironmentDTO } from "src/domain/environment/environment-test-helper"; import { transformEnvironmentApiResponse } from "src/domain/environment/environment-transformer"; import { @@ -19,9 +19,9 @@ import { customRender } from "src/services/test-utils/render-with-wrappers"; jest.mock("src/domain/schema-request/schema-request-api.ts"); jest.mock("src/domain/environment/environment-api.ts"); -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema +const mockGetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockGetSchemaRequestsForApprover = @@ -37,8 +37,9 @@ const mockApproveSchemaRequest = approveSchemaRequest as jest.MockedFunction< >; const mockedEnvironments = [ - { name: "DEV", id: "1" }, - { name: "TST", id: "2" }, + { name: "DEV", id: "1", associatedEnv: { name: "DEV_SCH", id: "111" } }, + { name: "TST", id: "2", associatedEnv: { name: "TST_SCH", id: "222" } }, + { name: "RANDOM", id: "3" }, ]; const mockedEnvironmentResponse = transformEnvironmentApiResponse([ @@ -133,7 +134,7 @@ describe("SchemaApprovals", () => { totalPages: 1, currentPage: 1, }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); }); afterEach(() => { @@ -177,7 +178,7 @@ describe("SchemaApprovals", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -239,7 +240,7 @@ describe("SchemaApprovals", () => { totalPages: 1, currentPage: 1, }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); }); afterEach(() => { @@ -345,7 +346,7 @@ describe("SchemaApprovals", () => { entries: [], }); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); customRender(, { queryClient: true, @@ -386,7 +387,7 @@ describe("SchemaApprovals", () => { describe("shows a detail modal for schema request", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -506,7 +507,7 @@ describe("SchemaApprovals", () => { describe("handles filtering entries in the table", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue({ @@ -577,13 +578,19 @@ describe("SchemaApprovals", () => { name: "Filter by Environment", }); const environmentOption = screen.getByRole("option", { - name: mockedEnvironments[0].name, + // we're defining the test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + name: mockedEnvironments[0].associatedEnv.name, }); await userEvent.selectOptions(environmentFilter, environmentOption); expect(mockGetSchemaRequestsForApprover).toHaveBeenNthCalledWith(2, { ...defaultApiParams, - env: mockedEnvironments[0].id, + // we're defining the test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + env: mockedEnvironments[0].associatedEnv.id, }); }); @@ -614,7 +621,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -712,7 +719,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -837,7 +844,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( @@ -1007,7 +1014,7 @@ describe("SchemaApprovals", () => { console.error = jest.fn(); console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequestsForApprover.mockResolvedValue( diff --git a/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx b/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx index 3e0f37cb79..5db6d53cf3 100644 --- a/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx +++ b/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx @@ -261,10 +261,7 @@ function SchemaApprovals() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/approvals/topics/TopicApprovals.tsx b/coral/src/app/features/approvals/topics/TopicApprovals.tsx index 9be2dd0bf3..52bca393d8 100644 --- a/coral/src/app/features/approvals/topics/TopicApprovals.tsx +++ b/coral/src/app/features/approvals/topics/TopicApprovals.tsx @@ -284,7 +284,7 @@ function TopicApprovals() { filters={[ , , , diff --git a/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx b/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx index 1dc03380e1..a4a54b4127 100644 --- a/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx +++ b/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx @@ -5,7 +5,6 @@ import EnvironmentFilter from "src/app/features/components/filters/EnvironmentFi import { withFiltersContext } from "src/app/features/components/filters/useFiltersContext"; import { getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema, getAllEnvironmentsForConnector, } from "src/domain/environment"; import { createEnvironment } from "src/domain/environment/environment-test-helper"; @@ -18,11 +17,6 @@ const mockGetEnvironments = typeof getAllEnvironmentsForTopicAndAcl >; -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema - >; - const mockGetSyncConnectorsEnvironments = getAllEnvironmentsForConnector as jest.MockedFunction< typeof getAllEnvironmentsForConnector @@ -42,18 +36,13 @@ const mockEnvironments = [ const filterLabel = "Filter by Environment"; const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); describe("EnvironmentFilter.tsx", () => { - describe("uses a given endpoint to fetch environments", () => { + describe("uses different endpoint to fetch environments dependent on props", () => { beforeEach(() => { mockGetEnvironments.mockResolvedValue([]); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); }); afterEach(() => { @@ -61,42 +50,35 @@ describe("EnvironmentFilter.tsx", () => { jest.resetAllMocks(); }); - it("fetches from the getAllEnvironmentsForTopicAndAcl endpoint", () => { + it("fetches environments for 'TOPIC_AND_ACL'", () => { + const WrappedEnvironmentFilter = withFiltersContext({ + element: , + }); customRender(, { memoryRouter: true, queryClient: true, }); expect(mockGetEnvironments).toHaveBeenCalled(); - expect(mockGetSchemaRegistryEnvironments).not.toHaveBeenCalled(); expect(mockGetSyncConnectorsEnvironments).not.toHaveBeenCalled(); }); - it("fetches from the getAllEnvironmentsForSchema endpoint", () => { + it("fetches environments for 'SCHEMA'", () => { const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); customRender(, { memoryRouter: true, queryClient: true, }); - expect(mockGetSchemaRegistryEnvironments).toHaveBeenCalled(); - expect(mockGetEnvironments).not.toHaveBeenCalled(); + expect(mockGetEnvironments).toHaveBeenCalled(); expect(mockGetSyncConnectorsEnvironments).not.toHaveBeenCalled(); }); - it("fetches from the getAllEnvironmentsForConnector endpoint", () => { + it("fetches environments for 'CONNECTOR'", () => { const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); customRender(, { memoryRouter: true, @@ -105,14 +87,12 @@ describe("EnvironmentFilter.tsx", () => { expect(mockGetSyncConnectorsEnvironments).toHaveBeenCalled(); expect(mockGetEnvironments).not.toHaveBeenCalled(); - expect(mockGetSchemaRegistryEnvironments).not.toHaveBeenCalled(); }); }); - describe("renders all necessary elements", () => { + describe("renders all necessary elements for 'TOPIC_AND_ACL' (same as 'CONNECTOR')", () => { beforeAll(async () => { mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { @@ -158,6 +138,104 @@ describe("EnvironmentFilter.tsx", () => { }); }); + describe("renders all necessary elements for 'SCHEMA'", () => { + const associatedEnvDev = { + id: "111", + name: "DEV_SCH", + }; + + const associatedEnvTst = { + id: "222", + name: "TST_SCH", + }; + + const mockEnvironmentsSchema = [ + createEnvironment({ + name: "DEV", + id: "1", + associatedEnv: associatedEnvDev, + }), + createEnvironment({ + name: "TST", + id: "2", + associatedEnv: associatedEnvTst, + }), + + createEnvironment({ + name: "DIV", + id: "3", + }), + ]; + + beforeAll(async () => { + mockGetEnvironments.mockResolvedValue(mockEnvironmentsSchema); + mockGetSyncConnectorsEnvironments.mockResolvedValue([]); + + const WrappedEnvironmentFilter = withFiltersContext({ + element: , + }); + + customRender(, { + memoryRouter: true, + queryClient: true, + }); + await waitForElementToBeRemoved( + screen.getByTestId("select-environment-loading") + ); + }); + + afterAll(() => { + cleanup(); + jest.resetAllMocks(); + }); + + it("shows a select element for Kafka Environments", () => { + const select = screen.getByRole("combobox", { + name: filterLabel, + }); + + expect(select).toBeEnabled(); + }); + + it("renders a list of options for environments with associated envs plus a option for `All Environments`", () => { + const filteredEnvs = mockEnvironmentsSchema.filter( + (env) => env.associatedEnv + ); + + filteredEnvs.forEach((environment) => { + const option = screen.getByRole("option", { + // associated env is not undefined in this test, + // no need for warning + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + name: environment.associatedEnv.name, + }); + + expect(option).toBeEnabled(); + }); + + expect(screen.getAllByRole("option")).toHaveLength( + filteredEnvs.length + 1 + ); + }); + + it("shows `All Environments` as the active option one", () => { + const option = screen.getByRole("option", { + selected: true, + }); + expect(option).toHaveAccessibleName("All Environments"); + }); + + it("shows the name of the associated env as option", () => { + const option = screen.getByRole("option", { + name: associatedEnvDev.name, + }); + + expect(option).toHaveAccessibleName(associatedEnvDev.name); + expect(option).toHaveValue(associatedEnvDev.id); + }); + }); + describe("sets the active environment based on a query param", () => { const mockedQueryParamDev = mockEnvironments[0].id; @@ -165,7 +243,6 @@ describe("EnvironmentFilter.tsx", () => { const routePath = `/?environment=${mockedQueryParamDev}`; mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { @@ -196,7 +273,6 @@ describe("EnvironmentFilter.tsx", () => { describe("handles user selecting a environment", () => { beforeEach(async () => { mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { @@ -230,7 +306,6 @@ describe("EnvironmentFilter.tsx", () => { describe("updates the search param to preserve environment in url", () => { beforeEach(async () => { mockGetEnvironments.mockResolvedValue(mockEnvironments); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); customRender(, { diff --git a/coral/src/app/features/components/filters/EnvironmentFilter.tsx b/coral/src/app/features/components/filters/EnvironmentFilter.tsx index dea4e9b757..c57668ca6e 100644 --- a/coral/src/app/features/components/filters/EnvironmentFilter.tsx +++ b/coral/src/app/features/components/filters/EnvironmentFilter.tsx @@ -4,35 +4,66 @@ import { useFiltersContext } from "src/app/features/components/filters/useFilter import { Environment, getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema, getAllEnvironmentsForConnector, } from "src/domain/environment"; import { HTTPError } from "src/services/api"; -type EnvironmentEndpoint = - | "getAllEnvironmentsForTopicAndAcl" - | "getAllEnvironmentsForSchema" - | "getAllEnvironmentsForConnector"; +type EnvironmentFor = "TOPIC_AND_ACL" | "SCHEMA" | "CONNECTOR"; interface EnvironmentFilterProps { - isSchemaRegistryEnvironments?: boolean; - environmentEndpoint: EnvironmentEndpoint; + environmentsFor: EnvironmentFor; } const environmentEndpointMap: { - [key in EnvironmentEndpoint]: () => Promise; + [key in EnvironmentFor]: { + apiEndpoint: () => Promise; + // we use the api function name as query usually, so we + // want to keep that pattern here, too. + queryFn: string; + }; } = { - getAllEnvironmentsForTopicAndAcl: getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema: getAllEnvironmentsForSchema, - getAllEnvironmentsForConnector: getAllEnvironmentsForConnector, + TOPIC_AND_ACL: { + apiEndpoint: getAllEnvironmentsForTopicAndAcl, + queryFn: "getAllEnvironmentsForTopicAndAcl", + }, + SCHEMA: { + apiEndpoint: getAllEnvironmentsForTopicAndAcl, + queryFn: "getAllEnvironmentsForTopicAndAcl", + }, + CONNECTOR: { + apiEndpoint: getAllEnvironmentsForConnector, + queryFn: "getAllEnvironmentsForConnector", + }, }; -function EnvironmentFilter({ environmentEndpoint }: EnvironmentFilterProps) { +function filterEnvironmentsForSchema( + environments: Environment[] +): Environment[] { + return environments + .map((env) => { + if (env.associatedEnv) { + return { + ...env, + id: env.associatedEnv.id, + name: env.associatedEnv.name, + }; + } + }) + .filter((entry) => entry !== undefined) as Environment[]; +} + +function EnvironmentFilter({ environmentsFor }: EnvironmentFilterProps) { const { environment, setFilterValue } = useFiltersContext(); const { data: environments } = useQuery( - [environmentEndpoint], + [environmentEndpointMap[environmentsFor].queryFn], { - queryFn: environmentEndpointMap[environmentEndpoint], + queryFn: environmentEndpointMap[environmentsFor].apiEndpoint, + select: (environments) => { + if (environmentsFor === "SCHEMA") { + return filterEnvironmentsForSchema(environments); + } + return environments; + }, } ); diff --git a/coral/src/app/features/connectors/browse/BrowseConnectors.tsx b/coral/src/app/features/connectors/browse/BrowseConnectors.tsx index 2fa6f14396..11d71cec07 100644 --- a/coral/src/app/features/connectors/browse/BrowseConnectors.tsx +++ b/coral/src/app/features/connectors/browse/BrowseConnectors.tsx @@ -54,10 +54,7 @@ function BrowseConnectors() { , - , + , , ]} table={ diff --git a/coral/src/app/features/requests/acls/AclRequests.tsx b/coral/src/app/features/requests/acls/AclRequests.tsx index 17d179875f..2eb67c7b87 100644 --- a/coral/src/app/features/requests/acls/AclRequests.tsx +++ b/coral/src/app/features/requests/acls/AclRequests.tsx @@ -170,7 +170,7 @@ function AclRequests() { filters={[ , , , diff --git a/coral/src/app/features/requests/connectors/ConnectorRequests.tsx b/coral/src/app/features/requests/connectors/ConnectorRequests.tsx index 26a5b1da4d..77dd4d6bcc 100644 --- a/coral/src/app/features/requests/connectors/ConnectorRequests.tsx +++ b/coral/src/app/features/requests/connectors/ConnectorRequests.tsx @@ -150,10 +150,7 @@ function ConnectorRequests() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx b/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx index 5c524cfe51..b2b22bc6bf 100644 --- a/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx +++ b/coral/src/app/features/requests/schemas/SchemaRequests.test.tsx @@ -17,16 +17,16 @@ import { mockedEnvironmentResponse, } from "src/app/features/requests/schemas/utils/mocked-api-responses"; import userEvent from "@testing-library/user-event"; -import { getAllEnvironmentsForSchema } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; import { requestStatusNameMap } from "src/app/features/approvals/utils/request-status-helper"; import { requestOperationTypeNameMap } from "src/app/features/approvals/utils/request-operation-type-helper"; jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/schema-request/schema-request-api.ts"); -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema +const mockgetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockGetSchemaRequests = getSchemaRequests as jest.MockedFunction< @@ -60,7 +60,7 @@ describe("SchemaRequest", () => { // while making sure to not swallow other console.errors console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue({ @@ -111,7 +111,7 @@ describe("SchemaRequest", () => { describe("renders all necessary elements", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -184,7 +184,7 @@ describe("SchemaRequest", () => { describe("renders pagination dependent on response", () => { beforeEach(() => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue({ @@ -290,7 +290,7 @@ describe("SchemaRequest", () => { describe("handles user stepping through pagination", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue({ @@ -338,7 +338,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by 'environment'", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -371,20 +371,26 @@ describe("SchemaRequest", () => { }); const environmentOption = screen.getByRole("option", { - name: mockedEnvironmentResponse[0].name, + // we created test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + name: mockedEnvironmentResponse[0].associatedEnv.name, }); await userEvent.selectOptions(environmentFilter, environmentOption); expect(mockGetSchemaRequests).toHaveBeenNthCalledWith(2, { ...defaultApiParams, - env: mockedEnvironmentResponse[0].id, + // we created test data, so it is not undefined + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + env: mockedEnvironmentResponse[0].associatedEnv.id, }); }); }); describe("user can filter schema requests by 'Request type'", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -431,7 +437,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by 'status'", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -478,7 +484,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by 'topic' they searched for", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -523,7 +529,7 @@ describe("SchemaRequest", () => { describe("user can filter schema requests by only showing their own requests", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -568,7 +574,7 @@ describe("SchemaRequest", () => { describe("shows a detail modal for schema request", () => { beforeEach(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); @@ -664,7 +670,7 @@ describe("SchemaRequest", () => { const originalConsoleError = console.error; beforeEach(async () => { console.error = jest.fn(); - mockGetSchemaRegistryEnvironments.mockResolvedValue( + mockgetAllEnvironmentsForTopicAndAcl.mockResolvedValue( mockedEnvironmentResponse ); mockGetSchemaRequests.mockResolvedValue(mockedApiResponseSchemaRequests); diff --git a/coral/src/app/features/requests/schemas/SchemaRequests.tsx b/coral/src/app/features/requests/schemas/SchemaRequests.tsx index a7623bdf5b..bc47860c1c 100644 --- a/coral/src/app/features/requests/schemas/SchemaRequests.tsx +++ b/coral/src/app/features/requests/schemas/SchemaRequests.tsx @@ -160,10 +160,7 @@ function SchemaRequests() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts b/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts index 1ce252364c..8ac4312f33 100644 --- a/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts +++ b/coral/src/app/features/requests/schemas/utils/mocked-api-responses.ts @@ -89,8 +89,9 @@ const mockedApiResponseSchemaRequests: SchemaRequestApiResponse = transformGetSchemaRequests(mockedApiResponses); const mockedEnvironments = [ - { name: "DEV", id: "1" }, - { name: "TST", id: "2" }, + { name: "DEV", id: "1", associatedEnv: { name: "DEV_SCH", id: "111" } }, + { name: "TST", id: "2", associatedEnv: { name: "TST_SCH", id: "222" } }, + { name: "RANDOM", id: "2" }, ]; const mockedEnvironmentResponse = transformEnvironmentApiResponse([ diff --git a/coral/src/app/features/requests/topics/TopicRequests.tsx b/coral/src/app/features/requests/topics/TopicRequests.tsx index 0a95f67073..9ffdab0188 100644 --- a/coral/src/app/features/requests/topics/TopicRequests.tsx +++ b/coral/src/app/features/requests/topics/TopicRequests.tsx @@ -152,7 +152,7 @@ function TopicRequests() { filters={[ , , , diff --git a/coral/src/app/features/topics/browse/BrowseTopics.tsx b/coral/src/app/features/topics/browse/BrowseTopics.tsx index 0bea56788d..7a873ae48e 100644 --- a/coral/src/app/features/topics/browse/BrowseTopics.tsx +++ b/coral/src/app/features/topics/browse/BrowseTopics.tsx @@ -57,7 +57,7 @@ function BrowseTopics() { , , , ]} diff --git a/coral/src/app/pages/requests/schemas/index.test.tsx b/coral/src/app/pages/requests/schemas/index.test.tsx index 92a013574d..8f3ce1da7d 100644 --- a/coral/src/app/pages/requests/schemas/index.test.tsx +++ b/coral/src/app/pages/requests/schemas/index.test.tsx @@ -3,14 +3,14 @@ import { customRender } from "src/services/test-utils/render-with-wrappers"; import SchemaRequestsPage from "src/app/pages/requests/schemas/index"; import { cleanup, screen, within } from "@testing-library/react"; import { waitForElementToBeRemoved } from "@testing-library/react/pure"; -import { getAllEnvironmentsForSchema } from "src/domain/environment"; +import { getAllEnvironmentsForTopicAndAcl } from "src/domain/environment"; jest.mock("src/domain/environment/environment-api.ts"); jest.mock("src/domain/schema-request/schema-request-api.ts"); -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema +const mockGetAllEnvironmentsForTopicAndAcl = + getAllEnvironmentsForTopicAndAcl as jest.MockedFunction< + typeof getAllEnvironmentsForTopicAndAcl >; const mockGetSchemaRequests = getSchemaRequests as jest.MockedFunction< typeof getSchemaRequests @@ -18,7 +18,7 @@ const mockGetSchemaRequests = getSchemaRequests as jest.MockedFunction< describe("SchemaRequestPage", () => { beforeAll(async () => { - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); + mockGetAllEnvironmentsForTopicAndAcl.mockResolvedValue([]); mockGetSchemaRequests.mockResolvedValue({ entries: [], totalPages: 1,