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

DFPL-2599: Change additional applications from post-submit sealing to about-to-submit sealing #5692

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import org.springframework.test.context.ActiveProfiles;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.ccd.document.am.model.Document;
import uk.gov.hmcts.reform.fpl.enums.AdditionalApplicationType;
import uk.gov.hmcts.reform.fpl.enums.CaseRole;
import uk.gov.hmcts.reform.fpl.enums.OtherApplicationType;
import uk.gov.hmcts.reform.fpl.enums.SupplementType;
import uk.gov.hmcts.reform.fpl.enums.YesNo;
import uk.gov.hmcts.reform.fpl.enums.notification.DocumentUploaderType;
import uk.gov.hmcts.reform.fpl.exceptions.EncryptedPdfUploadedException;
import uk.gov.hmcts.reform.fpl.model.CaseData;
import uk.gov.hmcts.reform.fpl.model.PBAPayment;
import uk.gov.hmcts.reform.fpl.model.Representative;
Expand All @@ -34,6 +36,9 @@
import uk.gov.hmcts.reform.fpl.model.order.HearingOrdersBundle;
import uk.gov.hmcts.reform.fpl.model.order.selector.Selector;
import uk.gov.hmcts.reform.fpl.request.RequestData;
import uk.gov.hmcts.reform.fpl.service.DocumentDownloadService;
import uk.gov.hmcts.reform.fpl.service.DocumentSealingService;
import uk.gov.hmcts.reform.fpl.service.UploadDocumentService;
import uk.gov.hmcts.reform.fpl.service.UserService;
import uk.gov.hmcts.reform.fpl.service.docmosis.DocumentConversionService;
import uk.gov.hmcts.reform.fpl.service.document.ManageDocumentService;
Expand Down Expand Up @@ -62,6 +67,8 @@
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements;
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.wrapElements;
import static uk.gov.hmcts.reform.fpl.utils.SecureDocumentManagementStoreLoader.document;
import static uk.gov.hmcts.reform.fpl.utils.TestDataHelper.testDocument;
import static uk.gov.hmcts.reform.fpl.utils.TestDataHelper.testDocumentBinary;
import static uk.gov.hmcts.reform.fpl.utils.TestDataHelper.testDocumentReference;

@ActiveProfiles("integration-test")
Expand All @@ -74,18 +81,30 @@ class UploadAdditionalApplicationsAboutToSubmitControllerTest extends AbstractCa
private static final String APPLICANT_SOMEONE_ELSE = "SOMEONE_ELSE";
private static final String APPLICANT = "applicant";
private static final String OTHER_APPLICANT_NAME = "some other name";
private static final DocumentReference DOCUMENT_REFERENCE = testDocumentReference();
private static final String ADMIN_ROLE = "caseworker-publiclaw-courtadmin";

private static final DocumentReference UPLOADED_DOCUMENT = testDocumentReference();
private static final DocumentReference PDF_DOCUMENT = testDocumentReference();
private static final DocumentReference SUPPORTING_DOC_REF = testDocumentReference();
private static final DocumentReference APPLICATION_DOC_REF = testDocumentReference();
private static final Document SEALED_APPLICATION_DOC = testDocument();
private static final DocumentReference SEALED_APPLICATION_DOC_REF = testDocumentReference();
private static final byte[] SEALED_APPLICATION_BINARY = testDocumentBinary();
private static final byte[] APPLICATION_BINARY = testDocumentBinary();

@MockBean
private ManageDocumentService manageDocumentService;

@MockBean
private DocumentConversionService documentConversionService;

@MockBean
private DocumentDownloadService documentDownloadService;

@MockBean
private UploadDocumentService uploadDocumentService;

@MockBean
private DocumentSealingService documentSealingService;

@MockBean
private RequestData requestData;

