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-2136. Update Name for a given organisation #1573

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
db90255
Upgrading perftest branch to V16 and adding subnet_suffix
SabinaHMCTS Dec 11, 2023
530bf25
Update name for an organisation moving code to controller
SabinaHMCTS Feb 20, 2024
0a6934f
Update name for an organisation adding test cases
SabinaHMCTS Feb 20, 2024
c93a0f8
Update name for an organisation adding test cases
SabinaHMCTS Feb 21, 2024
c163fbf
Update name for an organisation adding test cases
SabinaHMCTS Feb 21, 2024
4bf43e3
Merge branch 'master' into DTSRD-2136
SabinaHMCTS Feb 21, 2024
8743c98
Update name for an organisation adding test cases
SabinaHMCTS Feb 21, 2024
9ab2dfa
Update name for an organisation adding test cases
SabinaHMCTS Feb 21, 2024
379ba0b
Update name for an organisation adding test cases
SabinaHMCTS Feb 21, 2024
f6ce243
Update name for an organisation adding test cases
SabinaHMCTS Feb 21, 2024
df887a5
Merge branch 'master' into DTSRD-2136
SabinaHMCTS Feb 27, 2024
570432d
Update OrganisationCreationRequestValidatorTest.java
SabinaHMCTS Feb 27, 2024
9927c5e
Update ProfessionalInternalUserFunctionalTest.java
SabinaHMCTS Feb 27, 2024
f6a762a
Update name sra for an organisation adding test cases
SabinaHMCTS Feb 27, 2024
1029f2c
Update name sra for an organisation adding test cases
SabinaHMCTS Feb 27, 2024
0afe4d2
Update name sra for an organisation adding test cases
SabinaHMCTS Feb 29, 2024
dafd810
Update name sra for an organisation adding test cases
SabinaHMCTS Feb 29, 2024
3cb3dbd
Update name sra for an organisation adding test cases
SabinaHMCTS Feb 29, 2024
b8e0323
Merge branch 'master' into DTSRD-2136
SabinaHMCTS Mar 12, 2024
76e261c
fixing review comments
SabinaHMCTS Mar 12, 2024
88e1cff
fixing review comments
SabinaHMCTS Mar 13, 2024
6edef7d
fixing review comments
SabinaHMCTS Mar 13, 2024
5e99427
fixing review comments
SabinaHMCTS Mar 13, 2024
809444f
Merge branch 'master' into DTSRD-2136
SabinaHMCTS Mar 19, 2024
357d65f
Update name sra for an organisation adding test cases
SabinaHMCTS Mar 20, 2024
fd295ab
Update name sra for an organisation adding test cases
SabinaHMCTS Mar 20, 2024
5273b65
Merge branch 'master' into DTSRD-2136
SabinaHMCTS May 1, 2024
177e806
Merge branch 'master' into DTSRD-2136
SabinaHMCTS May 9, 2024
8dc916e
Update ProfessionalInternalUserFunctionalTest.java
SabinaHMCTS May 14, 2024
94b25b5
Update ProfessionalInternalUserFunctionalTest.java
SabinaHMCTS May 14, 2024
0ae9a03
Update OrganisationServiceImpl.java
SabinaHMCTS May 14, 2024
dbefdbb
update admin unit tests
SabinaHMCTS Jun 11, 2024
31d9f06
update admin unit tests
SabinaHMCTS Jun 11, 2024
1a96311
update functional tests
SabinaHMCTS Aug 23, 2024
ed30490
Update OrganisationServiceImpl.java
SabinaHMCTS Aug 27, 2024
1587540
Merge branch 'master' into DTSRD-2136
SabinaHMCTS Aug 27, 2024
76a321d
Update OrganisationInternalController.java
SabinaHMCTS Aug 27, 2024
69971f4
Update OrganisationServiceImpl.java
SabinaHMCTS Aug 27, 2024
7f82f30
Update ProfessionalInternalUserFunctionalTest.java
SabinaHMCTS Aug 29, 2024
f6bc99b
Update UpdateOrgNameSraIdIntegrationTest.java
SabinaHMCTS Aug 29, 2024
dc30a32
Fixing build
SabinaHMCTS Sep 2, 2024
437cdd9
Changing endpoint to only update Organisation Name
SabinaHMCTS Sep 2, 2024
9279e00
Changing endpoint to only update Organisation Name
SabinaHMCTS Sep 3, 2024
2792daf
Changing endpoint to only update Organisation Name
SabinaHMCTS Sep 3, 2024
35133bf
Changing endpoint to only update Organisation Name
SabinaHMCTS Sep 3, 2024
ed57433
Changing endpoint to only update Organisation Name
SabinaHMCTS Sep 3, 2024
744e4bc
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
2c039fb
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
c0aadab
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
4965cf6
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
1ee1c6c
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
c6e634b
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
437ef4b
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
218fc52
Changes to fix review comments
SabinaHMCTS Sep 4, 2024
e5df3a0
Update UpdateOrgNameIntegrationTest.java
SabinaHMCTS Sep 4, 2024
7470194
Changes to fix review comments
SabinaHMCTS Sep 5, 2024
e7b85c9
Changes to fix review comments
SabinaHMCTS Sep 5, 2024
8a86724
Changes to fix review comments
SabinaHMCTS Sep 5, 2024
0137be0
Changes to fix review comments
SabinaHMCTS Sep 6, 2024
875902a
Merge branch 'master' into DTSRD-2136
SabinaHMCTS Sep 6, 2024
48ffa58
DTSRD-2136: Org name update - refactored IT tests
rajkatla-hmcts Sep 9, 2024
294b75b
DTSRD-2136: Org name update - refactored IT tests
rajkatla-hmcts Sep 9, 2024
3539636
removed teh extra code for DTSRD-2134
SabinaHMCTS Sep 10, 2024
b530f0f
DTSRD-2136: Org name update - refactored error messages
rajkatla-hmcts Sep 10, 2024
00f0ca5
DTSRD-2136: Org name update - refactored error messages
rajkatla-hmcts Sep 10, 2024
cc40acf
DTSRD-2136: Org name update - refactored error messages
rajkatla-hmcts Sep 10, 2024
41d4ffa
DTSRD-2136: Org name update - refactored error messages
rajkatla-hmcts Sep 10, 2024
d149a7b
DTSRD-2136: Org name update - refactored error messages
rajkatla-hmcts Sep 11, 2024
60e96f3
DTSRD-2136: Org name update - temporary fix for test coverage issue
rajkatla-hmcts Sep 11, 2024
99e68f1
changed orgId to invalid value
SabinaHMCTS Sep 11, 2024
76ed65f
fixing sonar code smell
SabinaHMCTS Sep 11, 2024
5fd5005
DTSRD-2136: Org name update - populating last updated value
rajkatla-hmcts Sep 11, 2024
b080721
DTSRD-2136: Org name update - populating last updated value
rajkatla-hmcts Sep 11, 2024
836cb17
DTSRD-2136: Org name update - populating last updated value
rajkatla-hmcts Sep 11, 2024
1f657b8
DTSRD-2136: Org name update - functional test update for error scenario
rajkatla-hmcts Sep 11, 2024
4b2d138
DTSRD-2136: Org name update - functional test update for error scenario
rajkatla-hmcts Sep 11, 2024
7bc5b51
DTSRD-2136: Org name update
rajkatla-hmcts Sep 11, 2024
9efcae0
fixing review comments on controller changed status to OK and deleted…
SabinaHMCTS Sep 12, 2024
612f4b0
made changes to endpoint to accept multiple requests for name change
SabinaHMCTS Sep 17, 2024
581a2ab
made changes to endpoint to accept multiple requests for name change
SabinaHMCTS Sep 17, 2024
57a11b9
made changes to endpoint to accept multiple requests for name change
SabinaHMCTS Sep 17, 2024
924344b
made changes to endpoint to accept multiple requests for name change
SabinaHMCTS Sep 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 @@ -780,6 +780,38 @@ void updatePaymentAccountsShouldReturnForbiddenWhenToggledOff() {
log.info("updatePaymentAccountsShouldReturnForbiddenWhenToggledOff :: END");
}

