Skip to content

Commit

Permalink
[SELC-4835] hotfix: Added productRole param in suspend, activate and …
Browse files Browse the repository at this point in the history
…delete user product (#431)
  • Loading branch information
flaminiaScarciofolo authored May 9, 2024
1 parent b65324d commit 3ebc8ad
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public interface UserApiConnector {

User searchByFiscalCode(String fiscalCode, String institutionId);

void suspendUserProduct(String userId, String institutionId, String productId);
void suspendUserProduct(String userId, String institutionId, String productId, String productRole);

void activateUserProduct(String userId, String institutionId, String productId);
void activateUserProduct(String userId, String institutionId, String productId, String productRole);

void deleteUserProduct(String userId, String institutionId, String productId);
void deleteUserProduct(String userId, String institutionId, String productId, String productRole);

UserInstitution getProducts(String institutionId, String userId);

Expand Down
7 changes: 7 additions & 0 deletions connector/rest/docs/openapi/selfcare-user-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@
"schema" : {
"type" : "string"
}
},{
"name" : "productRole",
"in" : "query",
"required" : false,
"schema" : {
"type" : "string"
}
}, {
"name" : "status",
"in" : "query",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,26 @@ public User searchByFiscalCode(String fiscalCode, String institutionId) {
}

@Override
public void suspendUserProduct(String userId, String institutionId, String productId) {
public void suspendUserProduct(String userId, String institutionId, String productId, String productRole) {
log.trace("suspend start");
log.debug("suspend userId = {}, institutionId = {}", userId, institutionId);
userApiRestClient._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.SUSPENDED);
userApiRestClient._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.SUSPENDED, productRole);
log.trace("suspend end");
}

@Override
public void activateUserProduct(String userId, String institutionId, String productId) {
public void activateUserProduct(String userId, String institutionId, String productId, String productRole) {
log.trace("activate start");
log.debug("activate userId = {}, institutionId = {}", userId, institutionId);
userApiRestClient._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.ACTIVE);
userApiRestClient._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.ACTIVE, productRole);
log.trace("activate end");
}

@Override
public void deleteUserProduct(String userId, String institutionId, String productId) {
public void deleteUserProduct(String userId, String institutionId, String productId, String productRole) {
log.trace("delete start");
log.debug("delete userId = {}, institutionId = {}", userId, institutionId);
userApiRestClient._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.DELETED);
userApiRestClient._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.DELETED, productRole);
log.trace("delete end");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ void suspend() {
String userId = "userId";
String institutionId = "id1";
String productId = "prod-pagopa";
String productRole = "admin";
// when
userConnector.suspendUserProduct(userId, institutionId, productId);
userConnector.suspendUserProduct(userId, institutionId, productId, productRole);
// then
verify(userApiRestClient, times(1))
._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.SUSPENDED);
._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.SUSPENDED, productRole);
verifyNoMoreInteractions(userApiRestClient);
}

Expand All @@ -140,11 +141,13 @@ void activate() {
String userId = "userId";
String institutionId = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
userConnector.activateUserProduct(userId, institutionId, productId);
userConnector.activateUserProduct(userId, institutionId, productId, productRole);
// then
verify(userApiRestClient, times(1))
._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.ACTIVE);
._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.ACTIVE, productRole);
verifyNoMoreInteractions(userApiRestClient);
}

