Skip to content

Commit

Permalink
SSCSSI-95: C1b: updateCaseOnly - ReIssueFurtherEvidenceHandler (#4118)
Browse files Browse the repository at this point in the history
* SSCSSI-95: C1b: updateCaseOnly - ReIssueFurtherEvidenceHandler

* SSCSSI-95: C1b: updateCaseOnly - ReIssueFurtherEvidenceHandler

* SSCSSI-95: C1b: updateCaseOnly - ReIssueFurtherEvidenceHandler

* SSCSSI-95: C1b: updateCaseOnly - ReIssueFurtherEvidenceHandler

---------

Co-authored-by: gokul <[email protected]>
  • Loading branch information
srochani and gokul-sol authored Nov 14, 2024
1 parent 553a82d commit 4dcdd65
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Stream;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.sscs.callback.CallbackHandler;
import uk.gov.hmcts.reform.sscs.ccd.callback.Callback;
Expand All @@ -15,6 +16,7 @@
import uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType;
import uk.gov.hmcts.reform.sscs.ccd.domain.*;
import uk.gov.hmcts.reform.sscs.ccd.service.CcdService;
import uk.gov.hmcts.reform.sscs.ccd.service.UpdateCcdCaseService;
import uk.gov.hmcts.reform.sscs.evidenceshare.domain.FurtherEvidenceLetterType;
import uk.gov.hmcts.reform.sscs.evidenceshare.service.FurtherEvidenceService;
import uk.gov.hmcts.reform.sscs.idam.IdamService;
Expand All @@ -25,14 +27,20 @@ public class ReissueFurtherEvidenceHandler implements CallbackHandler<SscsCaseDa
private final FurtherEvidenceService furtherEvidenceService;
private final CcdService ccdService;
private final IdamService idamService;
private final UpdateCcdCaseService updateCcdCaseService;

@Value("${feature.update-case-only-hearing-v2.enabled}")
private boolean updateCaseOnlyHearingV2Enabled;

@Autowired
public ReissueFurtherEvidenceHandler(FurtherEvidenceService furtherEvidenceService,
CcdService ccdService,
IdamService idamService) {
IdamService idamService,
UpdateCcdCaseService updateCcdCaseService) {
this.furtherEvidenceService = furtherEvidenceService;
this.ccdService = ccdService;
this.idamService = idamService;
this.updateCcdCaseService = updateCcdCaseService;
}

@Override
Expand Down Expand Up @@ -118,9 +126,14 @@ private void udateCaseForReasonableAdjustments(SscsCaseData caseData, AbstractDo
final SscsCaseDetails sscsCaseDetails = ccdService.getByCaseId(Long.valueOf(caseData.getCcdCaseId()), idamService.getIdamTokens());
caseData = sscsCaseDetails.getData();
}
setEvidenceIssuedFlagToYes(selectedDocument);
setReissueFlagsToNull(caseData);
updateCase(caseData, selectedDocument);

if (updateCaseOnlyHearingV2Enabled) {
updateCaseV2(caseData, selectedDocument);
} else {
setEvidenceIssuedFlagToYes(selectedDocument);
setReissueFlagsToNull(caseData);
updateCase(caseData, selectedDocument);
}
}

private List<FurtherEvidenceLetterType> getAllowedFurtherEvidenceLetterTypes(SscsCaseData caseData) {
Expand Down Expand Up @@ -195,6 +208,22 @@ private void setEvidenceIssuedFlagToYes(AbstractDocument doc) {
}
}

private void updateCaseV2(final SscsCaseData caseData, AbstractDocument selectedDocument) {

updateCcdCaseService.updateCaseV2(
Long.valueOf(caseData.getCcdCaseId()),
EventType.UPDATE_CASE_ONLY.getCcdType(),
"Update case data only",
determineDescription(selectedDocument),
idamService.getIdamTokens(),
sscsCaseDetails -> {
final AbstractDocument documentIssuedFlagToYes =
getSelectedDocumentInUiFromCaseData(sscsCaseDetails.getData(), sscsCaseDetails.getData().getReissueArtifactUi());
setEvidenceIssuedFlagToYes(documentIssuedFlagToYes);
setReissueFlagsToNull(sscsCaseDetails.getData());
});
}

