Skip to content

Commit

Permalink
[SELC-4644] fix: setting productRole when creating an user (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Apr 15, 2024
1 parent 87923a8 commit 74a2b05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private List<CreateUserDto.Role> retrieveRole(String productId, Set<String> prod
return productRoles.stream().map(productRole -> {
EnumMap<PartyRole, ProductRoleInfo> roleMappings = product.getRoleMappings();
CreateUserDto.Role role = new CreateUserDto.Role();
role.setProductRole(productRole);
role.setLabel(Product.getLabel(productRole, roleMappings).orElse(null));
Optional<PartyRole> partyRole = Product.getPartyRole(productRole, roleMappings, PARTY_ROLE_WHITE_LIST);
role.setPartyRole(partyRole.orElseThrow(() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
Expand Down Expand Up @@ -294,9 +295,10 @@ void createUsersByFiscalCode() {
// given
final String institutionId = "institutionId";
final String productId = "productId";
final String productRole = "operator";
UserToCreate userToCreate = new UserToCreate();
HashSet<String> productRoles = new HashSet<>();
productRoles.add("operator");
productRoles.add(productRole);
userToCreate.setProductRoles(productRoles);

Product product = getProduct();
Expand All @@ -318,8 +320,10 @@ void createUsersByFiscalCode() {

// then
assertNotNull(userId);
ArgumentCaptor<List<CreateUserDto.Role>> captorRoles = ArgumentCaptor.forClass(List.class);
verify(userApiConnector, times(1))
.createOrUpdateUserByFiscalCode(eq(institutionId), eq(productId), eq(userToCreate), anyList());
.createOrUpdateUserByFiscalCode(eq(institutionId), eq(productId), eq(userToCreate), captorRoles.capture());
assertEquals(captorRoles.getValue().get(0).getProductRole(), productRole);
verifyNoMoreInteractions(userApiConnector);
}

Expand Down

0 comments on commit 74a2b05

Please sign in to comment.