-
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-2137. Update SRA Id #1668
base: master
Are you sure you want to change the base?
Changes from 64 commits
db90255
530bf25
0a6934f
c93a0f8
c163fbf
4bf43e3
8743c98
9ab2dfa
379ba0b
f6ce243
df887a5
570432d
9927c5e
f6a762a
1029f2c
0afe4d2
dafd810
3cb3dbd
b8e0323
76e261c
88e1cff
6edef7d
5e99427
809444f
357d65f
fd295ab
5273b65
177e806
8dc916e
94b25b5
0ae9a03
dbefdbb
31d9f06
1a96311
ed30490
1587540
76a321d
69971f4
7f82f30
f6bc99b
dc30a32
437cdd9
9279e00
2792daf
35133bf
f2d47c8
b79f88a
770c6ca
8e2edd7
73b166c
3fef26e
c85c293
70a0726
6e5a4aa
bd190b3
7396023
772ce63
deb92fd
e3f9d83
f3450bb
7f427c5
838ac3d
9f4bcf2
78046a4
c1d7c94
967c9e1
8641e45
f290893
986835e
31b4ad8
b951436
6a0e047
0c875e3
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,7 +13,9 @@ | |
import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationByProfileIdsRequest; | ||
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.OrganisationSraUpdateRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.UsersInOrganisationsByOrganisationIdentifiersRequest; | ||
import uk.gov.hmcts.reform.professionalapi.controller.response.UsersInOrganisationsByOrganisationIdentifiersResponse; | ||
import uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus; | ||
|
@@ -22,17 +24,23 @@ | |
import uk.gov.hmcts.reform.professionalapi.util.OrganisationProfileIdConstants; | ||
import uk.gov.hmcts.reform.professionalapi.util.ToggleEnable; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
import static org.springframework.http.HttpStatus.NO_CONTENT; | ||
import static org.springframework.http.HttpStatus.OK; | ||
import static uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient.createOrganisationRequest; | ||
import static uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient.createOrganisationRequestForV2; | ||
import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; | ||
import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.generateRandomDate; | ||
|
@@ -529,4 +537,72 @@ private void verifyOrganisationDetailsBySinceDateV2(Map<String, Object> response | |
}); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
void updateOrganisationSraIdShouldReturnSuccess() { | ||
log.info("updateOrganisationSraIdShouldReturnSuccess :: STARTED"); | ||
String updatedSra = randomAlphabetic(7); | ||
String organisationIdentifier = getActiveOrganisationId(); | ||
//create request to update sraid | ||
OrganisationSraUpdateRequest organisationSraUpdateRequest = | ||
new OrganisationSraUpdateRequest(updatedSra); | ||
|
||
//call endpoint to update name as 'updatedsraid' | ||
Response orgUpdatedSraResponse = professionalApiClient.updatesOrganisationSra( | ||
organisationSraUpdateRequest,organisationIdentifier, OK); | ||
assertNotNull(orgUpdatedSraResponse); | ||
assertThat(orgUpdatedSraResponse.statusCode()).isEqualTo(200); | ||
|
||
//retrieve saved organisation by id | ||
var orgResponse = professionalApiClient.retrieveOrganisationDetailsForV2(organisationIdentifier, hmctsAdmin, | ||
OK); | ||
assertThat(orgResponse).isNotNull(); | ||
assertNotNull(orgResponse.get("sraId")); | ||
assertThat(orgResponse.get("sraId").toString()).isEqualTo(updatedSra); | ||
|
||
List organisationAttributes = (List)orgResponse.get("orgAttributes"); | ||
assertThat(organisationAttributes).isNotNull(); | ||
|
||
LinkedHashMap<String, Object> attr = (LinkedHashMap)organisationAttributes.get(0); | ||
assertThat(attr).isNotNull(); | ||
assertThat(attr.get("key")).isEqualTo("regulators-0"); | ||
assertThat(attr.get("value").toString()).isEqualTo( | ||
"{\"regulatorType\":\"Solicitor Regulation Authority " | ||
+ "(SRA)\",\"organisationRegistrationNumber\":\"" + updatedSra + "\"}"); | ||
|
||
LocalDateTime updatedDate = LocalDateTime.parse(orgResponse.get("lastUpdated").toString()); | ||
assertThat(updatedDate.toLocalDate()).isEqualTo(LocalDate.now()); | ||
|
||
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 delete organisation call |
||
log.info("updateOrganisationSraIdShouldReturnSuccess :: END"); | ||
} | ||
|
||
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 partial success sra ids update |
||
@Test | ||
void updateOrganisationSraIdShouldReturnFailureIfNoSraId() { | ||
log.info("updateOrganisationNameShouldReturnFailureIfNoName :: STARTED"); | ||
String organisationIdentifier = getActiveOrganisationId(); | ||
OrganisationSraUpdateRequest organisationSraUpdateRequest = | ||
new OrganisationSraUpdateRequest(""); | ||
|
||
Response orgUpdatedSraIdResponse = professionalApiClient.updatesOrganisationSra( | ||
organisationSraUpdateRequest,organisationIdentifier, BAD_REQUEST); | ||
|
||
assertNotNull(orgUpdatedSraIdResponse); | ||
assertThat(orgUpdatedSraIdResponse.statusCode()).isEqualTo(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 assertion for error message |
||
log.info("updateOrganisationNameShouldReturnFailureIfNoName :: END"); | ||
} | ||
|
||
private String getActiveOrganisationId() { | ||
Map<String, Object> response = professionalApiClient.createOrganisation(); | ||
String organisationIdentifier = (String) response.get("organisationIdentifier"); | ||
assertThat(organisationIdentifier).isNotEmpty(); | ||
|
||
OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest().status("ACTIVE").build(); | ||
|
||
professionalApiClient.updateOrganisation(organisationCreationRequest, hmctsAdmin, organisationIdentifier,OK); | ||
|
||
return organisationIdentifier; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package uk.gov.hmcts.reform.professionalapi; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationSraUpdateRequest; | ||
import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
|
||
class UpdateOrgSraIntegrationTest extends AuthorizationEnabledIntegrationTest { | ||
|
||
|
||
@Test | ||
void update_sra_of_an_active_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. modify test case to update multiple sra ids |
||
|
||
String orgIdentifier = getOrganisationId(); | ||
String sraId = randomAlphabetic(7); | ||
OrganisationSraUpdateRequest organisationSraUpdateRequest = | ||
new OrganisationSraUpdateRequest(sraId); | ||
Map<String, Object> orgResponse = professionalReferenceDataClient | ||
.updateOrgSra(organisationSraUpdateRequest, | ||
hmctsAdmin,orgIdentifier); | ||
assertThat(orgResponse).isNotNull(); | ||
assertThat(orgResponse.get("http_status")).isEqualTo(200); | ||
|
||
Map<String, Object> responseBody = professionalReferenceDataClient | ||
.retrieveSingleOrganisationForV2Api(orgIdentifier,hmctsAdmin); | ||
assertThat(responseBody).isNotNull(); | ||
assertNotNull(responseBody.get("sraId")); | ||
assertThat(responseBody.get("sraId").toString()).isEqualTo(sraId); | ||
|
||
List organisationAttributes = (List)responseBody.get("orgAttributes"); | ||
assertThat(organisationAttributes).isNotNull(); | ||
|
||
LinkedHashMap<String, Object> attr = (LinkedHashMap)organisationAttributes.get(0); | ||
assertThat(attr).isNotNull(); | ||
assertThat(attr.get("key")).isEqualTo("regulators-0"); | ||
assertThat(attr.get("value").toString()).isEqualTo( | ||
"{\"regulatorType\":\"Solicitor Regulation Authority " | ||
+ "(SRA)\",\"organisationRegistrationNumber\":\"" + sraId + "\"}"); | ||
|
||
LocalDateTime updatedDate = LocalDateTime.parse(responseBody.get("lastUpdated").toString()); | ||
assertThat(updatedDate.toLocalDate()).isEqualTo(LocalDate.now()); | ||
} | ||
|
||
@Test | ||
void update_sra_with_bad_request_should_return_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. use Junit 5 to parameterise all error scenarios in test case similar like update name error tests |
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgSra(null, hmctsAdmin,getOrganisationId()); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "400"); | ||
assertThat(updateResponse.get("response_body").toString()) | ||
.contains("Required request body is missing:"); | ||
} | ||
|
||
@Test | ||
void update_sra_with_bad_request_OrgId_missing_should_return_400() { | ||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgSra(new OrganisationSraUpdateRequest("some-SraId"), hmctsAdmin,null); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "400"); | ||
assertThat(updateResponse.get("response_body").toString()) | ||
.contains("The given organisationIdentifier must be 7 Alphanumeric Characters"); | ||
|
||
} | ||
|
||
@Test | ||
void update_sra_with_invalid_name_should_return_400() { | ||
|
||
OrganisationSraUpdateRequest organisationSraUpdateRequest = | ||
new OrganisationSraUpdateRequest(""); | ||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgSra(organisationSraUpdateRequest, | ||
hmctsAdmin,getOrganisationId()); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "400"); | ||
assertThat(updateResponse.get("response_body").toString()).contains("SRA Id 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. for error message you need to use the changes made in ExceptionMapper class for update org name, but you have to wait until those changes are merged in master branch then only you can rebase this branch with master and assert expected error messages. |
||
|
||
} | ||
|
||
@Test | ||
void update_sra_with_blank_name_should_return_400() { | ||
OrganisationSraUpdateRequest organisationSraUpdateRequest = | ||
new OrganisationSraUpdateRequest(" "); | ||
|
||
Map<String, Object> updateResponse = professionalReferenceDataClient | ||
.updateOrgSra(organisationSraUpdateRequest, | ||
hmctsAdmin,getOrganisationId()); | ||
|
||
assertThat(updateResponse).containsEntry("http_status", "400"); | ||
assertThat(updateResponse.get("response_body").toString()).contains("SRA Id is required"); | ||
|
||
} | ||
|
||
|
||
private String getOrganisationId() { | ||
String organisationIdentifier = createOrganisationRequest(); | ||
updateOrganisation(organisationIdentifier, hmctsAdmin, "ACTIVE"); | ||
|
||
return organisationIdentifier; | ||
} | ||
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 partial success sra ids update |
||
|
||
} |
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.
modify test case to update multiple sra ids