-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: master
Are you sure you want to change the base?
Changes from all commits
9a50a6d
d82e858
e8fc944
9b93b8d
afa9069
3e9c773
97d98d5
45c19ac
7bfa4a4
681846a
ebf7086
f3bae92
1297067
d0f7116
df2a523
70abbd7
548a071
71c907c
bae5f68
fff2c8a
ed445d5
40acc8e
f8178fd
f87d92b
3eabbed
eef197a
5f5b2e3
5c17dec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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, | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
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<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont need to add new user There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont need to add new user There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test case for error scenario: "Request is empty" There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add error scenario test cases for below user profile calls:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added error testcase |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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