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 2140 #1583

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9a50a6d
Upgrading perftest branch to V16 and adding subnet_suffix
SabinaHMCTS Dec 11, 2023
a7e03dd
End point to delete Payment account for an organisation
SabinaHMCTS Feb 9, 2024
3c3c8b0
unit tests added
aneesaHMCTS May 9, 2024
079a36a
Merge branch 'master' into DTSRD-2140
aneesaHMCTS May 9, 2024
32334dd
unit tests added
aneesaHMCTS May 22, 2024
44e0348
Merge branch 'master' into DTSRD-2140
SabinaHMCTS May 22, 2024
86f7180
Add Pact state for calls to ProfessionalUserService.findUserStatusByE…
jthmcts May 23, 2024
f9127ca
DTSRD-2525: handle flyway out of order (#1613)
kiran-yenigala-hmcts May 23, 2024
7edaedb
Add out of order to db migration (#1614)
kiran-yenigala-hmcts May 23, 2024
df8f113
End point to delete Payment account for an organisation
SabinaHMCTS Feb 9, 2024
8fe15f3
unit tests added
aneesaHMCTS May 9, 2024
55c4eca
Merge branch 'master' into DTSRD-2140
aneesaHMCTS May 28, 2024
c7061b2
Fix functional tests
chi-rd1 May 31, 2024
e44d1a1
Fix functional tests
chi-rd1 May 31, 2024
1395bbe
Fix functional tests
chi-rd1 May 31, 2024
a62cb16
update admin unit tests
SabinaHMCTS Jun 19, 2024
06d015b
update admin unit tests
SabinaHMCTS Jun 19, 2024
e1bbd1c
Merge branch 'master' into DTSRD-2140
SabinaHMCTS Jun 19, 2024
82d3290
update admin unit tests
SabinaHMCTS Jun 19, 2024
80d5dd2
update admin functional tests
SabinaHMCTS Jun 21, 2024
1f6254a
update admin functional tests
SabinaHMCTS Jun 24, 2024
09af566
update admin functional tests
SabinaHMCTS Jun 24, 2024
c0071af
update admin functional tests
SabinaHMCTS Jun 24, 2024
90b15c6
update functional tests
SabinaHMCTS Jun 25, 2024
105f7a3
update functional tests
SabinaHMCTS Jul 16, 2024
ace6c6b
update pact tests
SabinaHMCTS Jul 16, 2024
3e318ee
update pact tests
SabinaHMCTS Jul 16, 2024
102219a
update functional tests
SabinaHMCTS Jul 17, 2024
582530e
Updating Terraform Formatting
hmcts-jenkins-j-to-z[bot] Jul 17, 2024
9a1d5a3
update pact tests
SabinaHMCTS Jul 17, 2024
a6d93b3
update pact tests
SabinaHMCTS Jul 17, 2024
a7cee3c
Updating Terraform Formatting
hmcts-jenkins-j-to-z[bot] Jul 17, 2024
5868e2d
update infrastructure tests
SabinaHMCTS Jul 17, 2024
359748f
Updating Terraform Formatting
hmcts-jenkins-j-to-z[bot] Jul 17, 2024
6b4cb25
update infrastructure tests
SabinaHMCTS Jul 17, 2024
eb47f62
Merge branch 'master' into DTSRD-2140
SabinaHMCTS Jul 17, 2024
88a26ae
update functional tests
SabinaHMCTS Jul 17, 2024
25f64fb
Merge branch 'master' into DTSRD-2140
SabinaHMCTS Jul 19, 2024
b65f862
Merge branch 'master' into DTSRD-2140
SabinaHMCTS Jul 26, 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 @@ -622,7 +622,7 @@ void updateOrgMfaShouldReturn403WhenToggledOff() {
log.info("updateOrgMFAShouldReturn403 :: END");
}

public void updateOrgStatusScenarios() {
public void updateOrgStatusScenarios() {
updateOrgStatusShouldBeSuccess();
}

Expand Down Expand Up @@ -785,7 +785,7 @@ void findOrganisationsWithPaginationShouldReturnSuccess() {
log.info("findOrganisationsWithPaginationShouldReturnSuccess :: STARTED");
professionalApiClient.createOrganisation();
Map<String, Object> organisations = professionalApiClient
.retrieveAllOrganisationsWithPagination(hmctsAdmin, "1", "2");
.retrieveAllOrganisationsWithPagination(hmctsAdmin, "1", "2");

assertThat(organisations).isNotNull().hasSize(2);

Expand Down Expand Up @@ -1231,4 +1231,59 @@ private static List<Map<String, Object>> sortByValue(final List<Map<String, Obje
.sorted(Comparator.comparing(map -> (String) map.get(key)))
.collect(Collectors.toList());
}

@Test
@ToggleEnable(mapKey = "OrganisationExternalController.deletePaymentAccountsOfOrganisation", withFeature = true)
@ExtendWith(FeatureToggleConditionExtension.class)
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
void deletePbaOfExistingOrganisationShouldBeForbiddenWhenLDOff() {
log.info("deletePbaOfExistingOrganisationShouldBeForbiddenWhenLDOff :: STARTED");

Set<String> paymentAccounts = new HashSet<>();
paymentAccounts.add("PBA0000021");
paymentAccounts.add("PBA0000022");
paymentAccounts.add("PBA0000023");

setUpTestData();
setUpUserBearerTokens(List.of(puiFinanceManager));

PbaRequest deletePbaRequest = new PbaRequest();
deletePbaRequest.setPaymentAccounts(Set.of("PBA0000021", "PBA0000022", "PBA0000023"));

String pfmBearerTokens = null;
professionalApiClient.deletePaymentAccountsOfOrganisation(deletePbaRequest,
Copy link
Contributor

Choose a reason for hiding this comment

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

this line making a call to existing external endpoint, so this test is invalid. make change to call new internal endpoint with prd-admin user

professionalApiClient.getMultipleAuthHeaders(null), FORBIDDEN);

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

private void setUpUserBearerTokens(List<String> puiFinanceManager) {
}

@Test
//@ToggleEnable(mapKey = "OrganisationExternalController.deletePaymentAccountsOfOrganisation", withFeature = true)
//@ExtendWith(FeatureToggleConditionExtension.class)
void deletePbaOfExistingOrganisationShouldBeSuccess() {
log.info("deletePbaOfExistingOrganisationShouldBeSuccess :: STARTED");



setUpTestData();
setUpUserBearerTokens(List.of(puiFinanceManager));

PbaRequest deletePbaRequest = new PbaRequest();
deletePbaRequest.setPaymentAccounts(organisationCreationRequest.getPaymentAccount());

String pfmBearerToken = null;
professionalApiClient.deletePaymentAccountsOfOrganisation(deletePbaRequest,
Copy link
Contributor

Choose a reason for hiding this comment

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

this line making a call to existing external endpoint, so this test is invalid. make change to call new internal endpoint with prd-admin user

professionalApiClient.getMultipleAuthHeaders(null), NO_CONTENT);

Map<String, Object> response = professionalApiClient.retrieveOrganisationByOrgIdExternal(OK,
professionalApiClient.getMultipleAuthHeaders(null));

var paymentAccounts = (List<String>) response.get("paymentAccount");
assertThat(paymentAccounts).isEmpty();
log.info("deletePbaOfExistingOrganisationShouldBeSuccess :: END");
}
}

2 changes: 1 addition & 1 deletion src/integrationTest/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring:
flyway:
schemas: DBREFDATA
locations: classpath:db/testmigration

jpa:
show-sql: true
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ protected ResponseEntity<List<OrganisationMinimalInfoResponse>> retrieveAllOrgan

var organisationMinimalInfoResponses =
organisations.stream()
.map(organisation -> new OrganisationMinimalInfoResponse(organisation, address))
.collect(Collectors.toList());
.map(organisation -> new OrganisationMinimalInfoResponse(organisation, address)).toList();

return ResponseEntity.status(200).body(organisationMinimalInfoResponses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@

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.DEL_ORG_PBA_NOTES_1;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DEL_ORG_PBA_NOTES_2;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DEL_ORG_PBA_NOTES_3;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DEL_ORG_PBA_NOTES_4;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.DEL_ORG_PBA_NOTES_5;
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;
Expand Down Expand Up @@ -697,6 +702,65 @@ public ResponseEntity<OrganisationEntityResponse> retrieveOrganisationByUserId(
return organisationService.retrieveOrganisationByUserId(userId);
}



@Operation(
summary = "Deletes the provided list of payment accounts from the organisation.",
description = "**IDAM Roles to access API** : <br> - pui-finance-manager",
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong role , it should be prd-admin

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

security = {
@SecurityRequirement(name = "ServiceAuthorization"),
@SecurityRequirement(name = "Authorization")
}
)
@ApiResponse(
responseCode = "204",
description = "Successfully deleted the list of provided payment accounts from the organisation.",
content = @Content
)
@ApiResponse(
responseCode = "400",
description = DEL_ORG_PBA_NOTES_1 + DEL_ORG_PBA_NOTES_2 + DEL_ORG_PBA_NOTES_3
+ DEL_ORG_PBA_NOTES_4 + DEL_ORG_PBA_NOTES_5,
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 for either invalid permissions or user is pending",
content = @Content
)
@ApiResponse(
responseCode = "404",
description = "Resource Not Found Error: The Organisation does not exist"
+ " to delete Payment Accounts from",
content = @Content
)
@ApiResponse(
responseCode = "500",
description = "Internal Server Error",
content = @Content
)

@DeleteMapping(path = "/pba/{orgId}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@Secured({"prd-admin"})
public void deletePaymentAccountsOfOrganisation(
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "deletePbaRequest")
@Valid @NotNull @RequestBody PbaRequest deletePbaRequest,
@PathVariable("orgId") @NotBlank String organisationIdentifier,
@Parameter(hidden = true) @UserId String userId) {

deletePaymentAccountsOfGivenOrganisation(deletePbaRequest, organisationIdentifier, userId);

}


@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 @@ -745,4 +809,5 @@ public ResponseEntity<Object> retrieveOrganisationsByProfileIds(
.status(HttpStatus.OK)
.body(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS;


@ExtendWith(MockitoExtension.class)
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
class OrganisationInternalControllerTest {
Expand Down Expand Up @@ -109,8 +110,14 @@ class OrganisationInternalControllerTest {
private List<PrdEnum> prdEnumList;

private ProfessionalUser professionalUser;
private OrganisationIdentifierValidatorImpl organisationIdentifierValidatorImplMock;


private NewUserCreationRequest newUserCreationRequest;
private UserProfileFeignClient userProfileFeignClient;



private DeleteOrganisationResponse deleteOrganisationResponse;
HttpServletRequest httpRequest = mock(HttpServletRequest.class);

Expand All @@ -120,6 +127,8 @@ class OrganisationInternalControllerTest {
@InjectMocks
private OrganisationInternalControllerV2 organisationInternalControllerV2;



@BeforeEach
void setUp() throws Exception {
organisation = new Organisation("Org-Name", OrganisationStatus.PENDING, "sra-id",
Expand All @@ -137,6 +146,7 @@ void setUp() throws Exception {
new OrganisationEntityResponse(organisation, false, true, true);

organisationServiceMock = mock(OrganisationService.class);
//organisationIdentifierValidatorImplMock = mock(OrganisationIdentifierValidatorImpl.class);
professionalUserServiceMock = mock(ProfessionalUserService.class);
paymentAccountServiceMock = mock(PaymentAccountService.class);
organisationCreationRequestValidatorMock = mock(OrganisationCreationRequestValidator.class);
Expand Down Expand Up @@ -572,4 +582,46 @@ void testRetrieveOrgByPbaStatus() {
.getOrganisationsByPbaStatus(pbaStatus.toString());
}





@Test
void testDeletePaymentAccounts() {
PbaRequest deletePbaRequest = new PbaRequest();
var accountsToDelete = new HashSet<String>();
accountsToDelete.add("PBA1234567");
deletePbaRequest.setPaymentAccounts(accountsToDelete);
final List<PaymentAccount> paymentAccounts = new ArrayList<>();
paymentAccounts.add(new PaymentAccount());
organisation.setPaymentAccounts(paymentAccounts);
when(organisationServiceMock.getOrganisationByOrgIdentifier(anyString())).thenReturn(organisation);

String orgId = UUID.randomUUID().toString().substring(0, 7);
String userId = UUID.randomUUID().toString();
organisationInternalController
.deletePaymentAccountsOfOrganisation(deletePbaRequest, orgId, userId);

verify(professionalUserServiceMock, times(1))
.checkUserStatusIsActiveByUserId(anyString());
verify(orgIdValidatorMock, times(1))
.validateOrganisationIsActive(any(Organisation.class), any(HttpStatus.class));
verify(paymentAccountServiceMock, times(1))
.deletePaymentsOfOrganisation(any(PbaRequest.class), any(Organisation.class));

}


@Test
void test_deletePaymentAccounts_NoPaymentAccountsPassed() {
PbaRequest deletePbaRequest = new PbaRequest();
var accountsToDelete = new HashSet<String>();
deletePbaRequest.setPaymentAccounts(accountsToDelete);
String orgId = UUID.randomUUID().toString().substring(0, 7);
String userId = UUID.randomUUID().toString();
assertThrows(InvalidRequest.class,() ->
organisationInternalController
.deletePaymentAccountsOfOrganisation(deletePbaRequest, orgId, userId));

}
}