Skip to content

Commit

Permalink
[RDCC-6888]Increase Mutation Coverage for Professional API (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
manukundloo-hmcts authored Jul 13, 2023
1 parent c018c93 commit 34efcc7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,48 @@ void test_creates_professional_user_correctly() {
ProfessionalUser professionalUser = new ProfessionalUser("some-fname", "some-lname",
"some-email-address", organisation);

PrdEnumId prdEnumId = new PrdEnumId(1,"test");
PrdEnum anEnum = new PrdEnum(prdEnumId,"testenumName","testenumDescription");
UserAttribute userAttribute = new UserAttribute(professionalUser, anEnum);
List<UserAttribute> userAttributes = new ArrayList<>();
userAttributes.add(userAttribute);

professionalUser.setLastUpdated(LocalDateTime.now());
professionalUser.setCreated(LocalDateTime.now());
professionalUser.setRoles(roles);
professionalUser.setUserAttributes(userAttributes);

assertThat(professionalUser.getFirstName()).isEqualTo("some-fname");
assertThat(professionalUser.getLastName()).isEqualTo("some-lname");
assertThat(professionalUser.getEmailAddress()).isEqualTo("some-email-address");
assertThat(professionalUser.getOrganisation()).isEqualTo(organisation);
assertThat(professionalUser.getUserIdentifier()).isNull();
assertThat(professionalUser.getId()).isNull(); // hibernate generated
assertThat(professionalUser.getRoles()).hasSize(1);
assertThat(professionalUser.getRoles().get(0)).isEqualTo("pui-user-manager");
assertThat(professionalUser.getLastUpdated()).isNotNull();
assertThat(professionalUser.getCreated()).isNotNull();
assertThat(professionalUser.getUserAttributes()).isNotNull();

ProfessionalUser user = new ProfessionalUser();
assertThat(user).isNotNull();
}

@Test
void test_creates_professional_user_for_empty_user_attribute_correctly() {
List<String> roles = new ArrayList<>();
roles.add("pui-user-manager");

Organisation organisation = new Organisation();
ProfessionalUser professionalUser = new ProfessionalUser("some-fname", "some-lname",
"some-email-address", organisation);
List<UserAttribute> userAttributes = null;


professionalUser.setLastUpdated(LocalDateTime.now());
professionalUser.setCreated(LocalDateTime.now());
professionalUser.setRoles(roles);
professionalUser.setUserAttributes(userAttributes);

assertThat(professionalUser.getFirstName()).isEqualTo("some-fname");
assertThat(professionalUser.getLastName()).isEqualTo("some-lname");
Expand All @@ -37,6 +76,7 @@ void test_creates_professional_user_correctly() {
assertThat(professionalUser.getRoles().get(0)).isEqualTo("pui-user-manager");
assertThat(professionalUser.getLastUpdated()).isNotNull();
assertThat(professionalUser.getCreated()).isNotNull();
assertThat(professionalUser.getUserAttributes()).isNull();

ProfessionalUser user = new ProfessionalUser();
assertThat(user).isNotNull();
Expand All @@ -48,12 +88,19 @@ void test_toSuperUser() {
ProfessionalUser professionalUser = new ProfessionalUser("some-fname", "some-lname",
"some-email-address", organisation);

PrdEnumId prdEnumId = new PrdEnumId(1,"test");
PrdEnum anEnum = new PrdEnum(prdEnumId,"testenumName","testenumDescription");
UserAttribute userAttribute = new UserAttribute(professionalUser, anEnum);
List<UserAttribute> userAttributes = new ArrayList<>();
userAttributes.add(userAttribute);

UUID id = UUID.randomUUID();
professionalUser.setUserIdentifier(id.toString());
professionalUser.setId(id);
professionalUser.setCreated(LocalDateTime.now());
professionalUser.setLastUpdated(LocalDateTime.now());
professionalUser.setDeleted(LocalDateTime.now());
professionalUser.setUserAttributes(userAttributes);

SuperUser superUser = professionalUser.toSuperUser();
assertThat(superUser.getFirstName()).isEqualTo("some-fname");
Expand All @@ -64,5 +111,6 @@ void test_toSuperUser() {
assertThat(superUser.getId()).isNotNull();
assertThat(superUser.getLastUpdated()).isNotNull();
assertThat(superUser.getUserIdentifier()).isEqualTo(id.toString());
assertThat(professionalUser.getUserAttributes()).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ void testIsFlagEnabled() {


flaFeatureToggleService = new FeatureToggleServiceImpl(ldClient, "rd");
assertFalse(flaFeatureToggleService.isFlagEnabled("test", "test"));
assertFalse(flaFeatureToggleService.isFlagEnabled("test1", "test1"));
}

@Test
void testIsFlagEnabledFalse() {
when(flaFeatureToggleService.isFlagEnabled("test1", "test1")).thenReturn(false);
assertFalse(flaFeatureToggleService.isFlagEnabled("test1", "test1"));

flaFeatureToggleService = new FeatureToggleServiceImpl(ldClient, "rd1");
assertFalse(flaFeatureToggleService.isFlagEnabled("test1", "test1"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MSG_PARTIAL_SUCCESS;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.LENGTH_OF_ORGANISATION_IDENTIFIER;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_NAME;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ORG_STATUS;
import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.PBA_STATUS_MESSAGE_AUTO_ACCEPTED;
import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.ACTIVE;
import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.BLOCKED;
import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.REVIEW;
import static uk.gov.hmcts.reform.professionalapi.domain.PbaStatus.ACCEPTED;
import static uk.gov.hmcts.reform.professionalapi.domain.PbaStatus.PENDING;
Expand Down Expand Up @@ -322,7 +324,7 @@ void test_addDefaultMfaStatusToOrganisation() {

sut.addDefaultMfaStatusToOrganisation(organisationMock);

verify(organisationMock, times(1)).setOrganisationMfaStatus(any(OrganisationMfaStatus.class));
verify(organisationMock, times(1)).setOrganisationMfaStatus(any());
}

@Test
Expand Down Expand Up @@ -602,7 +604,10 @@ void test_RetrieveAnOrganisationsByStatusAndPagination() throws JsonProcessingEx
false);
String body = mapper.writeValueAsString(professionalUsersEntityResponse);

Pageable pageable = PageRequest.of(1,2, Sort.by(Sort.DEFAULT_DIRECTION, ORG_NAME));
var order = new Sort.Order(Sort.DEFAULT_DIRECTION, ORG_STATUS).ignoreCase();
var name = new Sort.Order(Sort.DEFAULT_DIRECTION, ORG_NAME).ignoreCase();

Pageable pageable = PageRequest.of(1,2, Sort.by(order).and(Sort.by(name)));
Page<Organisation> orgPage = (Page<Organisation>) mock(Page.class);

when(organisationRepository.findByStatusIn(List.of(ACTIVE), pageable)).thenReturn(orgPage);
Expand Down Expand Up @@ -640,7 +645,7 @@ void test_RetrieveOrganisationsByPendingAndReviewStatusAndPagination() throws Js
"REVIEW", null, null, null);
Organisation reviewOrganisation3 = new Organisation("some-review-org-name3", OrganisationStatus.PENDING,
"REVIEW", null, null, null);
Organisation pendingOrganisation3 = new Organisation("some-pending-org-name3", REVIEW,
Organisation pendingOrganisation3 = new Organisation("some-pending-org-name3", BLOCKED,
"PENDING", null, null, null);


Expand All @@ -652,24 +657,30 @@ void test_RetrieveOrganisationsByPendingAndReviewStatusAndPagination() throws Js
organisations.add(pendingOrganisation3);
organisations.add(reviewOrganisation3);

Pageable pageable = PageRequest.of(1,2, Sort.by(Sort.DEFAULT_DIRECTION, ORG_NAME));
var order = new Sort.Order(Sort.DEFAULT_DIRECTION, ORG_STATUS).ignoreCase();
var name = new Sort.Order(Sort.DEFAULT_DIRECTION, ORG_NAME).ignoreCase();

Pageable pageable = PageRequest.of(1,2, Sort.by(order).and(Sort.by(name)));

Page<Organisation> orgPage = (Page<Organisation>) mock(Page.class);

when(organisationRepository.findByStatusIn(List.of(OrganisationStatus.PENDING, REVIEW), pageable))
when(organisationRepository.findByStatusIn(List.of(OrganisationStatus.PENDING, REVIEW,BLOCKED), pageable))
.thenReturn(orgPage);
when(orgPage.getContent()).thenReturn(organisations);
when(orgPage.getTotalElements()).thenReturn(1L);


String status = "PENDING,REVIEW";
String status = "PENDING,REVIEW,blocked";
OrganisationsDetailResponse organisationDetailResponse
= sut.findByOrganisationStatus(status, pageable);



assertThat(organisationDetailResponse).isNotNull();
verify(organisationRepository, times(1))
.findByStatusIn(List.of(OrganisationStatus.PENDING,REVIEW), pageable);
.findByStatusIn(List.of(OrganisationStatus.PENDING,REVIEW,BLOCKED), pageable);
assertThat(organisationDetailResponse.getTotalRecords()).isPositive();

}

@Test
Expand Down Expand Up @@ -1159,6 +1170,22 @@ void test_addPaymentAccountsToOrganisation() {
verify(professionalUserServiceMock, times(1)).checkUserStatusIsActiveByUserId(any());
}


@Test
void test_addPaymentAccountsToOrganisationForNullRequest() {
PbaRequest pbaRequest = new PbaRequest();
pbaRequest.setPaymentAccounts(null);

organisation.setStatus(OrganisationStatus.ACTIVE);
organisation.setUsers(asList(superUser));
when(organisationRepository.findByOrganisationIdentifier(any())).thenReturn(organisation);

String orgId = UUID.randomUUID().toString().substring(0, 7);
String userId = UUID.randomUUID().toString();
assertThrows(InvalidRequest.class, () ->
sut.addPaymentAccountsToOrganisation(pbaRequest, orgId, userId));
}

@Test
void test_addPaymentAccountsToOrganisation_pba_invalid() {
var pbas = new HashSet<String>();
Expand Down Expand Up @@ -1266,6 +1293,7 @@ void should_add_contact_informations_to_organisation() {
}


@Test
void test_sortContactInfoByCreatedDateAsc() {
var contactInformation = new ContactInformation();
contactInformation.setCountry("TestCountry");
Expand Down

0 comments on commit 34efcc7

Please sign in to comment.