private void updateCase(SscsCaseData caseData, AbstractDocument selectedDocument) {

ccdService.updateCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Rule;
Expand All @@ -23,11 +24,13 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.springframework.test.util.ReflectionTestUtils;
import uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType;
import uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType;
import uk.gov.hmcts.reform.sscs.ccd.domain.*;
import uk.gov.hmcts.reform.sscs.ccd.exception.RequiredFieldMissingException;
import uk.gov.hmcts.reform.sscs.ccd.service.CcdService;
import uk.gov.hmcts.reform.sscs.ccd.service.UpdateCcdCaseService;
import uk.gov.hmcts.reform.sscs.evidenceshare.domain.FurtherEvidenceLetterType;
import uk.gov.hmcts.reform.sscs.evidenceshare.service.FurtherEvidenceService;
import uk.gov.hmcts.reform.sscs.idam.IdamService;
Expand All @@ -46,13 +49,18 @@ public class ReissueFurtherEvidenceHandlerTest {
private IdamService idamService;
@Mock
private CcdService ccdService;
@Mock
private UpdateCcdCaseService updateCcdCaseService;

@InjectMocks
private ReissueFurtherEvidenceHandler handler;

@Captor
ArgumentCaptor<SscsCaseData> captor;

@Captor
private ArgumentCaptor<Consumer<SscsCaseDetails>> sscsCaseDetailsCaptor;

@Test(expected = NullPointerException.class)
public void givenCallbackIsNull_whenHandleIsCalled_shouldThrowException() {
handler.handle(CallbackType.SUBMITTED, null);
Expand Down Expand Up @@ -228,6 +236,100 @@ public void givenIssueFurtherEvidenceCallback_shouldReissueEvidenceForAppellantA

}

@Test
@Parameters({"APPELLANT_EVIDENCE, true, true, true",
"REPRESENTATIVE_EVIDENCE, false, false, true",
"DWP_EVIDENCE, true, true, true",
"APPELLANT_EVIDENCE, true, false, true",
"APPELLANT_EVIDENCE, false, true, true",
"APPELLANT_EVIDENCE, true, true, false",
"APPELLANT_EVIDENCE, true, false, false",
"APPELLANT_EVIDENCE, false, true, false"
})
public void givenIssueFurtherEvidenceCallback_shouldReissueEvidenceForAppellantAndRepAndDwpAndV2Enabled(DocumentType documentType,
boolean resendToAppellant,
boolean resendToRepresentative,
boolean isEnglish) {
ReflectionTestUtils.setField(handler, "updateCaseOnlyHearingV2Enabled", true);

if (resendToAppellant || resendToRepresentative) {
when(idamService.getIdamTokens()).thenReturn(IdamTokens.builder().build());
}

given(furtherEvidenceService.canHandleAnyDocument(any())).willReturn(true);

AbstractDocument sscsDocumentNotIssued = null;
if (isEnglish) {
sscsDocumentNotIssued = SscsDocument.builder()
.value(SscsDocumentDetails.builder()
.documentLink(DocumentLink.builder().documentUrl("www.acme.co.uk").build())
.documentType(documentType.getValue())
.evidenceIssued("No")
.build())
.build();
} else {
sscsDocumentNotIssued = SscsWelshDocument.builder()
.value(SscsWelshDocumentDetails.builder()
.documentLink(DocumentLink.builder().documentUrl("www.acme.co.uk").build())
.documentType(documentType.getValue())
.evidenceIssued("No")
.build())
.build();
}


DynamicListItem dynamicListItem = new DynamicListItem(
sscsDocumentNotIssued.getValue().getDocumentLink().getDocumentUrl(), "a label");
DynamicList dynamicList = new DynamicList(dynamicListItem, Collections.singletonList(dynamicListItem));
SscsCaseData caseData = SscsCaseData.builder()
.ccdCaseId("1563382899630221")
.appeal(Appeal.builder().rep(Representative.builder().hasRepresentative("YES").build()).build())
.reissueArtifactUi(ReissueArtifactUi.builder()
.reissueFurtherEvidenceDocument(dynamicList)
.resendToAppellant(resendToAppellant ? YesNo.YES : YesNo.NO)
.resendToRepresentative(resendToRepresentative ? YesNo.YES : YesNo.NO)
.build())
.build();
SscsCaseDetails sscsCaseDetails = SscsCaseDetails.builder().data(caseData).build();

if (isEnglish) {
caseData.setSscsDocument(Collections.singletonList((SscsDocument) sscsDocumentNotIssued));
} else {
caseData.setSscsWelshDocuments(Collections.singletonList((SscsWelshDocument) sscsDocumentNotIssued));
}

handler.handle(CallbackType.SUBMITTED,
HandlerHelper.buildTestCallbackForGivenData(caseData, INTERLOCUTORY_REVIEW_STATE, REISSUE_FURTHER_EVIDENCE));

verify(furtherEvidenceService).canHandleAnyDocument(eq(caseData.getSscsDocument()));

List<FurtherEvidenceLetterType> allowedLetterTypes = new ArrayList<>();
if (resendToAppellant) {
allowedLetterTypes.add(FurtherEvidenceLetterType.APPELLANT_LETTER);
}
if (resendToRepresentative) {
allowedLetterTypes.add(FurtherEvidenceLetterType.REPRESENTATIVE_LETTER);
}

verify(furtherEvidenceService).issue(eq(Collections.singletonList(sscsDocumentNotIssued)), eq(caseData), eq(documentType), eq(allowedLetterTypes), eq(null));

verifyNoMoreInteractions(furtherEvidenceService);

if (resendToAppellant || resendToRepresentative) {
verify(updateCcdCaseService).updateCaseV2(any(Long.class), eq(EventType.UPDATE_CASE_ONLY.getCcdType()),
any(), any(), any(IdamTokens.class), sscsCaseDetailsCaptor.capture());
sscsCaseDetailsCaptor.getValue().accept(sscsCaseDetails);
if (isEnglish) {
assertEquals("Yes", sscsCaseDetails.getData().getSscsDocument().get(0).getValue().getEvidenceIssued());
} else {
assertEquals("Yes", sscsCaseDetails.getData().getSscsWelshDocuments().get(0).getValue().getEvidenceIssued());
}
} else {
verifyNoInteractions(updateCcdCaseService);
}

}

@Test
@Parameters({"APPELLANT_EVIDENCE, true, true, true, false, false",
"REPRESENTATIVE_EVIDENCE, false, false, true, false, false",
Expand Down Expand Up @@ -347,6 +449,130 @@ public void givenIssueFurtherEvidenceCallback_shouldReissueEvidenceForAppellantA

}

@Test
@Parameters({"APPELLANT_EVIDENCE, true, true, true, false, false",
"REPRESENTATIVE_EVIDENCE, false, false, true, false, false",
"DWP_EVIDENCE, true, true, true, false, false",
"APPELLANT_EVIDENCE, true, false, true, false, false",
"APPELLANT_EVIDENCE, false, true, true, false, false",
"APPELLANT_EVIDENCE, true, true, false, false, true",
"APPELLANT_EVIDENCE, true, false, false, false, false",
"APPELLANT_EVIDENCE, false, true, false, false, false",
"APPELLANT_EVIDENCE, true, true, true, true, false",
"REPRESENTATIVE_EVIDENCE, false, false, true, true, true",
"REPRESENTATIVE_EVIDENCE, false, false, true, false, true",
"REPRESENTATIVE_EVIDENCE, false, false, true, true, false",
"DWP_EVIDENCE, true, true, true, true, false",
"APPELLANT_EVIDENCE, true, false, true, true, true",
"APPELLANT_EVIDENCE, false, true, true, true, false",
"APPELLANT_EVIDENCE, true, true, false, true, false",
"APPELLANT_EVIDENCE, true, false, false, true, false",
"APPELLANT_EVIDENCE, false, true, false, true, false",
"OTHER_PARTY_EVIDENCE, true, true, true, true, false",
"OTHER_PARTY_EVIDENCE, false, false, true, true, true",
"OTHER_PARTY_EVIDENCE, false, false, true, false, true",
"OTHER_PARTY_EVIDENCE, false, false, true, true, false",
"OTHER_PARTY_EVIDENCE, true, true, true, true, false",
"OTHER_PARTY_REPRESENTATIVE_EVIDENCE, true, false, true, true, true",
"OTHER_PARTY_REPRESENTATIVE_EVIDENCE, false, true, true, true, false",
"OTHER_PARTY_REPRESENTATIVE_EVIDENCE, true, true, false, true, false",
"OTHER_PARTY_REPRESENTATIVE_EVIDENCE, true, false, false, true, false",
"OTHER_PARTY_REPRESENTATIVE_EVIDENCE, false, true, false, true, false",
})
public void givenIssueFurtherEvidenceCallback_shouldReissueEvidenceForAppellantAndRepAndDwpAndOtherPartyAndV2Enabled(DocumentType documentType,
boolean resendToAppellant,
boolean resendToRepresentative,
boolean isEnglish,
boolean resendToOtherParty,
boolean resendToOtherPartyRep) {
ReflectionTestUtils.setField(handler, "updateCaseOnlyHearingV2Enabled", true);

if (resendToAppellant || resendToRepresentative || resendToOtherParty || resendToOtherPartyRep) {
when(idamService.getIdamTokens()).thenReturn(IdamTokens.builder().build());
}

given(furtherEvidenceService.canHandleAnyDocument(any())).willReturn(true);

AbstractDocument sscsDocumentNotIssued = null;
if (isEnglish) {
sscsDocumentNotIssued = SscsDocument.builder()
.value(SscsDocumentDetails.builder()
.documentLink(DocumentLink.builder().documentUrl("www.acme.co.uk").build())
.documentType(documentType.getValue())
.evidenceIssued("No").originalSenderOtherPartyId("3")
.build())
.build();
} else {
sscsDocumentNotIssued = SscsWelshDocument.builder()
.value(SscsWelshDocumentDetails.builder()
.documentLink(DocumentLink.builder().documentUrl("www.acme.co.uk").build())
.documentType(documentType.getValue())
.evidenceIssued("No")
.build())
.build();
}


DynamicListItem dynamicListItem = new DynamicListItem(
sscsDocumentNotIssued.getValue().getDocumentLink().getDocumentUrl(), "a label");
DynamicList dynamicList = new DynamicList(dynamicListItem, Collections.singletonList(dynamicListItem));
SscsCaseData caseData = SscsCaseData.builder()
.ccdCaseId("1563382899630221")
.appeal(Appeal.builder().rep(Representative.builder().hasRepresentative("YES").build()).build())
.reissueArtifactUi(ReissueArtifactUi.builder()
.reissueFurtherEvidenceDocument(dynamicList)
.resendToAppellant(resendToAppellant ? YesNo.YES : YesNo.NO)
.resendToRepresentative(resendToRepresentative ? YesNo.YES : YesNo.NO)
.otherPartyOptions(getOtherPartyOptions(resendToOtherParty ? YesNo.YES : YesNo.NO,
resendToOtherPartyRep ? YesNo.YES : YesNo.NO))
.build())
.build();
SscsCaseDetails sscsCaseDetails = SscsCaseDetails.builder().data(caseData).build();

if (isEnglish) {
caseData.setSscsDocument(Collections.singletonList((SscsDocument) sscsDocumentNotIssued));
} else {
caseData.setSscsWelshDocuments(Collections.singletonList((SscsWelshDocument) sscsDocumentNotIssued));
}

handler.handle(CallbackType.SUBMITTED,
HandlerHelper.buildTestCallbackForGivenData(caseData, INTERLOCUTORY_REVIEW_STATE, REISSUE_FURTHER_EVIDENCE));

verify(furtherEvidenceService).canHandleAnyDocument(eq(caseData.getSscsDocument()));

List<FurtherEvidenceLetterType> allowedLetterTypes = new ArrayList<>();
if (resendToAppellant) {
allowedLetterTypes.add(FurtherEvidenceLetterType.APPELLANT_LETTER);
}
if (resendToRepresentative) {
allowedLetterTypes.add(FurtherEvidenceLetterType.REPRESENTATIVE_LETTER);
}
if (resendToOtherParty) {
allowedLetterTypes.add(FurtherEvidenceLetterType.OTHER_PARTY_LETTER);
}
if (resendToOtherPartyRep) {
allowedLetterTypes.add(FurtherEvidenceLetterType.OTHER_PARTY_REP_LETTER);
}

verify(furtherEvidenceService).issue(eq(Collections.singletonList(sscsDocumentNotIssued)), eq(caseData), eq(documentType), eq(allowedLetterTypes), eq(resendToOtherParty && isEnglish ? "3" : null));

verifyNoMoreInteractions(furtherEvidenceService);

if (resendToAppellant || resendToRepresentative || resendToOtherParty || resendToOtherPartyRep) {
verify(updateCcdCaseService).updateCaseV2(any(Long.class), eq(EventType.UPDATE_CASE_ONLY.getCcdType()),
any(), any(), any(IdamTokens.class), sscsCaseDetailsCaptor.capture());
sscsCaseDetailsCaptor.getValue().accept(sscsCaseDetails);
if (isEnglish) {
assertEquals("Yes", sscsCaseDetails.getData().getSscsDocument().get(0).getValue().getEvidenceIssued());
} else {
assertEquals("Yes", sscsCaseDetails.getData().getSscsWelshDocuments().get(0).getValue().getEvidenceIssued());
}
} else {
verifyNoInteractions(updateCcdCaseService);
}

}

@Test
@Parameters({"Second.doc", "SecondRedacted.doc",})
public void givenIssueFurtherEvidenceCallback_shouldReissueChosenEvidence(String chosenDoc) {
Expand Down

0 comments on commit 4dcdd65

Please sign in to comment.