-
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-2132.Update contactinformation for an organisation #1576
base: master
Are you sure you want to change the base?
Changes from 10 commits
4525006
3b99e90
5b4b273
6c99bec
f5b99fa
81d9552
43944b9
0f02825
f7c651a
9bd62ba
bd06ee9
d81e6b6
bca596f
1c55b22
4df88af
daf82ea
7d04ffa
24ba34a
23f5dec
ba7b5af
954cf2b
257018e
384c1c0
a9edd55
f5ed946
50160db
3f9590f
cf00715
7fa4b61
507d4cb
6223858
dfcfad5
8b650ac
eb08be7
fb4444b
5dc59b9
ec9bf3d
96fffd8
0d7750a
be25b24
6123244
0a65900
a7e6b50
f8de665
ac9767e
9c70da3
cf20e99
a27c993
c5b36fc
33361cd
2a5b0bf
9fc04eb
af33d84
157cc57
1175b6e
38c88bf
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import org.springframework.http.HttpStatus; | ||
import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.constants.IdamStatus; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.MfaUpdateRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; | ||
|
@@ -54,6 +55,7 @@ | |
import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; | ||
import static uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient.createOrganisationRequest; | ||
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.PBA_STATUS_MESSAGE_ACCEPTED; | ||
import static uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest.aContactInformationCreationRequest; | ||
import static uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest.anOrganisationCreationRequest; | ||
import static uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest.aUserCreationRequest; | ||
import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.REVIEW; | ||
|
@@ -1231,4 +1233,61 @@ private static List<Map<String, Object>> sortByValue(final List<Map<String, Obje | |
.sorted(Comparator.comparing(map -> (String) map.get(key))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Test | ||
void updateContactInformationForOrganisationShouldReturnSuccess() { | ||
log.info("updateContactInformationForOrganisationShouldReturnSuccess :: STARTED"); | ||
|
||
Map<String, Object> response = professionalApiClient.createOrganisation(); | ||
String organisationIdentifier = (String) response.get("organisationIdentifier"); | ||
|
||
assertThat(organisationIdentifier).isNotEmpty(); | ||
JsonPath orgResponse = professionalApiClient.retrieveOrganisationDetails( | ||
organisationIdentifier, hmctsAdmin,OK); | ||
assertNotNull(orgResponse); | ||
List<HashMap> existingContactInformationList = (List) orgResponse.get("contactInformation"); | ||
|
||
assertThat(existingContactInformationList).isNotEmpty() | ||
.hasSizeGreaterThan(0); | ||
|
||
List<ContactInformationCreationRequest> contactInformationCreationRequestList = | ||
professionalApiClient.createContactInformationCreationRequests(); | ||
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. both existing addresses and new addresses are same, create new addresses with different values and assert. 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. changed CI data to save. 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. still new and existing contact addresses and DX are same |
||
assertThat(contactInformationCreationRequestList).isNotEmpty() | ||
.hasSizeGreaterThan(0); | ||
ContactInformationCreationRequest contactInformationCreationRequest = | ||
contactInformationCreationRequestList.get(0); | ||
|
||
existingContactInformationList.forEach(existingContactInfo -> { | ||
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. why do you need to loop existing addresses to update with new addresses ? |
||
|
||
assertThat(existingContactInfo.get("addressLine1")).isNotNull(); | ||
assertThat(existingContactInfo.get("addressLine2")).isNotNull(); | ||
assertThat(existingContactInfo.get("addressLine3")).isNotNull(); | ||
assertThat(existingContactInfo.get("uprn")).isNotNull(); | ||
assertThat(existingContactInfo.get("country")).isNotNull(); | ||
assertThat(existingContactInfo.get("townCity")).isNotNull(); | ||
assertThat(existingContactInfo.get("country")).isNotNull(); | ||
assertThat(existingContactInfo.get("postCode")).isNotNull(); | ||
|
||
Response result = | ||
professionalApiClient.updateContactInformationsToOrganisation(aContactInformationCreationRequest() | ||
.uprn(contactInformationCreationRequest.getUprn()) | ||
.addressLine1(contactInformationCreationRequest.getAddressLine1()) | ||
.addressLine2(contactInformationCreationRequest.getAddressLine2()) | ||
.addressLine3(contactInformationCreationRequest.getAddressLine3()) | ||
.country(contactInformationCreationRequest.getCountry()) | ||
.county(contactInformationCreationRequest.getCounty()) | ||
.townCity(contactInformationCreationRequest.getTownCity()) | ||
.postCode(contactInformationCreationRequest.getPostCode()) | ||
.dxAddress(contactInformationCreationRequest.getDxAddress()) | ||
.build(), | ||
OK,organisationIdentifier); | ||
|
||
assertNotNull(result); | ||
assertThat(result.getBody()).isNotNull(); | ||
assertThat(result.statusCode()).isEqualTo(200); | ||
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 assertions to verify new address details are updated for each UPRN (if uprn is use ) or for each address id |
||
}); | ||
|
||
log.info("updateContactInformationForOrganisationShouldReturnSuccess :: END"); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package uk.gov.hmcts.reform.professionalapi; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; | ||
import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.createContactInformationRequest; | ||
import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithAllFieldsAreUpdated; | ||
import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithMultipleAddressAllFields; | ||
|
||
class UpdateOrgContactInformationIntegrationTest extends AuthorizationEnabledIntegrationTest { | ||
|
||
@Test | ||
void update_addressline1_for_organisation_with_prd_admin_role_should_return_200() { | ||
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. is this test is to update addressLine1 only ? but test updating other fields as well ! |
||
ContactInformationCreationRequest contactInformationCreationRequest = | ||
createContactInformationRequest().build(); | ||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(contactInformationCreationRequest, | ||
hmctsAdmin,createOrganisationRequest()); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", 200); | ||
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 assertions to verify updated address details 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 asserts 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. you updated contact information with below details, but assertions verifying different data and dx address verification is missing. Add prefix "updated" to each new field so that it is easy to identify what is updated data. .addressLine1("addLine1") |
||
} | ||
|
||
@Test | ||
void update_contact_with_bad_request_should_return_400() { | ||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(null, hmctsAdmin,createOrganisationRequest()); | ||
|
||
assertThat(updateResponse).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. assert error message |
||
} | ||
|
||
@Test | ||
void update_contact_information_invalid_addressline1_should_return_400() { | ||
ContactInformationCreationRequest contactInformationCreationRequest = | ||
createContactInformationRequest().addressLine1(null).build(); | ||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(contactInformationCreationRequest, | ||
hmctsAdmin,createOrganisationRequest()); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "400"); | ||
assertThat(updateResponse.get("response_body").toString()).contains( | ||
"Field error in object 'contactInformationCreationRequest' on field 'addressLine1'"); | ||
} | ||
|
||
@Test | ||
void update_contact_information_multiple_requests_existing_for_org_should_return_200() { | ||
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. test case updating only one address details but method name indicates multiple requests , correct the method name . |
||
|
||
ContactInformationCreationRequest contactInformationCreationRequest = | ||
createContactInformationRequest().build(); | ||
|
||
java.util.Map<String, Object> responseForOrganisationCreation = professionalReferenceDataClient | ||
.createOrganisation(organisationRequestWithMultipleAddressAllFields().build()); | ||
|
||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(contactInformationCreationRequest, | ||
hmctsAdmin,(String)responseForOrganisationCreation.get(ORG_IDENTIFIER)); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", 200); | ||
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. assert updated address details 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 asserts |
||
} | ||
|
||
@Test | ||
void update_contact_information_single_requests_existing_for_org_should_return_200() { | ||
|
||
ContactInformationCreationRequest contactInformationCreationRequest = | ||
createContactInformationRequest().build(); | ||
|
||
|
||
java.util.Map<String, Object> responseForOrganisationCreation = professionalReferenceDataClient | ||
.createOrganisation(organisationRequestWithAllFieldsAreUpdated().build()); | ||
|
||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(contactInformationCreationRequest, | ||
hmctsAdmin,(String)responseForOrganisationCreation.get(ORG_IDENTIFIER)); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", 200); | ||
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. assert updated address details 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 asserts |
||
} | ||
|
||
@Test | ||
void update_contact_information_for_non_existing_organisation_should_return_400() { | ||
ContactInformationCreationRequest contactInformationCreationRequest = | ||
createContactInformationRequest().build(); | ||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(contactInformationCreationRequest, hmctsAdmin,"ABCDEF7"); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "404"); | ||
assertThat(updateResponse.get("response_body").toString()) | ||
.contains("errorMessage\":\"4 : Resource not found\",\"errorDescription\":\"Organisation does not exist"); | ||
|
||
} | ||
|
||
@Test | ||
void update_contact_information_invalid_request_should_return_400() { | ||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgContactInformation(new ContactInformationCreationRequest(null,null, | ||
null,null,null,null,null, | ||
null,null), hmctsAdmin,createOrganisationRequest()); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "400"); | ||
assertThat(updateResponse.get("response_body").toString()) | ||
.contains("validation on an argument failed"); | ||
|
||
} | ||
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 to update single address details without dx address, AddressLine3 and assert updated address details 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 shouldReturn200WhenUpdateSingleAddressWithoutDxAddress with asserts |
||
|
||
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 missing dxAddressUpdateRequired query param to update dx address and assert bad request with error message "dxAddressUpdateRequired value is required" 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 shoudlReturn400ForMissingDxAddress |
||
} | ||
rajkatla-hmcts marked this conversation as resolved.
Show resolved
Hide resolved
rajkatla-hmcts marked this conversation as resolved.
Show resolved
Hide resolved
rajkatla-hmcts marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
import uk.gov.hmcts.reform.professionalapi.configuration.resolver.UserId; | ||
import uk.gov.hmcts.reform.professionalapi.controller.SuperController; | ||
import uk.gov.hmcts.reform.professionalapi.controller.advice.ErrorResponse; | ||
import uk.gov.hmcts.reform.professionalapi.controller.advice.ResourceNotFoundException; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.InvalidRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.MfaUpdateRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; | ||
|
@@ -37,6 +39,7 @@ | |
import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.validator.impl.OrganisationByProfileIdsRequestValidator; | ||
import uk.gov.hmcts.reform.professionalapi.controller.response.ContactInformationResponse; | ||
import uk.gov.hmcts.reform.professionalapi.controller.response.DeleteOrganisationResponse; | ||
import uk.gov.hmcts.reform.professionalapi.controller.response.MultipleOrganisationsResponse; | ||
import uk.gov.hmcts.reform.professionalapi.controller.response.NewUserResponse; | ||
|
@@ -49,6 +52,7 @@ | |
import uk.gov.hmcts.reform.professionalapi.domain.Organisation; | ||
import uk.gov.hmcts.reform.professionalapi.domain.PbaResponse; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import javax.validation.Valid; | ||
|
@@ -744,4 +748,71 @@ public ResponseEntity<Object> retrieveOrganisationsByProfileIds( | |
.status(HttpStatus.OK) | ||
.body(response); | ||
} | ||
|
||
|
||
@Operation( | ||
summary = "Updates contact informations(address details) to organisation", | ||
description = "**IDAM Roles to access API** :<br> pui-organisation-manager", | ||
security = { | ||
@SecurityRequirement(name = "ServiceAuthorization"), | ||
@SecurityRequirement(name = "Authorization") | ||
} | ||
|
||
) | ||
|
||
@ApiResponse( | ||
responseCode = "200", | ||
description = "Updated Contact Information", | ||
content = @Content | ||
) | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "An invalid request has been provided", | ||
content = @Content | ||
) | ||
@ApiResponse( | ||
responseCode = "401", | ||
description = "Unauthorized Error : " | ||
+ "The requested resource is restricted and requires authentication", | ||
content = @Content | ||
) | ||
|
||
@ApiResponse( | ||
responseCode = "403", | ||
description = "Forbidden Error: Access denied", | ||
content = @Content | ||
) | ||
@ApiResponse( | ||
responseCode = "500", | ||
description = "Internal Server Error", | ||
content = @Content | ||
) | ||
|
||
|
||
@PutMapping( | ||
path = "/contactInformation/{orgId}", | ||
consumes = APPLICATION_JSON_VALUE, | ||
produces = APPLICATION_JSON_VALUE | ||
) | ||
@ResponseStatus(value = HttpStatus.CREATED) | ||
@ResponseBody | ||
@Secured({"prd-admin"}) | ||
public ResponseEntity<ContactInformationResponse> updateContactInformationForOrganisation( | ||
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "contactInformationCreationRequests") | ||
@Valid @NotNull @RequestBody ContactInformationCreationRequest contactInformationCreationRequest, | ||
@PathVariable("orgId") @NotBlank String organisationIdentifier) { | ||
|
||
organisationCreationRequestValidator.validateContactInformations(Arrays | ||
.asList(contactInformationCreationRequest)); | ||
|
||
var organisation = organisationService.getOrganisationByOrgIdentifier(organisationIdentifier); | ||
|
||
if (organisation == null) { | ||
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. Duplicate organisation find call move this validation to service impl 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. removed null check moved to service |
||
throw new ResourceNotFoundException("Organisation does not exist"); | ||
} | ||
|
||
return organisationService.updateContactInformationForOrganisation( | ||
contactInformationCreationRequest,organisationIdentifier); | ||
|
||
} | ||
} |
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.
add another 2 tests