Skip to content

Commit

Permalink
Add call into new handling to remove duplicate execs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-saunders-cts committed Nov 27, 2024
1 parent 2bff617 commit e93534a
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public void transformForSolicitorApplicationCompletion(CallbackRequest callbackR


public void transformCaseDataForValidateProbate(CallbackRequest callbackRequest) {
final var caseData = callbackRequest.getCaseDetails().getData();
final var caseDetails = callbackRequest.getCaseDetails();
final var caseData = caseDetails.getData();

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

resetCaseDataTransformer.resetExecutorLists(caseData);
solicitorApplicationCompletionTransformer.setFieldsIfSolicitorIsNotNamedInWillAsAnExecutor(caseData);
solicitorApplicationCompletionTransformer.mapSolicitorExecutorFieldsOnAppDetailsComplete(caseData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import java.util.List;

import static uk.gov.hmcts.probate.model.ApplicationState.CASE_PRINTED;
import static uk.gov.hmcts.probate.model.Constants.CASE_TYPE_GRANT_OF_PROBATE;
import static uk.gov.hmcts.probate.model.Constants.NO;
import static uk.gov.hmcts.probate.model.Constants.TITLE_AND_CLEARING_NONE_OF_THESE;

@Component
@Slf4j
Expand Down Expand Up @@ -69,4 +71,30 @@ public void setFieldsOnServiceRequest(CaseDetails caseDetails, BigDecimal totalA
caseDetails.setState(CASE_PRINTED.getId());
}
}

public void clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(CaseDetails caseDetails) {
if (featureToggleService.enableDuplicateExecutorFiltering()) {
final var caseId = caseDetails.getId();
final var caseData = caseDetails.getData();

final var titleAndClearingType = caseData.getTitleAndClearingType();
final var caseType = caseData.getCaseType();

final var primaryApplicantApplying = caseData.isPrimaryApplicantApplying();
final var isNotNoneOfTheseTCT = titleAndClearingType != null
&& !TITLE_AND_CLEARING_NONE_OF_THESE.equalsIgnoreCase(titleAndClearingType);
final var isGrantOfProbate = CASE_TYPE_GRANT_OF_PROBATE.equalsIgnoreCase(caseType);

if (isNotNoneOfTheseTCT
&& primaryApplicantApplying
&& isGrantOfProbate) {
log.info("In GrantOfProbate case {} we have primary applicant applying for non-NoneOfThese "
+ "TitleAndClearingType {}, clear PrimaryApplicant fields",
caseId,
titleAndClearingType);

caseData.clearPrimaryApplicant();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.probate.model.Constants.CASE_TYPE_GRANT_OF_PROBATE;
import static uk.gov.hmcts.probate.model.Constants.TITLE_AND_CLEARING_NONE_OF_THESE;
import static uk.gov.hmcts.probate.model.Constants.TITLE_AND_CLEARING_TRUST_CORP;
import static uk.gov.hmcts.probate.util.CommonVariables.ADDITIONAL_EXECUTOR_APPLYING;
import static uk.gov.hmcts.probate.util.CommonVariables.ADDITIONAL_EXECUTOR_NOT_APPLYING;
Expand Down Expand Up @@ -260,4 +264,121 @@ void shouldSetPaymentTakenNotApplicableWhenNoServiceRequest() {

assertEquals(NOT_APPLICABLE, caseData.getPaymentTaken());
}

// given Case
// and CaseType is GrantOfProbate
// and TitleClearingType is not NoneOfThese
// and PrimaryApplicantApplying is true
// when transformer clearPrimaryForNoneOfThese called
// then primaryApplicantClear is called
@Test
void givenCaseWithoutNoneOfTheseTitleClearingTypeANDPrimaryApplicant_whenChecked_thenPrimaryApplicantDataCleared() {
final CaseData caseData = mock(CaseData.class);
final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L);

when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true);

when(caseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE);
when(caseData.getTitleAndClearingType()).thenReturn("");
when(caseData.isPrimaryApplicantApplying()).thenReturn(true);

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

verify(caseData, times(1)).clearPrimaryApplicant();
}

// given Case
// and CaseType is NOT GrantOfProbate
// and TitleClearingType is not NoneOfThese
// and PrimaryApplicantApplying is true
// when transformer clearPrimaryForNoneOfThese called
// then primaryApplicantClear is NOT called
@Test
void givenCaseNotGOPWoutNoneOfTheseTCTypeANDPrimaryApplicant_whenChecked_thenPrimaryApplicantDataNOTCleared() {
final CaseData caseData = mock(CaseData.class);
final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L);

when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true);

when(caseData.getCaseType()).thenReturn("");
when(caseData.getTitleAndClearingType()).thenReturn("");
when(caseData.isPrimaryApplicantApplying()).thenReturn(true);

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

verify(caseData, times(0)).clearPrimaryApplicant();
}

// given Case
// and CaseType is GrantOfProbate
// and TitleClearingType is NoneOfThese
// and PrimaryApplicantApplying is true
// when transformer clearPrimaryForNoneOfThese called
// then primaryApplicantClear is not called
@Test
void givenCaseWithNoneOfTheseTitleClearingTypeANDPrimaryApplicant_whenChecked_thenPrimaryApplicantDataNOTCleared() {
final CaseData caseData = mock(CaseData.class);
final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L);

when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true);