Expand All @@ -155,11 +158,13 @@ void delete() {
String userId = "userId";
String institutionId = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
userConnector.deleteUserProduct(userId, institutionId, productId);
userConnector.deleteUserProduct(userId, institutionId, productId, productRole);
// then
verify(userApiRestClient, times(1))
._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.DELETED);
._usersIdInstitutionInstitutionIdProductProductIdStatusPut(userId, institutionId, productId, OnboardedProductState.DELETED, productRole);
verifyNoMoreInteractions(userApiRestClient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public interface UserV2Service {

Collection<InstitutionBase> getInstitutions(String userId);

void deleteUserProduct(String userId, String institutionId, String productId);
void deleteUserProduct(String userId, String institutionId, String productId, String productRole);

void activateUserProduct(String userId, String institutionId, String productId);
void activateUserProduct(String userId, String institutionId, String productId, String productRole);

void suspendUserProduct(String userId, String institutionId, String productId);
void suspendUserProduct(String userId, String institutionId, String productId, String productRole);

User getUserById(String userId, String institutionId, List<String> fields);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ public Collection<InstitutionBase> getInstitutions(String userId) {
}

@Override
public void deleteUserProduct(String userId, String institutionId, String productId) {
public void deleteUserProduct(String userId, String institutionId, String productId, String productRole) {
log.trace("delete start");
log.debug("delete userId = {} for institutionId = {} and product = {}", userId, institutionId, productId);
userApiConnector.deleteUserProduct(userId, institutionId, productId);
log.debug("delete userId = {} for institutionId = {}, productId = {} and productRole = {}", userId, institutionId, productId, productRole);
userApiConnector.deleteUserProduct(userId, institutionId, productId, productRole);
userGroupService.deleteMembersByUserId(userId, institutionId, productId);
log.trace("delete end");
}

@Override
public void activateUserProduct(String userId, String institutionId, String productId) {
public void activateUserProduct(String userId, String institutionId, String productId, String productRole) {
log.trace("activate start");
log.debug("activate userId = {} for institutionId = {} and product = {}", userId, institutionId, productId);
userApiConnector.activateUserProduct(userId, institutionId, productId);
log.debug("activate userId = {} for institutionId = {}, productId = {} and productRole = {}", userId, institutionId, productId, productRole);
userApiConnector.activateUserProduct(userId, institutionId, productId, productRole);
log.trace("activate end");

}

@Override
public void suspendUserProduct(String userId, String institutionId, String productId) {
public void suspendUserProduct(String userId, String institutionId, String productId, String productRole) {
log.trace("suspend start");
log.debug("suspend userId = {} for institutionId = {} and product = {}", userId, institutionId, productId);
userApiConnector.suspendUserProduct(userId, institutionId, productId);
userApiConnector.suspendUserProduct(userId, institutionId, productId, productRole);
log.trace("suspend end");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ void suspend() {
String userId = "rel1";
String institutionid = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
userService.suspendUserProduct(userId, institutionid, productId);
userService.suspendUserProduct(userId, institutionid, productId, productRole);
Mockito.verify(userApiConnector, Mockito.times(1))
.suspendUserProduct(userId, institutionid, productId);
.suspendUserProduct(userId, institutionid, productId, productRole);
Mockito.verifyNoMoreInteractions(userApiConnector);
}

Expand All @@ -89,11 +91,13 @@ void activate() {
String userId = "rel1";
String institutionid = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
userService.activateUserProduct(userId, institutionid, productId);
userService.activateUserProduct(userId, institutionid, productId, productRole);
// then
Mockito.verify(userApiConnector, Mockito.times(1))
.activateUserProduct(userId, institutionid, productId);
.activateUserProduct(userId, institutionid, productId, productRole);
Mockito.verifyNoMoreInteractions(userApiConnector);
}

Expand All @@ -103,11 +107,13 @@ void delete() {
String userId = "rel1";
String institutionid = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

//when
userService.deleteUserProduct(userId, institutionid, productId);
userService.deleteUserProduct(userId, institutionid, productId, productRole);
//then
Mockito.verify(userApiConnector, Mockito.times(1))
.deleteUserProduct(userId, institutionid, productId);
.deleteUserProduct(userId, institutionid, productId, productRole);
Mockito.verify(userGroupService, Mockito.times(1))
.deleteMembersByUserId(userId, institutionid, productId);
Mockito.verifyNoMoreInteractions(userApiConnector, userGroupService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ public void suspendRelationship(@ApiParam("${swagger.dashboard.user.model.id}")
@PathVariable("userId") String userId,
@ApiParam("${swagger.dashboard.support.model.institutionId}")
@RequestParam(value = "institutionId") String institutionId,
@RequestParam(value = "productId") String productId) {
@RequestParam(value = "productId") String productId,
@RequestParam(value = "productRole", required = false) String productRole) {

log.trace("suspendUser start");
log.debug("suspendUser {} for institution: {} and product: {}", userId, institutionId, productId);
userService.suspendUserProduct(userId, institutionId, productId);
log.debug("suspendUser {} for institution: {}, productId: {} and productRole: {}", userId, institutionId, productId, productRole);
userService.suspendUserProduct(userId, institutionId, productId, productRole);
log.trace("suspendUser end");

}
Expand All @@ -65,11 +66,12 @@ public void suspendRelationship(@ApiParam("${swagger.dashboard.user.model.id}")
public void activateRelationship(@ApiParam("${swagger.dashboard.user.model.id}")
@PathVariable("userId") String userId,
@RequestParam(value = "institutionId") String institutionId,
@RequestParam(value = "productId") String productId) {
@RequestParam(value = "productId") String productId,
@RequestParam(value = "productRole", required = false) String productRole) {

log.trace("activateUser start");
log.debug("activateUser {} for institution: {} and product: {}", userId, institutionId, productId);
userService.activateUserProduct(userId, institutionId, productId);
log.debug("activateUser {} for institution: {}, productId: {} and productRole: {}", userId, institutionId, productId, productRole);
userService.activateUserProduct(userId, institutionId, productId, productRole);
log.trace("activateUser end");

}
Expand All @@ -81,10 +83,11 @@ public void activateRelationship(@ApiParam("${swagger.dashboard.user.model.id}")
public void deleteRelationshipById(@ApiParam("${swagger.dashboard.user.model.id}")
@PathVariable("userId") String userId,
@RequestParam(value = "institutionId") String institutionId,
@RequestParam(value = "productId") String productId) {
@RequestParam(value = "productId") String productId,
@RequestParam(value = "productRole", required = false) String productRole) {
log.trace("deleteUser start");
log.debug("deleteUser {} for institution: {} and product: {}", userId, institutionId, productId);
userService.deleteUserProduct(userId, institutionId, productId);
log.debug("deleteUser {} for institution: {}, productId: {} and productRole: {}", userId, institutionId, productId, productRole);
userService.deleteUserProduct(userId, institutionId, productId, productRole);
log.trace("deleteUser end");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ void suspendRelationship() throws Exception {
String userId = "rel1";
String institutionid = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
MvcResult result = mvc.perform(MockMvcRequestBuilders
.post(BASE_URL + "/{userId}/suspend", userId)
.queryParam("institutionId", institutionid )
.queryParam("productId", productId)
.queryParam("productRole", productRole)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andReturn();
// then
assertEquals(0, result.getResponse().getContentLength());
Mockito.verify(userServiceMock, Mockito.times(1))
.suspendUserProduct(userId, institutionid, productId);
.suspendUserProduct(userId, institutionid, productId, productRole);
Mockito.verifyNoMoreInteractions(userServiceMock);
}

Expand All @@ -106,19 +109,22 @@ void activateRelationship() throws Exception {
String userId = "rel1";
String institutionid = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
MvcResult result = mvc.perform(MockMvcRequestBuilders
.post(BASE_URL + "/{userId}/activate", userId)
.queryParam("institutionId", institutionid )
.queryParam("productId", productId)
.queryParam("productRole", productRole)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andReturn();
// then
assertEquals(0, result.getResponse().getContentLength());
Mockito.verify(userServiceMock, Mockito.times(1))
.activateUserProduct(userId, institutionid, productId);
.activateUserProduct(userId, institutionid, productId, productRole);
Mockito.verifyNoMoreInteractions(userServiceMock);
}

Expand All @@ -128,19 +134,22 @@ void deleteRelationship() throws Exception {
String userId = "rel1";
String institutionid = "id1";
String productId = "prod-pagopa";
String productRole = "admin";

// when
MvcResult result = mvc.perform(MockMvcRequestBuilders
.delete(BASE_URL + "/{userId}", userId)
.queryParam("institutionId", institutionid )
.queryParam("productId", productId)
.queryParam("productRole", productRole)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andReturn();
// then
assertEquals(0, result.getResponse().getContentLength());
Mockito.verify(userServiceMock, Mockito.times(1))
.deleteUserProduct(userId, institutionid, productId);
.deleteUserProduct(userId, institutionid, productId, productRole);
Mockito.verifyNoMoreInteractions(userServiceMock);
}

Expand Down

0 comments on commit 3ebc8ad

Please sign in to comment.