Expand All @@ -104,10 +123,18 @@ void before() {
given(requestData.authorisation()).willReturn(USER_AUTH_TOKEN);
given(requestData.userRoles()).willReturn(Set.of(ADMIN_ROLE));
given(idamClient.getUserDetails(eq(USER_AUTH_TOKEN))).willReturn(createUserDetailsWithHmctsRole());
given(documentConversionService.convertToPdf(UPLOADED_DOCUMENT)).willReturn(PDF_DOCUMENT);
given(documentConversionService.convertToPdf(SUPPORTING_DOC_REF)).willReturn(SUPPORTING_DOC_REF);
given(userService.isHmctsUser()).willReturn(true);
when(manageDocumentService.getUploaderType(any())).thenReturn(DocumentUploaderType.DESIGNATED_LOCAL_AUTHORITY);
when(manageDocumentService.getUploaderCaseRoles(any())).thenReturn(List.of(CaseRole.LASOLICITOR));
given(documentDownloadService.downloadDocument(APPLICATION_DOC_REF.getBinaryUrl()))
.willReturn(APPLICATION_BINARY);
given(uploadDocumentService.uploadPDF(SEALED_APPLICATION_BINARY, SEALED_APPLICATION_DOC_REF.getFilename()))
.willReturn(SEALED_APPLICATION_DOC);
given(documentSealingService.sealDocument(eq(APPLICATION_BINARY), any(), any()))
.willReturn(SEALED_APPLICATION_BINARY);
given(documentSealingService.sealDocument(eq(APPLICATION_DOC_REF), any(), any()))
.willReturn(SEALED_APPLICATION_DOC_REF);
}

@Test
Expand Down Expand Up @@ -353,12 +380,34 @@ void shouldUpdateDraftBundleIfConfidentialDraftOrderUploaded() {
.isEqualTo(caseData.getTemporaryC2Document().getDraftOrdersBundle().get(0).getValue().getDocument());
}

@Test
void shouldRespondWithErrorIfEncrpytedPdf() {
when(documentSealingService.sealDocument(any(DocumentReference.class), any(), any()))
.thenThrow(EncryptedPdfUploadedException.class);

CaseData caseData = CaseData.builder()
.additionalApplicationType(List.of(AdditionalApplicationType.C2_ORDER))
.temporaryC2Document(createTemporaryC2Document())
.applicantsList(createApplicantsDynamicList(APPLICANT))
.respondents1(wrapElements(Respondent.builder()
.party(RespondentParty.builder().firstName("Margaret").lastName("Jones").build())
.build()
))
.build();

AboutToStartOrSubmitCallbackResponse resp = postAboutToSubmitEvent(caseData);

assertThat(resp.getErrors()).containsExactly("The uploaded document is password protected. "
+ "Please remove the password protection and try again.");
}

