Skip to content

Commit

Permalink
SSCS-9772 - use uploaded document when writing adjournment notice (#2918
Browse files Browse the repository at this point in the history
)

* SSCS-9772 - use uploaded document when writing adjournment notice

* SSCS-9772 - test fix
  • Loading branch information
hajam09 committed Oct 24, 2022
1 parent 3c0c5c2 commit f74eecd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uk.gov.hmcts.reform.sscs.ccd.domain.CaseDetails;
import uk.gov.hmcts.reform.sscs.ccd.domain.EventType;
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData;
import uk.gov.hmcts.reform.sscs.ccd.domain.YesNo;
import uk.gov.hmcts.reform.sscs.ccd.presubmit.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.sscs.ccd.presubmit.adjourncase.AdjournCasePreviewService;

Expand Down Expand Up @@ -44,10 +45,12 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,

PreSubmitCallbackResponse<SscsCaseData> response = new PreSubmitCallbackResponse<>(sscsCaseData);

if (sscsCaseData.getAdjournCasePreviewDocument() != null) {
// Given the user selects No to generate notice option and has uploaded their custom adjournment notice document.
// Then don't generate the system default adjournment notice document.
if (YesNo.isYes(sscsCaseData.getAdjournCaseGenerateNotice())) {
previewService.preview(callback, DocumentType.ADJOURNMENT_NOTICE, userAuthorisation, true);
} else {
response.addError("No draft adjournment notice found on case. Please use 'Adjourn case' event before trying to issue.");
} else if (sscsCaseData.getAdjournCasePreviewDocument() == null) {
response.addError("No draft adjournment notice found on case. Please use 'Adjourn case' event or upload your adjourn case document.");
}

return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.hmcts.reform.sscs.ccd.presubmit.issueadjournment;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -67,18 +66,19 @@ public void setUp() {
@Test
public void givenANonIssueAdjournmentEvent_thenReturnFalse() {
when(callback.getEvent()).thenReturn(EventType.APPEAL_RECEIVED);
assertFalse(handler.canHandle(ABOUT_TO_START, callback));
assertThat(handler.canHandle(ABOUT_TO_START, callback)).isFalse();
}

@Test
@Parameters({"ABOUT_TO_SUBMIT", "MID_EVENT", "SUBMITTED"})
public void givenANonCallbackType_thenReturnFalse(CallbackType callbackType) {
assertFalse(handler.canHandle(callbackType, callback));
assertThat(handler.canHandle(callbackType, callback)).isFalse();
}

@Test
public void givenAboutToStartRequest_willGeneratePreviewFile() {
PreSubmitCallbackResponse response = new PreSubmitCallbackResponse(sscsCaseData);
sscsCaseData.setAdjournCaseGenerateNotice("Yes");

when(previewService.preview(callback, DocumentType.ADJOURNMENT_NOTICE, USER_AUTHORISATION, true)).thenReturn(response);
handler.handle(ABOUT_TO_START, callback, USER_AUTHORISATION);
Expand All @@ -89,10 +89,11 @@ public void givenAboutToStartRequest_willGeneratePreviewFile() {
@Test
public void givenNoPreviewDecisionFoundOnCase_thenShowError() {
sscsCaseData.setAdjournCasePreviewDocument(null);
sscsCaseData.setAdjournCaseGenerateNotice("No");
PreSubmitCallbackResponse<SscsCaseData> result = handler.handle(ABOUT_TO_START, callback, USER_AUTHORISATION);

String error = result.getErrors().stream().findFirst().orElse("");
assertEquals("No draft adjournment notice found on case. Please use 'Adjourn case' event before trying to issue.", error);
assertThat("No draft adjournment notice found on case. Please use 'Adjourn case' event or upload your adjourn case document.").isEqualTo(error);
}

@Test(expected = IllegalStateException.class)
Expand Down

0 comments on commit f74eecd

Please sign in to comment.