@Test
@ExtendWith(FeatureToggleConditionExtension.class)
void updateOrganisationNameAndSraShouldReturnSuccess() {
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
log.info("updateOrganisationNameShouldReturnSuccess :: STARTED");
String updatedName = "updatedName";
String updatedSra = "updatedSraId";
Map<String, Object> response = professionalApiClient.createOrganisation();
String organisationIdentifier = (String) response.get("organisationIdentifier");
assertThat(organisationIdentifier).isNotEmpty();

JsonPath orgResponse = professionalApiClient.retrieveOrganisationDetails(
organisationIdentifier, hmctsAdmin,OK);

assertNotNull(orgResponse.get("name"));

OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest()
.name(updatedName).sraId(updatedSra).build();

professionalApiClient.updatesOrganisationName(organisationCreationRequest,
hmctsAdmin,organisationIdentifier, OK);

JsonPath orgUpdatedNameResponse = professionalApiClient.retrieveOrganisationDetails(
organisationIdentifier, hmctsAdmin,OK);
assertThat(response).isNotNull();
assertNotNull(orgUpdatedNameResponse.get("name"));
assertThat(orgUpdatedNameResponse.get("name").toString()).contains(updatedName);
assertNotNull(orgUpdatedNameResponse.get("sraId"));
assertThat(orgUpdatedNameResponse.get("sraId").toString()).contains(updatedSra);

log.info("updateOrganisationNameShouldReturnSuccess :: END");
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
void findOrganisationsWithPaginationShouldReturnSuccess() {
log.info("findOrganisationsWithPaginationShouldReturnSuccess :: STARTED");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,22 @@ public void updateOrganisation(OrganisationCreationRequest organisationCreationR
.statusCode(expectedStatus.value());
}

public void updatesOrganisationName(OrganisationCreationRequest organisationCreationRequest, String role,
String organisationIdentifier, HttpStatus expectedStatus) {

Response response = getMultipleAuthHeadersInternal()
.body(organisationCreationRequest)
.put("/refdata/internal/v1/organisations/nameSra/" + organisationIdentifier)
.andReturn();

log.info("{}:: Update organisation Name or SRA id response: {}",
loggingComponentName, response.getStatusCode());

response.then()
.assertThat()
.statusCode(expectedStatus.value());
}

public void updateOrganisationToReview(String organisationIdentifier, String statusMessage, String role) {

OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package uk.gov.hmcts.reform.professionalapi;

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest;
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.organisationRequestWithAllFields;
import static uk.gov.hmcts.reform.professionalapi.helper.OrganisationFixtures.organisationRequestWithAllFieldsAreUpdated;


class UpdateOrgNameSraIdIntegrationTest extends AuthorizationEnabledIntegrationTest {


@Test
void update_name_or_sra_of_an_active_organisation_with_prd_admin_role_should_return_200() {
Map<String, Object> updateResponse = professionalReferenceDataClient
.updateOrgNameSraIdStatus(organisationRequestWithAllFields().build(), hmctsAdmin,getOrganisationId());

assertThat(updateResponse).containsEntry("http_status", 200);
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
void update_name_or_sra_with_bad_request_should_return_400() {
Map<String, Object> updateResponse = professionalReferenceDataClient
.updateOrgNameSraIdStatus(null, hmctsAdmin,getOrganisationId());

assertThat(updateResponse).containsEntry("http_status", "400");
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
void update_name_or_sra_with_invalid_name_and_sra_should_return_400() {
OrganisationCreationRequest organisationUpdateRequest = organisationRequestWithAllFieldsAreUpdated()
.name("")
.sraId(null)
.build();
Map<String, Object> updateResponse = professionalReferenceDataClient
.updateOrgNameSraIdStatus(organisationUpdateRequest, hmctsAdmin,getOrganisationId());

assertThat(updateResponse).containsEntry("http_status", "400");
assertThat(updateResponse.get("response_body").toString()).contains("Name or SRA Id not found");
}

void update_name_or_sra_with_invalid_name_and_valid_sra_should_return_200() {
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
OrganisationCreationRequest organisationUpdateRequest = organisationRequestWithAllFieldsAreUpdated()
.name(null)
.build();
Map<String, Object> updateResponse = professionalReferenceDataClient
.updateOrgNameSraIdStatus(organisationUpdateRequest, hmctsAdmin,getOrganisationId());

assertThat(updateResponse).containsEntry("http_status", 200);
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
}

void update_name_or_sra_with_invalid_sra_and_valid_name_should_return_200() {
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
OrganisationCreationRequest organisationUpdateRequest = organisationRequestWithAllFieldsAreUpdated()
.sraId(null)
.build();
Map<String, Object> updateResponse = professionalReferenceDataClient
.updateOrgNameSraIdStatus(organisationUpdateRequest, hmctsAdmin,getOrganisationId());

assertThat(updateResponse).containsEntry("http_status", 200);
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
}

private String getOrganisationId() {
String organisationIdentifier = createOrganisationRequest();
updateOrganisation(organisationIdentifier, hmctsAdmin, "ACTIVE");

return organisationIdentifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1021,4 +1021,25 @@ public Map<String, Object> findOrganisationsByUserId(String userId, String role)
return getResponse(responseEntity);
}


public Map<String, Object> updateOrgNameSraIdStatus(
OrganisationCreationRequest organisationCreationRequest, String role, String organisationIdentifier) {

ResponseEntity<Map> responseEntity = null;
String urlPath = "http://localhost:" + prdApiPort + APP_INT_BASE_PATH + "/nameSra/" + organisationIdentifier;
try {
HttpEntity<OrganisationCreationRequest> requestEntity = new HttpEntity<>(organisationCreationRequest,
getMultipleAuthHeaders(role));
responseEntity = restTemplate.exchange(urlPath, HttpMethod.PUT, requestEntity, Map.class);
} catch (RestClientResponseException ex) {
HashMap<String, Object> statusAndBody = new HashMap<>(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: map creation could be replaced by using Map.of(k1, v1, k2, v2) factory method

statusAndBody.put("http_status", String.valueOf(ex.getRawStatusCode()));
statusAndBody.put("response_body", ex.getResponseBodyAsString());
return statusAndBody;
}

Map<String, Object> organisationResponse = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: map creation could be replaced by using Map.of(k1, v1, k2, v2) factory method

organisationResponse.put("http_status", responseEntity.getStatusCodeValue());
return organisationResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ private ProfessionalApiConstants() {

public static final String NO_ORG_FOUND_FOR_GIVEN_ID
= "No Organisation was found with the given organisationIdentifier ";

public static final String NO_CONTACT_FOUND_FOR_GIVEN_ORG
= "No Contact Information was found with the given organisationIdentifier ";
SabinaHMCTS marked this conversation as resolved.
Show resolved Hide resolved

public static final String ORG_NOT_ACTIVE_NO_USERS_RETURNED
= "Organisation is not Active hence not returning any users";
public static final String ERROR_MESSAGE_403_FORBIDDEN = "403 Forbidden";
Expand Down Expand Up @@ -69,6 +73,7 @@ private ProfessionalApiConstants() {
public static final String EMPTY_USER_ID = "User Id cannot be empty";

public static final String ERROR_MSG_NO_ORGANISATION_FOUND = "No organisation belongs to given email";
public static final String ERROR_MSG_EMAIL_FOUND = "email address ";
SabinaHMCTS marked this conversation as resolved.
Show resolved Hide resolved
public static final String ERROR_MSG_NO_PBA_FOUND = "No PBAs associated with given email";
public static final String PBA_STATUS_MESSAGE_ACCEPTED = "Edited by Admin";
public static final String PBA_STATUS_MESSAGE_AUTO_ACCEPTED = "Auto approved by Admin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import static org.apache.commons.lang.StringUtils.isBlank;
import static org.apache.commons.lang3.BooleanUtils.isNotTrue;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORGANISATION_IDENTIFIER_FORMAT_REGEX;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_ID_VALIDATION_ERROR_MESSAGE;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NOT_ACTIVE;
import static uk.gov.hmcts.reform.professionalapi.util.RefDataUtil.removeEmptySpaces;

@RequestMapping(
path = "refdata/internal/v1/organisations"
Expand Down Expand Up @@ -696,6 +698,69 @@ public ResponseEntity<OrganisationEntityResponse> retrieveOrganisationByUserId(
return organisationService.retrieveOrganisationByUserId(userId);
}

@Operation(
summary = "Updates an Organisation's name",
description = "**IDAM Roles to access API** : <br> prd-admin",
security = {
@SecurityRequirement(name = "ServiceAuthorization"),
@SecurityRequirement(name = "Authorization")
})

@ApiResponse(
responseCode = "200",
description = "Organisation name has been updated",
content = @Content(schema = @Schema(implementation = String.class))
)
@ApiResponse(
responseCode = "400",
description = "If Organisation request sent with null/invalid values for mandatory fields",
content = @Content
)
@ApiResponse(
responseCode = "403",
description = "Forbidden Error: Access denied",
content = @Content
)
@ApiResponse(
responseCode = "404",
description = "No Organisation found with the given ID",
content = @Content
)
@ApiResponse(
responseCode = "500",
description = "Internal Server Error",
content = @Content
)

@PutMapping(
value = "/nameSra/{orgId}",
consumes = APPLICATION_JSON_VALUE,
produces = APPLICATION_JSON_VALUE
)
@ResponseStatus(value = HttpStatus.CREATED)
lukasz-wolski marked this conversation as resolved.
Show resolved Hide resolved
@ResponseBody
@Secured({"prd-admin"})
public ResponseEntity<OrganisationResponse> updateOrganisationNameOrSra(
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "organisationCreationRequest")
@Valid @NotNull @RequestBody OrganisationCreationRequest organisationCreationRequest,
@Pattern(regexp = ORGANISATION_IDENTIFIER_FORMAT_REGEX, message = ORG_ID_VALIDATION_ERROR_MESSAGE)
@PathVariable("orgId") @NotBlank String organisationIdentifier) {

var orgId = removeEmptySpaces(organisationIdentifier);
organisationCreationRequestValidator.validateOrganisationIdentifier(orgId);
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved

if (isBlank(organisationCreationRequest.getName()) && isBlank(organisationCreationRequest.getSraId())) {
throw new InvalidRequest("Name or SRA Id not found");
SabinaHMCTS marked this conversation as resolved.
Show resolved Hide resolved
}

OrganisationResponse organisationResponse = organisationService
.updateOrganisationNameOrSra(organisationCreationRequest, orgId);

ResponseEntity<OrganisationResponse> resp = ResponseEntity.status(200).body(organisationResponse);
return resp;
}


@Operation(
summary = "Retrieves Organisations by Organisation Profile IDs",
description = "**Bearer token not required to access API. Only a valid s2s token**",
Expand Down Expand Up @@ -744,4 +809,5 @@ public ResponseEntity<Object> retrieveOrganisationsByProfileIds(
.status(HttpStatus.OK)
.body(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
public class OrganisationCreationRequest {

@NotNull
private final String name;
private String name;

private String status;

private String statusMessage;

private final String sraId;
private String sraId;

private String sraRegulated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ OrganisationsDetailResponseV2 findByOrganisationStatusForV2Api(LocalDateTime for

OrganisationEntityResponse retrieveOrganisation(String organisationIdentifier, boolean isPendingPbaRequired);

OrganisationResponse updateOrganisationNameOrSra(
OrganisationCreationRequest organisationCreationRequest, String organisationIdentifier);

OrganisationResponse updateOrganisation(OrganisationCreationRequest organisationCreationRequest,
String organisationIdentifier,Boolean isOrgApprovalRequest);
String organisationIdentifier, Boolean isOrgApprovalRequest);

Organisation getOrganisationByOrgIdentifier(String organisationIdentifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import java.util.stream.Stream;

import static java.lang.Boolean.TRUE;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;
import static org.springframework.util.CollectionUtils.isEmpty;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS;
Expand Down Expand Up @@ -607,6 +608,23 @@ public OrganisationsDetailResponseV2 findByOrganisationStatusForV2Api(LocalDateT
return organisationsDetailResponse;
}

@Override
public OrganisationResponse updateOrganisationNameOrSra(
OrganisationCreationRequest organisationCreationRequest, String organisationIdentifier) {

var existingOrganisation = organisationRepository.findByOrganisationIdentifier(organisationIdentifier);
rajkatla-hmcts marked this conversation as resolved.
Show resolved Hide resolved
if (isNotBlank(organisationCreationRequest.getName())) {
existingOrganisation.setName(RefDataUtil.removeEmptySpaces(organisationCreationRequest.getName()));
}
if (isNotBlank(organisationCreationRequest.getSraId())) {
existingOrganisation.setSraId(RefDataUtil.removeEmptySpaces(organisationCreationRequest.getSraId()));
SabinaHMCTS marked this conversation as resolved.
Show resolved Hide resolved
}

var savedOrganisation = organisationRepository.save(existingOrganisation);

return new OrganisationResponse(savedOrganisation);
}

@Override
public OrganisationResponse updateOrganisation(
OrganisationCreationRequest organisationCreationRequest, String organisationIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -572,4 +573,37 @@ void testRetrieveOrgByPbaStatus() {
.getOrganisationsByPbaStatus(pbaStatus.toString());
}

@Test
void testUpdateOrgNameAndSra() {
final HttpStatus expectedHttpStatus = HttpStatus.OK;
String updatedName = "NewName";
String updatedSra = "NewSRA";
organisation.setName(updatedName);
organisation.setSraId(updatedSra);
organisationCreationRequest.setName(updatedName);
organisationCreationRequest.setSraId(updatedSra);

doNothing().when(organisationCreationRequestValidatorMock).validateOrganisationIdentifier(any(String.class));
assertThat(organisationCreationRequest.getName()).isNotEmpty();
assertThat(organisationCreationRequest.getSraId()).isNotEmpty();


when(organisationServiceMock.updateOrganisationNameOrSra(organisationCreationRequest,
organisation.getOrganisationIdentifier())).thenReturn(new OrganisationResponse(organisation));

ResponseEntity<OrganisationResponse> response = organisationInternalController
.updateOrganisationNameOrSra(organisationCreationRequest,organisation.getOrganisationIdentifier());

assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(expectedHttpStatus);
assertThat(response.getBody().getOrganisationIdentifier()).isEqualTo(organisation.getOrganisationIdentifier());


verify(organisationCreationRequestValidatorMock, times(1))
.validateOrganisationIdentifier(any(String.class));
verify(organisationServiceMock, times(1))
.updateOrganisationNameOrSra(organisationCreationRequest, organisation.getOrganisationIdentifier());

}

}
Loading