private void assertC2DocumentBundle(C2DocumentBundle uploadedC2DocumentBundle) {
String expectedDateTime = formatLocalDateTimeBaseUsingFormat(now(), DATE_TIME);

assertThat(uploadedC2DocumentBundle.getUploadedDateTime()).isEqualTo(expectedDateTime);

assertThat(uploadedC2DocumentBundle.getAuthor()).isEqualTo(USER_NAME);
assertThat(uploadedC2DocumentBundle.getDocument()).isEqualTo(SEALED_APPLICATION_DOC_REF);
// This is no longer true - PDF conversion has been moved to post submit
// assertDocument(uploadedC2DocumentBundle.getDocument(), PDF_DOCUMENT);
assertSupportingEvidenceBundle(uploadedC2DocumentBundle.getSupportingEvidenceBundle());
Expand All @@ -373,6 +422,7 @@ private void assertOtherApplicationsBundle(OtherApplicationsBundle uploadedOther
assertThat(uploadedOtherApplicationsBundle.getApplicationType())
.isEqualTo(OtherApplicationType.C1_APPOINTMENT_OF_A_GUARDIAN);
assertThat(uploadedOtherApplicationsBundle.getAuthor()).isEqualTo(USER_NAME);
assertThat(uploadedOtherApplicationsBundle.getDocument()).isEqualTo(SEALED_APPLICATION_DOC_REF);

assertSupportingEvidenceBundle(uploadedOtherApplicationsBundle.getSupportingEvidenceBundle());
assertSupplementsBundle(uploadedOtherApplicationsBundle.getSupplementsBundle());
Expand Down Expand Up @@ -412,7 +462,7 @@ private void assertSupportingEvidenceBundle(List<Element<SupportingEvidenceBundl
"Supporting document",
"Document notes",
time.now(),
UPLOADED_DOCUMENT,
SUPPORTING_DOC_REF,
USER_NAME
);
}
Expand Down Expand Up @@ -442,7 +492,7 @@ private PBAPayment createPbaPayment() {
private C2DocumentBundle createTemporaryC2Document() {
return C2DocumentBundle.builder()
.type(WITH_NOTICE)
.document(UPLOADED_DOCUMENT)
.document(APPLICATION_DOC_REF)
.draftOrdersBundle(createDraftOrderBundle())
.supplementsBundle(wrapElements(createSupplementsBundle()))
.supportingEvidenceBundle(wrapElements(createSupportingEvidenceBundle()))
Expand All @@ -466,7 +516,7 @@ private DynamicList createApplicantsDynamicList(String selected) {
private OtherApplicationsBundle createTemporaryOtherApplicationDocument() {
return OtherApplicationsBundle.builder()
.applicationType(OtherApplicationType.C1_APPOINTMENT_OF_A_GUARDIAN)
.document(UPLOADED_DOCUMENT)
.document(APPLICATION_DOC_REF)
.supplementsBundle(wrapElements(createSupplementsBundle()))
.supportingEvidenceBundle(wrapElements(createSupportingEvidenceBundle()))
.build();
Expand All @@ -477,7 +527,7 @@ private SupportingEvidenceBundle createSupportingEvidenceBundle() {
.name("Supporting document")
.notes("Document notes")
.dateTimeUploaded(time.now())
.document(UPLOADED_DOCUMENT)
.document(SUPPORTING_DOC_REF)
.build();
}

Expand All @@ -486,7 +536,7 @@ private Supplement createSupplementsBundle() {
.name(SupplementType.C13A_SPECIAL_GUARDIANSHIP)
.notes("Supplement notes")
.dateTimeUploaded(time.now())
.document(UPLOADED_DOCUMENT)
.document(SUPPORTING_DOC_REF)
.build();
}

Expand All @@ -508,7 +558,7 @@ private Element<DraftOrder> createDraftOrder() {
return element(DraftOrder.builder()
.title("Test")
.dateUploaded(dateNow())
.document(DOCUMENT_REFERENCE)
.document(SUPPORTING_DOC_REF)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import java.util.function.Function;

import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.AdditionalAnswers.returnsFirstArg;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
Expand Down Expand Up @@ -112,9 +111,7 @@ class UploadAdditionalApplicationsSubmittedControllerTest extends AbstractCallba
private static final Long CASE_ID = 12345L;
private static final FeesData FEES_DATA = FeesData.builder().totalAmount(BigDecimal.TEN).build();
private static final UUID LETTER_1_ID = randomUUID();
private static final Document ORDER_DOCUMENT = testDocument();
private static final Document COVERSHEET_OTHER_REPRESENTATIVE = testDocument();
private static final byte[] ORDER_BINARY = testDocumentBinary();
private static final byte[] COVERSHEET_OTHER_REPRESENTATIVE_BINARY = testDocumentBinary();
private static final DocumentReference ORDER = testDocumentReference();

Expand Down Expand Up @@ -198,9 +195,6 @@ class UploadAdditionalApplicationsSubmittedControllerTest extends AbstractCallba
void init() {
other.addRepresentative(OTHER_REP_BY_POST.getId());
givenFplService();
given(documentDownloadService.downloadDocument(ORDER.getBinaryUrl())).willReturn(ORDER_BINARY);
given(uploadDocumentService.uploadPDF(ORDER_BINARY, ORDER.getFilename()))
.willReturn(ORDER_DOCUMENT);
given(documentService.createCoverDocuments(any(), any(), eq(OTHER_REP_BY_POST.getValue()), any()))
.willReturn(DocmosisDocument.builder().bytes(COVERSHEET_OTHER_REPRESENTATIVE_BINARY).build());
given(uploadDocumentService.uploadPDF(COVERSHEET_OTHER_REPRESENTATIVE_BINARY, COVERSHEET_PDF))
Expand All @@ -209,10 +203,6 @@ void init() {
.willAnswer(returnsFirstArg());
given(sendLetterApi.sendLetter(any(), any(LetterWithPdfsRequest.class)))
.willReturn(new SendLetterResponse(LETTER_1_ID));
given(uploadAdditionalApplicationsService.convertC2Bundle(any(), any()))
.willAnswer(returnsFirstArg());
given(uploadAdditionalApplicationsService.convertOtherBundle(any(), any()))
.willAnswer(returnsFirstArg());

doNothing().when(sendDocumentService).sendDocuments(any());
doNothing().when(cafcassNotificationService).sendEmail(any(), any(), any());
Expand Down Expand Up @@ -570,81 +560,6 @@ void shouldNotSendPaymentNotificationsWhenApplyingForAdjournment() throws Notifi
anyString());
}

@Test
void shouldConvertBundles() {
UUID additionalApplicationsBundleId = UUID.randomUUID();
C2DocumentBundle c2Bundle = C2DocumentBundle.builder()
.type(WITH_NOTICE)
.supplementsBundle(new ArrayList<>())
.applicantName(LOCAL_AUTHORITY_1_NAME + ", Applicant").build();
OtherApplicationsBundle otherBundle = OtherApplicationsBundle.builder()
.applicationType(C1_APPOINTMENT_OF_A_GUARDIAN)
.supplementsBundle(new ArrayList<>())
.applicantName(LOCAL_AUTHORITY_1_NAME + ", Applicant").build();

AdditionalApplicationsBundle additionalApplicationsBundle = AdditionalApplicationsBundle.builder()
.pbaPayment(PBAPayment.builder().usePbaPayment(NO.getValue()).build())
.c2DocumentBundle(c2Bundle)
.otherApplicationsBundle(otherBundle)
.build();

CaseDetails caseDetails = createCase(ImmutableMap.<String, Object>builder()
.putAll(buildCommonNotificationParameters())
.put("additionalApplicationType", List.of(C2_ORDER, OTHER_ORDER))
.put("additionalApplicationsBundle",
List.of(element(additionalApplicationsBundleId, additionalApplicationsBundle)))
.put("sendToCtsc", NO.getValue())
.build());

when(coreCaseDataService.performPostSubmitCallback(any(),
eq("internal-change-upload-add-apps"),
changeFunctionCaptor.capture())).thenReturn(caseDetails);

C2DocumentBundle expectedC2 = c2Bundle.toBuilder().applicantName("Converted C2").build();
when(uploadAdditionalApplicationsService.convertC2Bundle(any(), any())).thenReturn(expectedC2);
OtherApplicationsBundle expectedOtherBundle = otherBundle.toBuilder().applicantName("Converted Other").build();
when(uploadAdditionalApplicationsService.convertOtherBundle(any(), any())).thenReturn(expectedOtherBundle);

postSubmittedEvent(caseDetails);
Map<String, Object> actual = changeFunctionCaptor.getValue().apply(caseDetails);

assertEquals(actual.get("additionalApplicationsBundle"), List.of(element(additionalApplicationsBundleId,
additionalApplicationsBundle.toBuilder()
.c2DocumentBundle(expectedC2)
.otherApplicationsBundle(expectedOtherBundle)
.build())));
}

@Test
@SuppressWarnings("unchecked")
void shouldConvertC2ConfidentialBundle() {
given(uploadAdditionalApplicationsService.getApplicationTypes(any()))
.willReturn(List.of(ApplicationType.C2_APPLICATION));

C2DocumentBundle c2 = C2DocumentBundle.builder()
.type(WITH_NOTICE)
.supplementsBundle(new ArrayList<>())
.applicantName(LOCAL_AUTHORITY_1_NAME + ", Applicant")
.build();

CaseDetails caseDetails = createCase(ImmutableMap.<String, Object>builder()
.putAll(buildCommonNotificationParameters())
.put("sendToCtsc", NO)
.put("additionalApplicationType", List.of(C2_ORDER))
.put("additionalApplicationsBundle", wrapElementsWithUUIDs(AdditionalApplicationsBundle.builder()
.pbaPayment(PBAPayment.builder().usePbaPayment(NO.getValue()).build())
.c2DocumentBundleConfidential(c2)
.build()))
.build());

postSubmittedEvent(caseDetails);

verify(coreCaseDataService).performPostSubmitCallback(eq(caseDetails.getId()),
eq("internal-change-upload-add-apps"), changeFunctionCaptor.capture());
changeFunctionCaptor.getValue().apply(caseDetails);
verify(uploadAdditionalApplicationsService).convertConfidentialC2Bundle(any(), eq(c2), any());
}

private CaseDetails buildCaseDetails(YesNo enableCtsc, YesNo usePbaPayment) {
return createCase(ImmutableMap.<String, Object>builder()
.putAll(buildCommonNotificationParameters())
Expand Down
Loading
Loading