Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTSRD-2139.Update Organisation user idam id endpoint #1562

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9a50a6d
Upgrading perftest branch to V16 and adding subnet_suffix
SabinaHMCTS Dec 11, 2023
d82e858
End point to update Idam id for a professional user
SabinaHMCTS Feb 12, 2024
e8fc944
Merge branch 'master' into DTSRD-2139
SabinaHMCTS Feb 28, 2024
9b93b8d
Delete User and User Profile
SabinaHMCTS Apr 30, 2024
afa9069
Delete User and User Profile
SabinaHMCTS Apr 30, 2024
3e9c773
Delete User and User Profile
SabinaHMCTS Apr 30, 2024
97d98d5
Delete User and User Profile
SabinaHMCTS May 1, 2024
45c19ac
Merge branch 'master' into DTSRD-2139
SabinaHMCTS May 1, 2024
7bfa4a4
Merge branch 'master' into DTSRD-2139
SabinaHMCTS May 2, 2024
681846a
Delete User and User Profile
SabinaHMCTS May 2, 2024
ebf7086
Merge branch 'master' into DTSRD-2139
SabinaHMCTS May 7, 2024
f3bae92
updateUserIdamForOrganisation
SabinaHMCTS May 7, 2024
1297067
Merge branch 'master' into DTSRD-2139
SabinaHMCTS Jun 11, 2024
d0f7116
update admin unit tests
SabinaHMCTS Jun 11, 2024
df2a523
update admin unit tests
SabinaHMCTS Jun 11, 2024
70abbd7
update admin unit tests
SabinaHMCTS Jun 11, 2024
548a071
update admin unit tests
SabinaHMCTS Jun 12, 2024
71c907c
update admin unit tests
SabinaHMCTS Jun 12, 2024
bae5f68
update admin unit tests
SabinaHMCTS Jun 12, 2024
fff2c8a
Merge branch 'master' into DTSRD-2139
SabinaHMCTS Jul 9, 2024
ed445d5
update functional tests
SabinaHMCTS Jul 9, 2024
40acc8e
update functional tests
SabinaHMCTS Jul 9, 2024
f8178fd
update functional tests
SabinaHMCTS Jul 9, 2024
f87d92b
update functional tests
SabinaHMCTS Jul 9, 2024
3eabbed
update pact tests
SabinaHMCTS Jul 17, 2024
eef197a
Merge branch 'master' into DTSRD-2139
SabinaHMCTS Jul 17, 2024
5f5b2e3
update pact tests
SabinaHMCTS Jul 17, 2024
5c17dec
Updating Terraform Formatting
hmcts-jenkins-j-to-z[bot] Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ private Organisation getOrganisation() {
contactInformation.setId(UUID.randomUUID());
organisation.setContactInformations(List.of(contactInformation));

SuperUser superUser = new SuperUser("firstName", "lastName",
"email", organisation);
SuperUser superUser = new SuperUser("firstName", "lastName","email", organisation);
superUser.setUserIdentifier(UUID.randomUUID().toString());
List<SuperUser> users = new ArrayList<>();
users.add(superUser);
organisation.setUsers(users);

return organisation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.PbaUpdateRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest;
import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse;
import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsWithPbaStatusResponse;
Expand All @@ -38,6 +39,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import static java.util.Objects.nonNull;
Expand Down Expand Up @@ -689,6 +691,50 @@ void findOrganisationByPbaStatusShouldReturn403WhenToggledOff() {

}

@Test
@ExtendWith(FeatureToggleConditionExtension.class)
@DisplayName("Update Organisation's Idam id should return 200 when toggled off")
@ToggleEnable(mapKey = "OrganisationInternalController.retrieveOrgByPbaStatus", withFeature = false)
void updateUserIdamForOrganisationShouldReturnSuccess() {
log.info("updateUserIdamForOrganisationShouldReturnSuccess :: STARTED");
OrganisationCreationRequest orgReq = createOrganisationRequest().build();
Map<String, Object> response = professionalApiClient.createOrganisation(orgReq);
String orgIdentifier = (String) response.get("organisationIdentifier");
orgReq.setStatus("ACTIVE");
professionalApiClient.updateOrganisation(orgReq, hmctsAdmin,
orgIdentifier, OK);

NewUserCreationRequest newUserCreationRequest =
professionalApiClient.createNewUserRequest("[email protected]");
Map<String, Object> newUserResponse = professionalApiClient.addNewUserToAnOrganisation(orgIdentifier,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need to add new user to update idam id for existing user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating a new user as test user to use as existing user for updating id

hmctsAdmin, newUserCreationRequest, HttpStatus.CREATED);
assertThat(newUserResponse).isNotNull();
assertThat(newUserResponse.get("userIdentifier")).isNotNull();
String existingUserId = (String) newUserResponse.get("userIdentifier");
String newId = UUID.randomUUID().toString();
ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest
.aUserIdentifierRequest().existingIdamId(existingUserId).newIdamId(newId)
.build();

Map<String, Object> updatedIdamResponse = professionalApiClient.updateUserIdamForOrganisation(
professionalUserIdentifierRequest, OK);

Map<String, Object> searchResponse = professionalApiClient
.searchOrganisationUsersByStatusInternal(orgIdentifier, hmctsAdmin, OK);

List<Map<String, Object>> professionalUsersResponses = (List<Map<String, Object>>) searchResponse.get("users");
Map professionalUsersResponse = getUserById(professionalUsersResponses, existingUserId);

assertThat(updatedIdamResponse).isNotNull();
assertThat(professionalUsersResponse).isNotNull();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add assertion to verify that the user's idam id is updated with new id value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assertThat(professionalUsersResponse.get("userIdentifier").toString())
.contains(newId);

professionalApiClient.deleteOrganisation(orgIdentifier, hmctsAdmin, NO_CONTENT);

log.info("updateUserIdamForOrganisationShouldReturnSuccess :: END");
}

@Test
@ToggleEnable(mapKey = "OrganisationInternalController.updateAnOrganisationsRegisteredPbas", withFeature = true)
@ExtendWith(FeatureToggleConditionExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.UsersInOrganisationsByOrganisationIdentifiersRequest;
Expand Down Expand Up @@ -776,6 +777,21 @@ public Map<String, Object> retrievePaymentAccountsByEmail(String email, String r
return response.body().as(Map.class);
}

public Map<String, Object> updateUserIdamForOrganisation(
ProfessionalUserIdentifierRequest professionalUserIdentifierRequest, HttpStatus status) {
Response response = getMultipleAuthHeadersInternal()
.body(professionalUserIdentifierRequest)
.put("/refdata/internal/v1/organisations/userIdam")
.andReturn();

response.then()
.assertThat()
.statusCode(OK.value());

return response.body().as(Map.class);
}


public Map<String, Object> retrievePaymentAccountsByEmailV2(String email, String role) {
Response response = getUserEmailAsHeaderWithExisting(idamOpenIdClient
.getcwdAdminOpenIdToken("prd-admin"), email)
Expand Down Expand Up @@ -1287,8 +1303,8 @@ public void updateOrganisationV2(OrganisationOtherOrgsCreationRequest organisati

public void updateOrganisation(String organisationIdentifier, String role) {

OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest().status("ACTIVE").build();

OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest().status("ACTIVE")
.statusMessage("Activate organisation").build();
updateOrganisation(organisationCreationRequest, role, organisationIdentifier);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package uk.gov.hmcts.reform.professionalapi;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest;
import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest;
import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;

@SerenityTest
@Slf4j
class ModifyUserIdamIdIntegrationTest extends AuthorizationEnabledIntegrationTest {

@Test
void ac1_modify_idamId_of_active_user_for_an_active_organisation_should_return_200() {
//create and update organisation
String organisationIdentifier = createOrganisationRequest();
updateOrganisation(organisationIdentifier, hmctsAdmin, ACTIVE);

//create new user
List<String> userRoles = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need to add new user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating test user

userProfileCreateUserWireMock(HttpStatus.CREATED);
userRoles.add(puiCaseManager);

Map<String, Object> newUserResponse =
professionalReferenceDataClient.addUserToOrganisation(organisationIdentifier,
inviteUserCreationRequest(randomAlphabetic(5) + "@email.com",
userRoles), hmctsAdmin);
String existingUserIdentifier = (String) newUserResponse.get(USER_IDENTIFIER);

ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest
.aUserIdentifierRequest().existingIdamId(existingUserIdentifier).newIdamId(UUID.randomUUID().toString())
.build();

//modify Idam details in user Profile
userProfileCreateUserWireMock(HttpStatus.CREATED);

updateUserProfileRolesMock(HttpStatus.OK);

Map<String, Object> modifiedUserResponse =
professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin);


//validate overall response should be 200 always
assertThat(modifiedUserResponse.get("http_status")).isNotNull();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add assertion to verify that the user's idam id is updated with new id value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fetching id in response

assertThat(modifiedUserResponse.get("http_status")).isEqualTo("200 OK");

}


@Test
void ac2_modify_idam_newId_null_should_return_400() {

//create and update organisation
String organisationIdentifier = createOrganisationRequest();
updateOrganisation(organisationIdentifier, hmctsAdmin, ACTIVE);

//create new user
List<String> userRoles = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need to add new user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creatign test user

userProfileCreateUserWireMock(HttpStatus.CREATED);
userRoles.add(puiCaseManager);

Map<String, Object> newUserResponse =
professionalReferenceDataClient.addUserToOrganisation(organisationIdentifier,
inviteUserCreationRequest(randomAlphabetic(5) + "@email.com",
userRoles), hmctsAdmin);
String existingUserIdentifier = (String) newUserResponse.get(USER_IDENTIFIER);

ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest
.aUserIdentifierRequest().existingIdamId(existingUserIdentifier).newIdamId(null)
.build();

userProfileCreateUserWireMock(HttpStatus.CREATED);
updateUserProfileRolesMock(HttpStatus.BAD_REQUEST);

Map<String, Object> modifiedUserResponse =
professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin);

assertThat(modifiedUserResponse.get("http_status")).isNotNull();
assertThat(modifiedUserResponse).containsEntry("http_status","400");

}


@Test
void ac2_modify_idam_existingId_null_should_return_400() {

ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest
.aUserIdentifierRequest().existingIdamId(null).newIdamId(UUID.randomUUID().toString())
.build();

userProfileCreateUserWireMock(HttpStatus.CREATED);
updateUserProfileRolesMock(HttpStatus.BAD_REQUEST);

Map<String, Object> modifiedUserResponse =
professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin);

assertThat(modifiedUserResponse.get("http_status")).isNotNull();
assertThat(modifiedUserResponse).containsEntry("http_status","400");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test case for error scenario: "Request is empty"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


void ac2_modify_idam_empty_Request_should_return_400() {

ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest
.aUserIdentifierRequest().existingIdamId(null).newIdamId(UUID.randomUUID().toString())
.build();

userProfileCreateUserWireMock(HttpStatus.CREATED);
updateUserProfileRolesMock(HttpStatus.BAD_REQUEST);

Map<String, Object> modifiedUserResponse =
professionalReferenceDataClient.updateUserIdamForOrganisation(null,hmctsAdmin);

assertThat(modifiedUserResponse.get("http_status")).isNotNull();
assertThat(modifiedUserResponse).containsEntry("http_status","400");
}

@Test
void ac1_modify_idamId_userProfileFeignClient_getUserProfileById_Bad_Request_error() {
//create and update organisation
String organisationIdentifier = createOrganisationRequest();
updateOrganisation(organisationIdentifier, hmctsAdmin, ACTIVE);

//create new user
List<String> userRoles = new ArrayList<>();
userProfileCreateUserWireMock(HttpStatus.CREATED);
userRoles.add(puiCaseManager);

Map<String, Object> newUserResponse =
professionalReferenceDataClient.addUserToOrganisation(organisationIdentifier,
inviteUserCreationRequest(randomAlphabetic(5) + "@email.com",
userRoles), hmctsAdmin);
String existingUserIdentifier = (String) newUserResponse.get(USER_IDENTIFIER);

ProfessionalUserIdentifierRequest professionalUserIdentifierRequest = ProfessionalUserIdentifierRequest
.aUserIdentifierRequest().existingIdamId(existingUserIdentifier).newIdamId(UUID.randomUUID().toString())
.build();

//modify Idam details in user Profile
userProfileCreateUserWireMock(HttpStatus.CREATED);

updateUserProfileRolesMock(HttpStatus.BAD_REQUEST);

Map<String, Object> modifiedUserResponse =
professionalReferenceDataClient.updateUserIdamForOrganisation(professionalUserIdentifierRequest,hmctsAdmin);

//validate overall response should be 200 always
assertThat(modifiedUserResponse.get("http_status")).isNotNull();
assertThat(modifiedUserResponse).containsEntry("http_status","400");

}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add error scenario test cases for below user profile calls:

  1. userProfileFeignClient.getUserProfileById
  2. userProfileFeignClient.modifyUserRoles. (change this method name as its confusing)

Copy link
Contributor Author

@SabinaHMCTS SabinaHMCTS Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added error testcase

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.ProfessionalUserIdentifierRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest;
import uk.gov.hmcts.reform.professionalapi.controller.request.UsersInOrganisationsByOrganisationIdentifiersRequest;
import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse;
Expand Down Expand Up @@ -664,6 +665,27 @@ public Map<String, Object> modifyUserRolesOfOrganisation(UserProfileUpdatedData
return getResponse(responseEntity);
}

public Map<String, Object> updateUserIdamForOrganisation(
ProfessionalUserIdentifierRequest professionalUserIdentifierRequest, String hmctsAdmin) {
ResponseEntity<Map> responseEntity = null;
String urlPath = "http://localhost:" + prdApiPort + APP_INT_BASE_PATH + "/userIdam/";

try {
HttpEntity<ProfessionalUserIdentifierRequest> requestEntity =
new HttpEntity<>(professionalUserIdentifierRequest,
getMultipleAuthHeaders(hmctsAdmin));
responseEntity = restTemplate.exchange(urlPath, HttpMethod.PUT, requestEntity, Map.class);
} catch (RestClientResponseException ex) {
HashMap<String, Object> statusAndBody = new HashMap<>(2);
statusAndBody.put("http_status", String.valueOf(ex.getRawStatusCode()));
statusAndBody.put("response_body", ex.getResponseBodyAsString());
return statusAndBody;
}


return getResponse(responseEntity);
}

public Map<String, Object> modifyUserRolesOfOrganisationExternal(UserProfileUpdatedData userProfileUpdatedData,
String userIdentifier, String externalRole) {
ResponseEntity<Map> responseEntity = null;
Expand Down
Loading