Skip to content

Commit

Permalink
feat: getProductRoleMappings by institutionType
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Oct 8, 2024
1 parent 61fffbb commit e8bbdc4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,15 @@
"schema" : {
"type" : "string"
}
}, {
"name" : "institutionType",
"in" : "query",
"description" : "Institution's type",
"required" : false,
"style" : "form",
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
Expand Down
2 changes: 1 addition & 1 deletion connector-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.3.0</version>
<version>0.3.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ void GetProducts() throws IOException {
@Test
void getProductRoleMappingsWithoutProductId() {

Assertions.assertThrows(IllegalArgumentException.class, () -> productConnectorImpl.getProductRoleMappings(null));
Assertions.assertThrows(IllegalArgumentException.class, () -> productConnectorImpl.getProductRoleMappings(null, null));
verify(productServiceMock, never()).getProduct(null);
}

@Test
void getProductRoleMappingsWithEmptyProduct() {

String productId = "123";
String institutionType = "type";
when(productServiceMock.getProduct(productId)).thenReturn(null);
Map<PartyRole, ProductRoleInfo> result = productConnectorImpl.getProductRoleMappings(productId);
Map<PartyRole, ProductRoleInfo> result = productConnectorImpl.getProductRoleMappings(productId, institutionType);
assertNull(result);
Mockito.verify(productServiceMock, times(1)).getProduct(productId);
}
Expand All @@ -121,15 +122,16 @@ void getProductRoleMappingsWithEmptyProduct() {
void testGetProductRoleMappings() throws IOException {

String productId = "123";
String institutionType = "type";

ClassPathResource resource = new ClassPathResource("stubs/Product.json");
byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath());
Product product = objectMapper.readValue(resourceStream, new TypeReference<>() {
});

when(productServiceMock.getProduct(productId)).thenReturn(product);
Map<PartyRole, ProductRoleInfo> result = productConnectorImpl.getProductRoleMappings(productId);
Assertions.assertEquals(product.getRoleMappings(), result);
Map<PartyRole, ProductRoleInfo> result = productConnectorImpl.getProductRoleMappings(productId, institutionType);
Assertions.assertEquals(product.getRoleMappings(institutionType), result);
Mockito.verify(productServiceMock, times(1)).getProduct(productId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Map<PartyRole, ProductRoleInfo> getProductRoles(String productId, String
log.debug("getProductRoles productId = {}, institutionType = {}", productId, institutionType);

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
Assert.hasText(productId, "A Product id is required");

Map<PartyRole, ProductRoleInfo> productRoleMappings = productsConnector.getProductRoleMappings(productId);
Map<PartyRole, ProductRoleInfo> productRoleMappings = productsConnector.getProductRoleMappings(productId, institutionType);
log.debug("getProductRoles result = {}", productRoleMappings);
log.trace("getProductRoles end");
return productRoleMappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ private List<CreateUserDto.Role> retrieveRole(String productId, Set<String> prod

CreateUserDto.Role role = new CreateUserDto.Role();
role.setProductRole(productRole);
role.setLabel(ProductMapper.getLabel(productRole, product.getRoleMappings()).orElse(null));

List<PartyRole> partyRoles = ProductUtils.validRolesByProductRole(product, PHASE_ADDITION_ALLOWED.DASHBOARD, productRole);
//TODO https://pagopa.atlassian.net/browse/SELC-5706 for institutionType=null
role.setLabel(ProductMapper.getLabel(productRole, product.getRoleMappings(null)).orElse(null));

List<PartyRole> partyRoles = ProductUtils.validRolesByProductRole(product, PHASE_ADDITION_ALLOWED.DASHBOARD, productRole, null);
if(Objects.isNull(partyRoles) || partyRoles.isEmpty()){
throw new InvalidProductRoleException(String.format("Product role '%s' is not valid", productRole));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ public void setUp() {
void getProductRoles() {

String productId = "productId";
String institutionType = "type";
Map<PartyRole, ProductRoleInfo> productRoleMappingsMock = new HashMap<>();
ProductRoleInfo productRoleInfo = new ProductRoleInfo();
productRoleMappingsMock.put(PartyRole.MANAGER, productRoleInfo);

when(productsConnectorMock.getProductRoleMappings(productId)).thenReturn(productRoleMappingsMock);
when(productsConnectorMock.getProductRoleMappings(productId, institutionType)).thenReturn(productRoleMappingsMock);

Map<PartyRole, ProductRoleInfo> result = productService.getProductRoles(productId);
Map<PartyRole, ProductRoleInfo> result = productService.getProductRoles(productId, institutionType);
Assertions.assertEquals(productRoleMappingsMock, result);
Mockito.verify(productsConnectorMock, Mockito.times(1)).getProductRoleMappings(productId);
Mockito.verify(productsConnectorMock, Mockito.times(1)).getProductRoleMappings(productId, institutionType);
}

@Test
void getProductRolesWithoutProductId() {

Assertions.assertThrows(IllegalArgumentException.class, () -> productService.getProductRoles(null));
Assertions.assertThrows(IllegalArgumentException.class, () -> productService.getProductRoles(null, null));
Mockito.verifyNoInteractions(productsConnectorMock);
}

Expand Down
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>it.pagopa.selfcare</groupId>
<artifactId>onboarding-sdk-product</artifactId>
<version>0.3.0</version>
<version>0.3.2</version>
<scope>compile</scope>
</dependency>

Expand Down

0 comments on commit e8bbdc4

Please sign in to comment.