when(caseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE);
when(caseData.getTitleAndClearingType()).thenReturn(TITLE_AND_CLEARING_NONE_OF_THESE);
when(caseData.isPrimaryApplicantApplying()).thenReturn(true);

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

verify(caseData, times(0)).clearPrimaryApplicant();
}

// given Case
// and CaseType is GrantOfProbate
// and TitleClearingType is not NoneOfThese
// and PrimaryApplicantApplying is false
// when transformer clearPrimaryForNoneOfThese called
// then primaryApplicantClear is not called
@Test
void givenCaseWoutNoneOfTheseTitleClearingTypeANDWoutPrmryApplicant_whenChecked_thenPrmryApplicantDataNOTCleared() {
final CaseData realCaseData = CaseData.builder().build();
final CaseData spyCaseData = spy(realCaseData);
final CaseDetails caseDetails = new CaseDetails(spyCaseData, null, 0L);

when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(true);

when(spyCaseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE);
when(spyCaseData.getTitleAndClearingType()).thenReturn("");
when(spyCaseData.isPrimaryApplicantApplying()).thenReturn(false);

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

verify(spyCaseData, times(0)).clearPrimaryApplicant();
}

// given Case
// and CaseType is GrantOfProbate
// and TitleClearingType is not NoneOfThese
// and PrimaryApplicantApplying is true
// and enableDuplicateApplicant is false
// when transformer clearPrimaryForNoneOfThese called
// then primaryApplicantClear is called
@Test
void givenCaseWithoutNoneOfTheseTtlClrngTypeANDPrmryApplANDDuplDisabled_whenChecked_thenPrmryApplDataNOTCleared() {
final CaseData caseData = mock(CaseData.class);
final CaseDetails caseDetails = new CaseDetails(caseData, null, 0L);

when(featureToggleServiceMock.enableDuplicateExecutorFiltering()).thenReturn(false);

when(caseData.getCaseType()).thenReturn(CASE_TYPE_GRANT_OF_PROBATE);
when(caseData.getTitleAndClearingType()).thenReturn("");
when(caseData.isPrimaryApplicantApplying()).thenReturn(true);

solicitorApplicationCompletionTransformer.clearPrimaryApplicantWhenNotInNoneOfTheseTitleAndClearingType(
caseDetails);

verify(caseData, times(0)).clearPrimaryApplicant();
}
}

0 comments on commit e93534a

Please sign in to comment.