diff --git a/docker/docmosis/templates/CV-SPC-CLM-ENG-00001-DRAFT.docx b/docker/docmosis/templates/CV-SPC-CLM-ENG-00001-DRAFT.docx index cb2ffe7610d..a64b6ca7c91 100644 Binary files a/docker/docmosis/templates/CV-SPC-CLM-ENG-00001-DRAFT.docx and b/docker/docmosis/templates/CV-SPC-CLM-ENG-00001-DRAFT.docx differ diff --git a/docker/docmosis/templates/CV-SPC-CLM-ENG-CLAIMANT-CLAIM-FORM.docx b/docker/docmosis/templates/CV-SPC-CLM-ENG-CLAIMANT-CLAIM-FORM.docx new file mode 100644 index 00000000000..ad0fe66b181 Binary files /dev/null and b/docker/docmosis/templates/CV-SPC-CLM-ENG-CLAIMANT-CLAIM-FORM.docx differ diff --git a/docker/docmosis/templates/CV-SPC-CLM-ENG-DEFENDANT-CLAIM-FORM.docx b/docker/docmosis/templates/CV-SPC-CLM-ENG-DEFENDANT-CLAIM-FORM.docx new file mode 100644 index 00000000000..e07eb89669a Binary files /dev/null and b/docker/docmosis/templates/CV-SPC-CLM-ENG-DEFENDANT-CLAIM-FORM.docx differ diff --git a/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java b/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java index be62a8c75ad..216df80fb8f 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java @@ -306,6 +306,7 @@ public enum CaseEvent { CREATE_SERVICE_REQUEST_API_HMC(CAMUNDA), UPDATE_PARTIES_NOTIFIED_HMC(CAMUNDA), UPDATE_CASE_PROGRESS_HMC(CAMUNDA), + UPDATE_CLAIMANT_INTENTION_CLAIM_STATE(CAMUNDA), NOTIFY_APPLICANT1_CLAIM_SUBMITTED(CAMUNDA), NOTIFY_DEFENDANT_CLAIMANT_SETTLE_THE_CLAIM(CAMUNDA), NOTIFY_DEFENDANT_LIP_CLAIMANT_REPRESENTED(CAMUNDA), @@ -326,8 +327,11 @@ public enum CaseEvent { RETRIGGER_CASES(CAMUNDA), GENERATE_LIP_CLAIMANT_MANUAL_DETERMINATION(CAMUNDA), GENERATE_LIP_SIGN_SETTLEMENT_AGREEMENT_FORM(CAMUNDA), + UPDATE_CLAIM_STATE_AFTER_TRANSLATED_DOCUMENT_UPLOADED(CAMUNDA), NOTIFY_CLAIMANT_LIP_HELP_WITH_FEES(CAMUNDA), - GENERATE_INTERLOCUTORY_JUDGEMENT_DOCUMENT(CAMUNDA); + GENERATE_INTERLOCUTORY_JUDGEMENT_DOCUMENT(CAMUNDA), + GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC(CAMUNDA), + GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC(CAMUNDA); private final UserType userType; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimStateAfterUploadingTranslatedDocuments.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimStateAfterUploadingTranslatedDocuments.java new file mode 100644 index 00000000000..afd59408565 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimStateAfterUploadingTranslatedDocuments.java @@ -0,0 +1,63 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.caseevents; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; +import uk.gov.hmcts.reform.civil.callback.Callback; +import uk.gov.hmcts.reform.civil.callback.CallbackHandler; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.model.CaseData; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_CLAIM_STATE_AFTER_TRANSLATED_DOCUMENT_UPLOADED; + +@Service +@RequiredArgsConstructor +public class UpdateClaimStateAfterUploadingTranslatedDocuments extends CallbackHandler { + + private static final List EVENTS = Collections.singletonList(UPDATE_CLAIM_STATE_AFTER_TRANSLATED_DOCUMENT_UPLOADED); + private Map callbackMap = Map.of(callbackKey(ABOUT_TO_SUBMIT), this::updateClaimState); + private static final String TASK_ID = "updateClaimStateAfterTranslateDocumentUploadedID"; + private final ObjectMapper objectMapper; + + @Override + protected Map callbacks() { + return callbackMap; + } + + private CallbackResponse updateClaimState(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + + String changeToState = setClaimState(caseData); + return AboutToStartOrSubmitCallbackResponse.builder() + .data(caseData.toMap(objectMapper)) + .state(changeToState) + .build(); + } + + private String setClaimState(CaseData caseData) { + if (caseData.getCcdState().equals(CaseState.AWAITING_RESPONDENT_ACKNOWLEDGEMENT)) { + return CaseState.AWAITING_APPLICANT_INTENTION.name(); + } + return caseData.getCcdState().name(); + } + + @Override + public List handledEvents() { + return EVENTS; + } + + @Override + public String camundaActivityId(CallbackParams callbackParams) { + return TASK_ID; + } + +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimantIntentionClaimStateCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimantIntentionClaimStateCallbackHandler.java new file mode 100644 index 00000000000..71404a28129 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimantIntentionClaimStateCallbackHandler.java @@ -0,0 +1,61 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.caseevents; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; +import uk.gov.hmcts.reform.civil.callback.Callback; +import uk.gov.hmcts.reform.civil.callback.CallbackHandler; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.UpdateClaimStateService; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_CLAIMANT_INTENTION_CLAIM_STATE; + +@Service +@RequiredArgsConstructor +public class UpdateClaimantIntentionClaimStateCallbackHandler extends CallbackHandler { + + private static final List EVENTS = Collections.singletonList(UPDATE_CLAIMANT_INTENTION_CLAIM_STATE); + + public static final String TASK_ID = "updateClaimantIntentionClaimStateID"; + private Map callbackMap = Map.of(callbackKey(ABOUT_TO_SUBMIT), this::updateCaseState); + private final ObjectMapper objectMapper; + private final UpdateClaimStateService updateClaimStateService; + + @Override + public String camundaActivityId(CallbackParams callbackParams) { + return TASK_ID; + } + + @Override + protected Map callbacks() { + return callbackMap; + } + + @Override + public List handledEvents() { + return EVENTS; + } + + private CallbackResponse updateCaseState(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + + CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); + CaseData updatedData = caseDataBuilder.build(); + AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response = + AboutToStartOrSubmitCallbackResponse.builder() + .data(updatedData.toMap(objectMapper)); + if (!updatedData.isBilingual()) { + response.state(updateClaimStateService.setUpCaseState(updatedData)); + } + return response.build(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDraftClaimFormCallBackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDraftClaimFormCallBackHandler.java deleted file mode 100644 index 8b70fc9c3e7..00000000000 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDraftClaimFormCallBackHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; -import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; -import uk.gov.hmcts.reform.civil.callback.Callback; -import uk.gov.hmcts.reform.civil.callback.CallbackHandler; -import uk.gov.hmcts.reform.civil.callback.CallbackParams; -import uk.gov.hmcts.reform.civil.callback.CaseEvent; -import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; -import uk.gov.hmcts.reform.civil.model.CaseData; -import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService; -import uk.gov.hmcts.reform.civil.service.docmosis.draft.DraftClaimFormGenerator; - -import java.util.List; -import java.util.Map; - -import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; -import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_DRAFT_FORM; - -@Service -@RequiredArgsConstructor -public class GenerateDraftClaimFormCallBackHandler extends CallbackHandler { - - private static final List EVENTS = List.of(GENERATE_DRAFT_FORM); - private final Map callbackMap = Map.of(callbackKey(ABOUT_TO_SUBMIT), this::generateDraftPdfForm); - private final ObjectMapper objectMapper; - private final DraftClaimFormGenerator draftClaimFormGenerator; - private final SystemGeneratedDocumentService systemGeneratedDocumentService; - - @Override - protected Map callbacks() { - return callbackMap; - } - - @Override - public List handledEvents() { - return EVENTS; - } - - private CallbackResponse generateDraftPdfForm(CallbackParams callbackParams) { - CaseData caseData = callbackParams.getCaseData(); - CaseDocument sealedForm = draftClaimFormGenerator.generate(caseData, callbackParams.getParams().get(BEARER_TOKEN).toString()); - CaseData updatedCaseData = caseData.toBuilder() - .systemGeneratedCaseDocuments(systemGeneratedDocumentService.getSystemGeneratedDocumentsWithAddedDocument( - sealedForm, - caseData - )) - .build(); - return AboutToStartOrSubmitCallbackResponse.builder() - .data(updatedCaseData.toMap(objectMapper)) - .build(); - } - -} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateLipClaimFormCallBackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateLipClaimFormCallBackHandler.java new file mode 100644 index 00000000000..968c3f3089b --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateLipClaimFormCallBackHandler.java @@ -0,0 +1,92 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; +import uk.gov.hmcts.reform.civil.callback.Callback; +import uk.gov.hmcts.reform.civil.callback.CallbackHandler; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; +import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService; +import uk.gov.hmcts.reform.civil.service.docmosis.claimform.ClaimFormGenerator; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_DRAFT_FORM; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC; + +@Service +@RequiredArgsConstructor +public class GenerateLipClaimFormCallBackHandler extends CallbackHandler { + + private static final List EVENTS = List.of( + GENERATE_DRAFT_FORM, + GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC, + GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC + ); + private final ObjectMapper objectMapper; + private final ClaimFormGenerator claimFormGenerator; + private final SystemGeneratedDocumentService systemGeneratedDocumentService; + private final Map callbackMap = Map.of(callbackKey(ABOUT_TO_SUBMIT), this::generateClaimForm); + + @Override + protected Map callbacks() { + return callbackMap; + } + + @Override + public List handledEvents() { + return EVENTS; + } + + private CallbackResponse generateClaimForm(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + CaseEvent caseEvent = CaseEvent.valueOf(callbackParams.getRequest().getEventId()); + CaseDocument caseDocument = claimFormGenerator.generate( + caseData, + callbackParams.getParams().get(BEARER_TOKEN).toString(), + caseEvent + ); + + CaseData updatedCaseData = updateCaseData(caseData, caseDocument, caseEvent); + return AboutToStartOrSubmitCallbackResponse.builder() + .data(updatedCaseData.toMap(objectMapper)) + .build(); + } + + private CaseData updateCaseData(CaseData caseData, CaseDocument caseDocument, CaseEvent caseEvent) { + return switch (caseEvent) { + case GENERATE_DRAFT_FORM, GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC, GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC -> + buildClaimFormData(caseData, caseDocument, caseEvent); + default -> throw new IllegalArgumentException("case event not found"); + }; + } + + private CaseData buildClaimFormData(CaseData caseData, CaseDocument caseDocument, CaseEvent event) { + List> systemGeneratedCaseDocuments = systemGeneratedDocumentService.getSystemGeneratedDocumentsWithAddedDocument( + caseDocument, + caseData + ); + + // Remove Draft form from documents + if (event == GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC) { + systemGeneratedCaseDocuments = systemGeneratedCaseDocuments.stream().filter(claimDoc -> claimDoc.getValue().getDocumentType() != DocumentType.DRAFT_CLAIM_FORM) + .collect(Collectors.toList()); + } + + return caseData.toBuilder() + .systemGeneratedCaseDocuments(systemGeneratedCaseDocuments) + .build(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler.java index 73cfb5c570e..fbfef065995 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler.java @@ -37,7 +37,7 @@ public class ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler e private CallbackResponse notifyRespondentForClaimantConfirmsToProceed(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); - if (Objects.nonNull(caseData.getRespondent1().getPartyEmail())) { + if (!caseData.isBilingual() && Objects.nonNull(caseData.getRespondent1().getPartyEmail())) { notificationService.sendMail( caseData.getRespondent1().getPartyEmail(), notificationsProperties.getRespondent1LipClaimUpdatedTemplate(), @@ -50,7 +50,7 @@ private CallbackResponse notifyRespondentForClaimantConfirmsToProceed(CallbackPa @Override protected Map callbacks() { - return callbackMap; + return callbackMap; } @Override diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandler.java index 2943d40dc51..ea5f1045083 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandler.java @@ -2,7 +2,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import feign.FeignException; + import java.util.Collections; + import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -13,6 +15,8 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.Fee; +import uk.gov.hmcts.reform.civil.model.SRPbaDetails; import uk.gov.hmcts.reform.civil.service.PaymentsService; import java.util.ArrayList; @@ -62,11 +66,14 @@ private CallbackResponse makePaymentServiceReq(CallbackParams callbackParams) { if (isServiceRequestNotRequested(caseData) && !caseData.isHelpWithFees()) { log.info("Calling payment service request (claim fee) for case {}", caseData.getCcdCaseReference()); String serviceRequestReference = getServiceRequestReference(caseData, authToken); - caseData = caseData.toBuilder().serviceRequestReference(serviceRequestReference).build(); + caseData = caseData.toBuilder().serviceRequestReference(serviceRequestReference) + .claimIssuedPBADetails(getClaimIssuePbaDetails(serviceRequestReference, caseData.getClaimFee())) + .build(); } } catch (FeignException e) { log.error("Failed creating a payment service request for case {}. Http status: {}. Exception: {}", - caseData.getCcdCaseReference(), e.status(), e); + caseData.getCcdCaseReference(), e.status(), e + ); errors.add(ERROR_MESSAGE); } return AboutToStartOrSubmitCallbackResponse.builder() @@ -83,4 +90,11 @@ private String getServiceRequestReference(CaseData caseData, String authToken) { private boolean isServiceRequestNotRequested(CaseData caseData) { return isNull(caseData.getServiceRequestReference()); } + + private SRPbaDetails getClaimIssuePbaDetails(String serviceReference, Fee claimFee) { + return SRPbaDetails.builder() + .serviceReqReference(serviceReference) + .fee(claimFee) + .build(); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java index 1c30ff235dd..c64125b4162 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java @@ -83,7 +83,7 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { CaseData.CaseDataBuilder builder = caseData.toBuilder() .applicant1ResponseDate(applicant1ResponseDate) .businessProcess(BusinessProcess.ready(CLAIMANT_RESPONSE_CUI)) - .respondent1RespondToSettlementAgreementDeadline(getRespondToSettlementAgreementDeadline( + .respondent1RespondToSettlementAgreementDeadline(caseData.isBilingual() ? null : getRespondToSettlementAgreementDeadline( caseData, applicant1ResponseDate )); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimForm.java similarity index 84% rename from src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimForm.java rename to src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimForm.java index b5ce0ceeca6..67aa66ccce0 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimForm.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimForm.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.civil.model.docmosis.draft; +package uk.gov.hmcts.reform.civil.model.docmosis.claimform; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -14,13 +14,15 @@ import uk.gov.hmcts.reform.civil.model.docmosis.lip.LipFormParty; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; @Builder @Getter @EqualsAndHashCode -public class DraftClaimForm implements MappableObject { +public class ClaimForm implements MappableObject { + private final String claimNumber; private final LipFormParty claimant; private final LipFormParty defendant; private final Address claimantCorrespondenceAddress; @@ -46,9 +48,8 @@ public class DraftClaimForm implements MappableObject { private final String interestAmount; private final String claimFee; private final String totalAmountOfClaim; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") - @JsonSerialize(using = LocalDateSerializer.class) - private final LocalDate generationDate; - - + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy 'at' HH:mm a") + private final LocalDateTime generationDate; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd MMM yyyy") + private final LocalDate claimIssuedDate; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimFormMapper.java b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimFormMapper.java similarity index 95% rename from src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimFormMapper.java rename to src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimFormMapper.java index e6e276553f6..0ed1bb1431a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimFormMapper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimFormMapper.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.civil.model.docmosis.draft; +package uk.gov.hmcts.reform.civil.model.docmosis.claimform; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.RequiredArgsConstructor; @@ -29,7 +29,7 @@ @Component @RequiredArgsConstructor -public class DraftClaimFormMapper { +public class ClaimFormMapper { private static final String STANDARD_INTEREST_RATE = "8"; public static final String EXPLANATION_OF_INTEREST_RATE = "The claimant reserves the right to claim interest under " @@ -37,7 +37,7 @@ public class DraftClaimFormMapper { public static final String INTEREST_START_FROM_CLAIM_ISSUED_DATE = "From the date the claim was issued"; private final InterestCalculator interestCalculator; - public DraftClaimForm toDraftClaimForm(CaseData caseData) { + public ClaimForm toClaimForm(CaseData caseData) { BigDecimal interest = interestCalculator.calculateInterest(caseData); Optional caseDataLip = Optional.ofNullable(caseData.getCaseDataLiP()); Optional applicantDetails = @@ -52,9 +52,11 @@ public DraftClaimForm toDraftClaimForm(CaseData caseData) { getContactPerson(applicantDetails) ); String totalClaimAmount = Optional.ofNullable(caseData.getTotalClaimAmount()) + .map(amount -> amount.setScale(2)) .map(BigDecimal::toString) .orElse("0"); - return DraftClaimForm.builder() + + return ClaimForm.builder() .totalInterestAmount(interest != null ? interest.toString() : null) .howTheInterestWasCalculated(Optional.ofNullable(caseData.getInterestClaimOptions()).map( InterestClaimOptions::getDescription).orElse(null)) @@ -79,7 +81,9 @@ public DraftClaimForm toDraftClaimForm(CaseData caseData) { getCorrespondenceAddress(defendantDetails), getContactPerson(defendantDetails) )) - .generationDate(LocalDate.now()) + .generationDate(LocalDateTime.now()) + .claimIssuedDate(caseData.getIssueDate()) + .claimNumber(caseData.getLegacyCaseReference()) .build(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/UpdateClaimStateService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/UpdateClaimStateService.java new file mode 100644 index 00000000000..ec88ed27493 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/UpdateClaimStateService.java @@ -0,0 +1,92 @@ +package uk.gov.hmcts.reform.civil.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.citizenui.CaseDataLiP; +import uk.gov.hmcts.reform.civil.model.citizenui.ClaimantLiPResponse; + +import java.util.Objects; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class UpdateClaimStateService { + + public String setUpCaseState(CaseData updatedData) { + if (isJudicialReferralAllowed(updatedData)) { + return CaseState.JUDICIAL_REFERRAL.name(); + } else if (updatedData.hasDefendantAgreedToFreeMediation() && updatedData.hasClaimantAgreedToFreeMediation()) { + return CaseState.IN_MEDIATION.name(); + } else if (isAllFinalOrderIssued(updatedData)) { + return CaseState.All_FINAL_ORDERS_ISSUED.name(); + } else if (isCaseSettledAllowed(updatedData)) { + return CaseState.CASE_SETTLED.name(); + } else if (updatedData.hasApplicantNotProceededWithClaim()) { + return CaseState.CASE_DISMISSED.name(); + } else if (isProceedsInHeritageSystemAllowed(updatedData)) { + return CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name(); + } else { + return updatedData.getCcdState().name(); + } + } + + private boolean isCaseSettledAllowed(CaseData caseData) { + return ((Objects.nonNull(caseData.getApplicant1PartAdmitIntentionToSettleClaimSpec()) + && caseData.isClaimantIntentionSettlePartAdmit()) + || (caseData.isPartAdmitImmediatePaymentClaimSettled())); + } + + private boolean isProceedsInHeritageSystemAllowed(CaseData caseData) { + ClaimantLiPResponse applicant1Response = Optional.ofNullable(caseData.getCaseDataLiP()) + .map(CaseDataLiP::getApplicant1LiPResponse) + .orElse(null); + boolean isCourtDecisionAccepted = applicant1Response != null + && applicant1Response.hasClaimantAcceptedCourtDecision(); + boolean isCourtDecisionRejected = applicant1Response != null + && applicant1Response.hasClaimantRejectedCourtDecision(); + boolean isCcjRequested = applicant1Response != null + && applicant1Response.hasApplicant1RequestedCcj(); + boolean isInFavourOfClaimant = applicant1Response != null + && applicant1Response.hasCourtDecisionInFavourOfClaimant(); + + return (caseData.hasApplicantRejectedRepaymentPlan() + && caseData.getRespondent1().isCompanyOROrganisation()) + || ((caseData.hasApplicantAcceptedRepaymentPlan() + || isCourtDecisionAccepted + || isInFavourOfClaimant) + && isCcjRequested) + || isCourtDecisionRejected; + } + + private boolean isJudicialReferralAllowed(CaseData caseData) { + return isProceedOrNotSettleClaim(caseData) + && (isClaimantOrDefendantRejectMediation(caseData) + || caseData.isFastTrackClaim()); + } + + private boolean isProceedOrNotSettleClaim(CaseData caseData) { + return caseData.isClaimantNotSettlePartAdmitClaim() || caseData.isFullDefence() || caseData.isFullDefenceNotPaid(); + } + + private boolean isClaimantOrDefendantRejectMediation(CaseData caseData) { + return (Objects.nonNull(caseData.getCaseDataLiP()) && caseData.getCaseDataLiP().hasClaimantNotAgreedToFreeMediation()) + || caseData.hasDefendantNotAgreedToFreeMediation(); + } + + private boolean isAllFinalOrderIssued(CaseData caseData) { + ClaimantLiPResponse applicant1Response = Optional.ofNullable(caseData.getCaseDataLiP()) + .map(CaseDataLiP::getApplicant1LiPResponse) + .orElse(null); + boolean isCourtDecisionAccepted = applicant1Response != null + && applicant1Response.hasClaimantAcceptedCourtDecision(); + boolean isInFavourOfClaimant = applicant1Response != null + && applicant1Response.hasCourtDecisionInFavourOfClaimant(); + + return (caseData.hasApplicantRejectedRepaymentPlan() + && (isCourtDecisionAccepted || isInFavourOfClaimant)) + || caseData.hasApplicantAcceptedRepaymentPlan() + && caseData.hasApplicant1SignedSettlementAgreement(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java index 6223142fc43..bb5a7a6cc42 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java @@ -64,7 +64,9 @@ public enum DocmosisTemplates { ASSISTED_ORDER_PDF("CV-UNS-DEC-ENG-01283.docx", "Order_%s.pdf"), SETTLEMENT_AGREEMENT_PDF("CV-SPC-CLM-ENG-00001-SETTLEMENT.docx", "%s-settlement-agreement.pdf"), CLAIMANT_LIP_MANUAL_DETERMINATION_PDF("CV-SPC-CLM-ENG-00001-LIP-MD.docx", "%s_request-org-repayment-amount.pdf"), - INTERLOCUTORY_JUDGEMENT_DOCUMENT("CV-SPC-CLM-ENG-INTERLOCUTORY-JUDGEMENT.docx", "%s-request-interloc-judgment.pdf"); + INTERLOCUTORY_JUDGEMENT_DOCUMENT("CV-SPC-CLM-ENG-INTERLOCUTORY-JUDGEMENT.docx", "%s-request-interloc-judgment.pdf"), + GENERATE_LIP_CLAIMANT_CLAIM_FORM("CV-SPC-CLM-ENG-CLAIMANT-CLAIM-FORM.docx", "%s-claim-form-claimant-copy.pdf"), + GENERATE_LIP_DEFENDANT_CLAIM_FORM("CV-SPC-CLM-ENG-DEFENDANT-CLAIM-FORM.docx", "%s-sealed-claim-form.pdf"); private final String template; private final String documentTitle; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/claimform/ClaimFormGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/claimform/ClaimFormGenerator.java new file mode 100644 index 00000000000..7c31f4db986 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/claimform/ClaimFormGenerator.java @@ -0,0 +1,77 @@ +package uk.gov.hmcts.reform.civil.service.docmosis.claimform; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; +import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; +import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; +import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; +import uk.gov.hmcts.reform.civil.model.docmosis.claimform.ClaimForm; +import uk.gov.hmcts.reform.civil.model.docmosis.claimform.ClaimFormMapper; +import uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates; +import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; +import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator; + +import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.CLAIMANT_CLAIM_FORM; +import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.SEALED_CLAIM; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.DRAFT_CLAIM_FORM; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.GENERATE_LIP_CLAIMANT_CLAIM_FORM; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.GENERATE_LIP_DEFENDANT_CLAIM_FORM; + +@Service +@Getter +@RequiredArgsConstructor +public class ClaimFormGenerator implements TemplateDataGenerator { + + private final ClaimFormMapper claimFormMapper; + private final DocumentManagementService documentManagementService; + private final DocumentGeneratorService documentGeneratorService; + + public CaseDocument generate(CaseData caseData, String authorisation, CaseEvent caseEvent) { + DocmosisTemplates docmosisTemplates = getDocmosisTemplate(caseEvent); + DocmosisDocument docmosisDocument = documentGeneratorService.generateDocmosisDocument( + getTemplateData(caseData), + docmosisTemplates + ); + + return documentManagementService.uploadDocument( + authorisation, + new PDF( + String.format(docmosisTemplates.getDocumentTitle(), caseData.getLegacyCaseReference()), + docmosisDocument.getBytes(), + getDocumentType(caseEvent) + ) + ); + } + + private DocmosisTemplates getDocmosisTemplate(CaseEvent caseEvent) { + return switch (caseEvent) { + case GENERATE_DRAFT_FORM -> DRAFT_CLAIM_FORM; + case GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC -> GENERATE_LIP_CLAIMANT_CLAIM_FORM; + case GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC -> GENERATE_LIP_DEFENDANT_CLAIM_FORM; + default -> throw new IllegalArgumentException(String.format( + "No Docmosis Template available for %s event", + caseEvent + )); + }; + } + + private DocumentType getDocumentType(CaseEvent caseEvent) { + return switch (caseEvent) { + case GENERATE_DRAFT_FORM -> DocumentType.DRAFT_CLAIM_FORM; + case GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC -> CLAIMANT_CLAIM_FORM; + case GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC -> SEALED_CLAIM; + default -> + throw new IllegalArgumentException(String.format("No DocumentType available for %s event", caseEvent)); + }; + } + + @Override + public ClaimForm getTemplateData(CaseData caseData) { + return claimFormMapper.toClaimForm(caseData); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/draft/DraftClaimFormGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/draft/DraftClaimFormGenerator.java deleted file mode 100644 index 96bbf21d443..00000000000 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/draft/DraftClaimFormGenerator.java +++ /dev/null @@ -1,46 +0,0 @@ -package uk.gov.hmcts.reform.civil.service.docmosis.draft; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; -import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; -import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; -import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; -import uk.gov.hmcts.reform.civil.model.CaseData; -import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; -import uk.gov.hmcts.reform.civil.model.docmosis.draft.DraftClaimForm; -import uk.gov.hmcts.reform.civil.model.docmosis.draft.DraftClaimFormMapper; -import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; -import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator; - -import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.DRAFT_CLAIM_FORM; - -@Service -@Getter -@RequiredArgsConstructor -public class DraftClaimFormGenerator implements TemplateDataGenerator { - - private final DraftClaimFormMapper draftClaimFormMapper; - private final DocumentManagementService documentManagementService; - private final DocumentGeneratorService documentGeneratorService; - - public CaseDocument generate(CaseData caseData, String authorisation) { - DocmosisDocument docmosisDocument = documentGeneratorService.generateDocmosisDocument( - getTemplateData(caseData), - DRAFT_CLAIM_FORM - ); - return documentManagementService.uploadDocument( - authorisation, - new PDF(String.format(DRAFT_CLAIM_FORM.getDocumentTitle(), caseData.getLegacyCaseReference()), - docmosisDocument.getBytes(), - DocumentType.DRAFT_CLAIM_FORM - ) - ); - } - - @Override - public DraftClaimForm getTemplateData(CaseData caseData) { - return draftClaimFormMapper.toDraftClaimForm(caseData); - } -} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/LipApplicantContactDetails.java b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/LipApplicantContactDetails.java new file mode 100644 index 00000000000..0d07203bef1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/LipApplicantContactDetails.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.reform.civil.service.mediation; + +public class LipApplicantContactDetails extends LipContactDetails implements ApplicantContactDetails { + + @Override + public String getApplicantContactName(MediationParams params) { + return getCsvIndividualName(params.getCaseData().getApplicant1()); + } + + @Override + public String getApplicantContactNumber(MediationParams params) { + return params.getCaseData().getApplicant1().getPartyPhone(); + } + + @Override + public String getApplicantContactEmail(MediationParams params) { + return params.getCaseData().getApplicant1Email(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipService.java new file mode 100644 index 00000000000..f6d71cf5243 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipService.java @@ -0,0 +1,27 @@ +package uk.gov.hmcts.reform.civil.service.mediation; + +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.civil.model.CaseData; + +@Service +@AllArgsConstructor +public class MediationCSVLipVLipService extends MediationCSVService { + + @Override + protected ApplicantContactDetails getApplicantContactDetails() { + return new LipApplicantContactDetails(); + } + + @Override + protected DefendantContactDetails getDefendantContactDetails() { + return new LipDefendantContactDetails(); + } + + @Override + protected MediationParams getMediationParams(CaseData caseData) { + return MediationParams.builder() + .caseData(caseData) + .build(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java index e9ddc527dfd..323361210ee 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @Service @RequiredArgsConstructor @@ -10,10 +11,14 @@ public class MediationCsvServiceFactory { private final MediationCSVLrvLrService mediationServiceLrvLr; private final MediationCSVLrvLipService mediationCSVLrvLipService; + private final MediationCSVLipVLipService mediationCSVLipVLipService; + private final FeatureToggleService toggleService; public MediationCSVService getMediationCSVService(CaseData caseData) { - if (caseData.isRespondent1LiP()) { + if (caseData.isRespondent1LiP() && !caseData.isApplicantLiP()) { return mediationCSVLrvLipService; + } else if (caseData.isApplicantLiP() && toggleService.isLipVLipEnabled()) { + return mediationCSVLipVLipService; } return mediationServiceLrvLr; } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimStateAfterUploadingTranslatedDocumentTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimStateAfterUploadingTranslatedDocumentTest.java new file mode 100644 index 00000000000..ca07343f4e7 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimStateAfterUploadingTranslatedDocumentTest.java @@ -0,0 +1,58 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.caseevents; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_CLAIM_STATE_AFTER_TRANSLATED_DOCUMENT_UPLOADED; + +@ExtendWith(MockitoExtension.class) +public class UpdateClaimStateAfterUploadingTranslatedDocumentTest extends BaseCallbackHandlerTest { + + @InjectMocks + private UpdateClaimStateAfterUploadingTranslatedDocuments handler; + @Mock + private ObjectMapper objectMapper; + + public static final String TASK_ID = "updateClaimStateAfterTranslateDocumentUploadedID"; + + @Test + void shouldReturnCorrectActivityId_whenRequested() { + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + assertThat(handler.camundaActivityId(params)).isEqualTo(TASK_ID); + } + + @Test + void shouldRunAboutToSubmitSuccessfully() { + // given + CaseData caseData = CaseDataBuilder.builder().atStateRespondent1v1BilingualFlagSet().build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // when + var response = (AboutToStartOrSubmitCallbackResponse)handler.handle(params); + + // then + assertThat(response.getErrors()).isNull(); + assertThat(response.getState()).isEqualTo(CaseState.AWAITING_APPLICANT_INTENTION.name()); + } + + @Test + void handleEventsReturnsTheExpectedCallbackEvent() { + assertThat(handler.handledEvents()).contains(UPDATE_CLAIM_STATE_AFTER_TRANSLATED_DOCUMENT_UPLOADED); + + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimantIntentionClaimStateCallbackHandlerTests.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimantIntentionClaimStateCallbackHandlerTests.java new file mode 100644 index 00000000000..c1899df41d4 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/UpdateClaimantIntentionClaimStateCallbackHandlerTests.java @@ -0,0 +1,52 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.caseevents; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; +import uk.gov.hmcts.reform.civil.service.UpdateClaimStateService; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; + +@ExtendWith(MockitoExtension.class) +public class UpdateClaimantIntentionClaimStateCallbackHandlerTests extends BaseCallbackHandlerTest { + + @InjectMocks + private UpdateClaimantIntentionClaimStateCallbackHandler handler; + + @Mock + private UpdateClaimStateService updateClaimStateService; + + @Mock + private ObjectMapper objectMapper; + + @Test + void shouldReturnCorrectActivityId_whenRequested() { + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + assertThat(handler.camundaActivityId(params)).isEqualTo("updateClaimantIntentionClaimStateID"); + } + + @Test + void shouldRunAboutToSubmitSuccessfully() { + // given + CaseData caseData = CaseDataBuilder.builder().build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // when + var response = (AboutToStartOrSubmitCallbackResponse)handler.handle(params); + + // then + assertThat(response.getErrors()).isNull(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDraftClaimFormCallBackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDraftClaimFormCallBackHandlerTest.java deleted file mode 100644 index 25ca6b9a98f..00000000000 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDraftClaimFormCallBackHandlerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; -import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; -import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.model.CaseData; -import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService; -import uk.gov.hmcts.reform.civil.service.docmosis.draft.DraftClaimFormGenerator; - -import java.time.LocalDateTime; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DRAFT_CLAIM_FORM; - -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateDraftClaimFormCallBackHandler.class, - JacksonAutoConfiguration.class -}) -class GenerateDraftClaimFormCallBackHandlerTest extends BaseCallbackHandlerTest { - - @MockBean - private DraftClaimFormGenerator draftClaimFormGenerator; - @MockBean - private SystemGeneratedDocumentService systemGeneratedDocumentService; - @Autowired - private GenerateDraftClaimFormCallBackHandler handler; - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - - private static final CaseDocument FORM = CaseDocument.builder() - .createdBy("John") - .documentName("document name") - .documentSize(0L) - .documentType(DRAFT_CLAIM_FORM) - .createdDatetime(LocalDateTime.now()) - .documentLink(Document.builder() - .documentUrl("fake-url") - .documentFileName("file-name") - .documentBinaryUrl("binary-url") - .build()) - .build(); - private static final String BEARER_TOKEN = "BEARER_TOKEN"; - - @Test - void shouldGenerateDraftClaimForm() { - //Given - given(draftClaimFormGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); - CaseData caseData = CaseData.builder().build(); - handler.handle(callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); - verify(draftClaimFormGenerator).generate(caseData, BEARER_TOKEN); - } - -} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateLipClaimFormCallBackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateLipClaimFormCallBackHandlerTest.java new file mode 100644 index 00000000000..459af7aa1d3 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateLipClaimFormCallBackHandlerTest.java @@ -0,0 +1,131 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; +import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; +import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; +import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService; +import uk.gov.hmcts.reform.civil.service.docmosis.claimform.ClaimFormGenerator; + +import java.time.LocalDateTime; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC; +import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DRAFT_CLAIM_FORM; +import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.SEALED_CLAIM; + +@ExtendWith(MockitoExtension.class) +class GenerateLipClaimFormCallBackHandlerTest extends BaseCallbackHandlerTest { + + @Mock + private ClaimFormGenerator claimFormGenerator; + @Mock + private SystemGeneratedDocumentService systemGeneratedDocumentService; + @Mock + private ObjectMapper mapper; + @InjectMocks + private GenerateLipClaimFormCallBackHandler handler; + + private static final String BEARER_TOKEN = "BEARER_TOKEN"; + + @Test + void shouldGenerateDraftClaimForm() { + //Given + given(claimFormGenerator.generate( + any(CaseData.class), + anyString(), + eq(CaseEvent.GENERATE_DRAFT_FORM) + )).willReturn(generateForm(DRAFT_CLAIM_FORM)); + CaseData caseData = CaseData.builder().build(); + CallbackParams callbackParams = buildCallbackParams(caseData, "GENERATE_DRAFT_FORM"); + + // When + handler.handle(callbackParams); + + // Then + verify(claimFormGenerator).generate(caseData, BEARER_TOKEN, CaseEvent.GENERATE_DRAFT_FORM); + + } + + @Test + void shouldGenerateClaimantClaimForm() { + //Given + given(claimFormGenerator.generate( + any(CaseData.class), + anyString(), + eq(CaseEvent.GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC) + )).willReturn(generateForm(DocumentType.CLAIMANT_CLAIM_FORM)); + CaseData caseData = CaseData.builder().build(); + CallbackParams callbackParams = buildCallbackParams(caseData, "GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC"); + + // When + handler.handle(callbackParams); + + // Then + verify(claimFormGenerator).generate(caseData, BEARER_TOKEN, CaseEvent.GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC); + + } + + @Test + void shouldGenerateDefendantClaimForm() { + //Given + given(claimFormGenerator.generate( + any(CaseData.class), + anyString(), + eq(GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC) + )).willReturn(generateForm(SEALED_CLAIM)); + + CaseData caseData = CaseData.builder().build(); + CallbackParams callbackParams = buildCallbackParams(caseData, "GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC"); + + // When + handler.handle(callbackParams); + + //Then + verify(claimFormGenerator).generate(caseData, BEARER_TOKEN, CaseEvent.GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC); + + } + + private CaseDocument generateForm(DocumentType documentType) { + return CaseDocument.builder() + .createdBy("John") + .documentName("document name") + .documentSize(0L) + .documentType(documentType) + .createdDatetime(LocalDateTime.now()) + .documentLink(Document.builder() + .documentUrl("fake-url") + .documentFileName("file-name") + .documentBinaryUrl("binary-url") + .build()) + .build(); + } + + private CallbackParams buildCallbackParams(CaseData caseData, String eventId) { + + return CallbackParams.builder() + .caseData(caseData) + .request(CallbackRequest.builder() + .eventId(eventId) + .build()) + .params(Map.of(CallbackParams.Params.BEARER_TOKEN, "BEARER_TOKEN")) + .type(ABOUT_TO_SUBMIT) + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimFormMapperTest.java b/src/test/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimFormMapperTest.java similarity index 87% rename from src/test/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimFormMapperTest.java rename to src/test/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimFormMapperTest.java index 578c90a4a28..afb526a3f0e 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/model/docmosis/draft/DraftClaimFormMapperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/model/docmosis/claimform/ClaimFormMapperTest.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.civil.model.docmosis.draft; +package uk.gov.hmcts.reform.civil.model.docmosis.claimform; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -30,13 +30,13 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -class DraftClaimFormMapperTest { +class ClaimFormMapperTest { @Mock private InterestCalculator interestCalculator; @InjectMocks - private DraftClaimFormMapper draftClaimFormMapper; + private ClaimFormMapper claimFormMapper; private static final String INDIVIDUAL_TITLE = "Mr."; private static final String INDIVIDUAL_FIRST_NAME = "Hot"; @@ -81,7 +81,7 @@ void should_displayIndividualName_whenPartiesIndividual() { .build()) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getClaimant().name()).isEqualTo(caseData.getApplicant1().getPartyName()); assertThat(form.getDefendant().name()).isEqualTo(caseData.getRespondent1().getPartyName()); @@ -109,7 +109,7 @@ void shouldDisplay_soleTraderInformation_whenPartiesAreSoleTrader() { .build()) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getClaimant().name()).isEqualTo(caseData.getApplicant1().getPartyName()); assertThat(form.getDefendant().name()).isEqualTo(caseData.getRespondent1().getPartyName()); @@ -136,7 +136,7 @@ void shouldDisplayCompany_whenPartiesAreCompany() { .build()) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getClaimant().name()).isEqualTo(COMPANY); assertThat(form.getDefendant().name()).isEqualTo(COMPANY); @@ -161,7 +161,7 @@ void shouldDisplayOrganisationName_whenPartiesAreOrganisation() { .build()) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getClaimant().name()).isEqualTo(ORGANISATION); assertThat(form.getDefendant().name()).isEqualTo(ORGANISATION); @@ -172,7 +172,7 @@ void shouldShowInterest_whenExists() { //Given given(interestCalculator.calculateInterest(CASE_DATA)).willReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getInterestAmount()).isEqualTo(INTEREST.toString()); assertThat(form.getTotalInterestAmount()).isEqualTo(INTEREST.toString()); @@ -183,7 +183,7 @@ void shouldDisplayNull_whenNoInterestExists() { //Given given(interestCalculator.calculateInterest(CASE_DATA)).willReturn(null); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getInterestAmount()).isNull(); assertThat(form.getTotalInterestAmount()).isNull(); @@ -196,7 +196,7 @@ void shouldMapHowInterestWasCalculated_whenInterestOptionExists() { .interestClaimOptions(InterestClaimOptions.SAME_RATE_INTEREST) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getHowTheInterestWasCalculated()) .isEqualTo(InterestClaimOptions.SAME_RATE_INTEREST.getDescription()); @@ -205,7 +205,7 @@ void shouldMapHowInterestWasCalculated_whenInterestOptionExists() { @Test void shouldReturnNullForHowInterestWasCalculated_whenInterestOptionIsNull() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getHowTheInterestWasCalculated()).isNull(); } @@ -218,7 +218,7 @@ void shouldReturnDifferentInterestRate_whenItExists() { .differentRate(INTEREST).build()) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestRate()).isEqualTo(INTEREST.toString()); } @@ -230,7 +230,7 @@ void shouldReturnEightPercentInterestRate_whenDifferentRateIsNull() { .sameRateInterestSelection(SameRateInterestSelection.builder().build()) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestRate()).isEqualTo(STANDARD_INTEREST_RATE); } @@ -238,7 +238,7 @@ void shouldReturnEightPercentInterestRate_whenDifferentRateIsNull() { @Test void shouldReturnNull_whenSameInterestSelectionIsNull() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getInterestRate()).isNull(); } @@ -253,9 +253,9 @@ void shouldReturnStandardExplanationText_whenNoDifferentRateReason() { when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then - assertThat(form.getInterestExplanationText()).isEqualTo(DraftClaimFormMapper.EXPLANATION_OF_INTEREST_RATE); + assertThat(form.getInterestExplanationText()).isEqualTo(ClaimFormMapper.EXPLANATION_OF_INTEREST_RATE); } @Test @@ -268,7 +268,7 @@ void shouldReturnDifferentExplanationText_whenDifferentRateReasonExists() { .build(); when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestExplanationText()).isEqualTo(DIFFERENT_RATE_EXPLANATION); } @@ -276,7 +276,7 @@ void shouldReturnDifferentExplanationText_whenDifferentRateReasonExists() { @Test void shouldReturnNullForInterestExplanation_whenNoInterestRateSelection() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getInterestExplanationText()).isNull(); } @@ -289,7 +289,7 @@ void shouldReturnInterestFromSpecificDate_whenInterestFromSpecificDateExists() { .build(); when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestFromDate()).isEqualTo(INTEREST_FROM_SPECIFIC_DATE); } @@ -302,7 +302,7 @@ void shouldReturnInterestFromClaimIssueDate_whenInterestFromSpecificDateIsNull() .build(); when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestFromDate()).isEqualTo(SUBMITTED_DATE.toLocalDate()); } @@ -310,7 +310,7 @@ void shouldReturnInterestFromClaimIssueDate_whenInterestFromSpecificDateIsNull() @Test void shouldReturnNullForInterestFromDate_whenSubmittedDateIsNull() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getInterestFromDate()).isNull(); } @@ -318,7 +318,7 @@ void shouldReturnNullForInterestFromDate_whenSubmittedDateIsNull() { @Test void shouldReturnNullForWhenAreYouPlanningInterestFrom_whenInterestFromIsNull() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getWhenAreYouClaimingInterestFrom()).isNull(); } @@ -332,10 +332,10 @@ void shouldReturnInterestStartFromClaimIssue_whenInterestClaimFromTypeIsFromClai .build(); when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getWhenAreYouClaimingInterestFrom()) - .isEqualTo(DraftClaimFormMapper.INTEREST_START_FROM_CLAIM_ISSUED_DATE); + .isEqualTo(ClaimFormMapper.INTEREST_START_FROM_CLAIM_ISSUED_DATE); } @Test @@ -348,7 +348,7 @@ void shouldReturnSpecificDescriptionForWhenAreYouPlanningInterestFrom_whenIntere .build(); when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getWhenAreYouClaimingInterestFrom()) .isEqualTo(caseData.getInterestFromSpecificDateDescription()); @@ -362,7 +362,7 @@ void shouldReturnZeroForTotalClaimAmount_whenTotalClaimAmountIsNull() { IdamUserDetails.builder().email(EMAIL).build() ).totalClaimAmount(null).build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getTotalClaimAmount()).isEqualTo("0"); } @@ -370,9 +370,9 @@ void shouldReturnZeroForTotalClaimAmount_whenTotalClaimAmountIsNull() { @Test void shouldReturnTotalClaimAmount_whenTotalClaimAmountExists() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then - assertThat(form.getTotalClaimAmount()).isEqualTo(TOTAL_CLAIM_AMOUNT.toString()); + assertThat(form.getTotalClaimAmount()).isEqualTo(TOTAL_CLAIM_AMOUNT.setScale(2).toString()); } @Test @@ -384,7 +384,7 @@ void shouldReturnTotalAmountOfClaimWithInterest_whenInterestIsNotNull() { .build(); given(interestCalculator.calculateInterest(caseData)).willReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getTotalAmountOfClaim()) .isEqualTo(INTEREST.add(TOTAL_CLAIM_AMOUNT).add(MonetaryConversions.penniesToPounds(CLAIM_FEE)).toString()); @@ -398,7 +398,7 @@ void shouldReturnEndInterestDate_whenEndDateDescritptionIsNull() { .build(); when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestEndDate()).isNotNull(); } @@ -411,7 +411,7 @@ void shouldReturnNullForEndInterestDate_whenEndDateDescriptionExists() { .breakDownInterestDescription(DIFFERENT_RATE_EXPLANATION) .build(); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestEndDate()).isNull(); } @@ -426,7 +426,7 @@ void shouldReturnInterestEndDateDescription_whenBreakDownInterestDescriptionExis when(interestCalculator.calculateInterest(any())).thenReturn(INTEREST); //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(caseData); + ClaimForm form = claimFormMapper.toClaimForm(caseData); //Then assertThat(form.getInterestEndDateDescription()).isEqualTo(DIFFERENT_RATE_EXPLANATION); } @@ -434,13 +434,30 @@ void shouldReturnInterestEndDateDescription_whenBreakDownInterestDescriptionExis @Test void shouldReturnNullForInterestEndDateDescription_whenBreakDownInterestDescriptionIsNull() { //When - DraftClaimForm form = draftClaimFormMapper.toDraftClaimForm(CASE_DATA); + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); //Then assertThat(form.getInterestEndDateDescription()).isNull(); } + @Test + void shouldMapIssueDate() { + //When + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); + //Then + assertThat(form.getClaimIssuedDate()).isEqualTo(LocalDate.now()); + } + + @Test + void shouldMapClaimNumber() { + //When + ClaimForm form = claimFormMapper.toClaimForm(CASE_DATA); + //Then + assertThat(form.getClaimNumber()).isEqualTo("000MC038"); + } + private static CaseData getCaseData() { CaseData caseData = CaseData.builder() + .legacyCaseReference("000MC038") .applicant1(Party.builder() .companyName(ORGANISATION) .partyEmail(EMAIL) @@ -460,6 +477,7 @@ private static CaseData getCaseData() { .builder() .build()) .build()) + .issueDate(LocalDate.now()) .build(); return caseData; } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java index 03f699e50c7..102fd258312 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java @@ -15,8 +15,10 @@ import uk.gov.hmcts.reform.civil.enums.ExpertReportsSent; import uk.gov.hmcts.reform.civil.enums.MediationDecision; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.PaymentFrequencyClaimantResponseLRspec; import uk.gov.hmcts.reform.civil.enums.PaymentFrequencyLRspec; import uk.gov.hmcts.reform.civil.enums.PaymentStatus; +import uk.gov.hmcts.reform.civil.enums.PaymentType; import uk.gov.hmcts.reform.civil.enums.PersonalInjuryType; import uk.gov.hmcts.reform.civil.enums.ReasonForProceedingOnPaper; import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; @@ -29,20 +31,16 @@ import uk.gov.hmcts.reform.civil.enums.dj.DisposalHearingBundleType; import uk.gov.hmcts.reform.civil.enums.dj.DisposalHearingFinalDisposalHearingTimeEstimate; import uk.gov.hmcts.reform.civil.enums.dj.DisposalHearingMethodDJ; -import uk.gov.hmcts.reform.civil.enums.dq.UnavailableDateType; import uk.gov.hmcts.reform.civil.enums.dq.SupportRequirements; +import uk.gov.hmcts.reform.civil.enums.dq.UnavailableDateType; import uk.gov.hmcts.reform.civil.enums.hearing.HearingDuration; import uk.gov.hmcts.reform.civil.enums.hearing.ListingOrRelisting; import uk.gov.hmcts.reform.civil.enums.mediation.MediationUnsuccessfulReason; +import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle; import uk.gov.hmcts.reform.civil.enums.sdo.DisposalHearingMethod; import uk.gov.hmcts.reform.civil.enums.sdo.FastTrackHearingTimeEstimate; import uk.gov.hmcts.reform.civil.enums.sdo.TrialHearingTimeEstimateDJ; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.ResponseOneVOneShowTag; -import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle; -import uk.gov.hmcts.reform.civil.model.FlightDelayDetails; -import uk.gov.hmcts.reform.civil.model.MediationAgreementDocument; -import uk.gov.hmcts.reform.civil.model.MediationSuccessful; -import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.Bundle; import uk.gov.hmcts.reform.civil.model.BusinessProcess; @@ -59,6 +57,7 @@ import uk.gov.hmcts.reform.civil.model.CourtLocation; import uk.gov.hmcts.reform.civil.model.DefendantPinToPostLRspec; import uk.gov.hmcts.reform.civil.model.Fee; +import uk.gov.hmcts.reform.civil.model.FlightDelayDetails; import uk.gov.hmcts.reform.civil.model.HearingDates; import uk.gov.hmcts.reform.civil.model.HearingSupportRequirementsDJ; import uk.gov.hmcts.reform.civil.model.IdValue; @@ -66,23 +65,27 @@ import uk.gov.hmcts.reform.civil.model.LengthOfUnemploymentComplexTypeLRspec; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.Mediation; +import uk.gov.hmcts.reform.civil.model.MediationAgreementDocument; +import uk.gov.hmcts.reform.civil.model.MediationSuccessful; import uk.gov.hmcts.reform.civil.model.PartnerAndDependentsLRspec; import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; +import uk.gov.hmcts.reform.civil.model.PaymentBySetDate; import uk.gov.hmcts.reform.civil.model.PaymentDetails; import uk.gov.hmcts.reform.civil.model.RepaymentPlanLRspec; import uk.gov.hmcts.reform.civil.model.RespondToClaim; import uk.gov.hmcts.reform.civil.model.RespondToClaimAdmitPartLRspec; import uk.gov.hmcts.reform.civil.model.Respondent1EmployerDetailsLRspec; import uk.gov.hmcts.reform.civil.model.ResponseDocument; -import uk.gov.hmcts.reform.civil.model.ServedDocumentFiles; import uk.gov.hmcts.reform.civil.model.SRPbaDetails; +import uk.gov.hmcts.reform.civil.model.ServedDocumentFiles; import uk.gov.hmcts.reform.civil.model.SmallClaimMedicalLRspec; import uk.gov.hmcts.reform.civil.model.SolicitorOrganisationDetails; import uk.gov.hmcts.reform.civil.model.SolicitorReferences; import uk.gov.hmcts.reform.civil.model.StatementOfTruth; import uk.gov.hmcts.reform.civil.model.UnavailableDate; import uk.gov.hmcts.reform.civil.model.UnemployedComplexTypeLRspec; +import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; import uk.gov.hmcts.reform.civil.model.breathing.BreathingSpaceEnterInfo; import uk.gov.hmcts.reform.civil.model.breathing.BreathingSpaceInfo; import uk.gov.hmcts.reform.civil.model.breathing.BreathingSpaceLiftInfo; @@ -128,12 +131,12 @@ import uk.gov.hmcts.reform.civil.model.interestcalc.InterestClaimUntilType; import uk.gov.hmcts.reform.civil.model.interestcalc.SameRateInterestSelection; import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentInstalmentDetails; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentPaidInFull; import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentRecordedReason; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentStatusDetails; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentStatusType; import uk.gov.hmcts.reform.civil.model.judgmentonline.PaymentFrequency; import uk.gov.hmcts.reform.civil.model.judgmentonline.PaymentPlanSelection; -import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentPaidInFull; -import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentStatusType; -import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentStatusDetails; import uk.gov.hmcts.reform.civil.model.mediation.MediationDocumentsReferredInStatement; import uk.gov.hmcts.reform.civil.model.mediation.MediationDocumentsType; import uk.gov.hmcts.reform.civil.model.mediation.MediationNonAttendanceStatement; @@ -6537,6 +6540,12 @@ private List> buildMediationDocum .build()); } + public CaseDataBuilder atStateRespondent1v1BilingualFlagSet() { + respondent1ClaimResponseTypeForSpec = RespondentResponseTypeSpec.FULL_ADMISSION; + ccdState = AWAITING_RESPONDENT_ACKNOWLEDGEMENT; + return this; + } + public static CaseDataBuilder builder() { return new CaseDataBuilder(); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/UpdateClaimStateServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/UpdateClaimStateServiceTest.java new file mode 100644 index 00000000000..cf16a193871 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/UpdateClaimStateServiceTest.java @@ -0,0 +1,333 @@ +package uk.gov.hmcts.reform.civil.service; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; + +import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.enums.MediationDecision; +import uk.gov.hmcts.reform.civil.enums.PaymentType; +import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.citizenui.CaseDataLiP; +import uk.gov.hmcts.reform.civil.model.citizenui.ChooseHowToProceed; +import uk.gov.hmcts.reform.civil.model.citizenui.ClaimantLiPResponse; +import uk.gov.hmcts.reform.civil.model.citizenui.ClaimantMediationLip; +import uk.gov.hmcts.reform.civil.model.citizenui.dto.ClaimantResponseOnCourtDecisionType; +import uk.gov.hmcts.reform.civil.model.citizenui.dto.RepaymentDecisionType; +import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.FAST_CLAIM; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.model.Party.Type.COMPANY; + +@ExtendWith(MockitoExtension.class) +class UpdateClaimStateServiceTest { + + @InjectMocks + private UpdateClaimStateService service; + + @Test + void shouldUpdateCaseStateToJudicialReferral_WhenPartAdmitNoSettle_NoMediation() { + //Given + CaseDataLiP caseDataLiP = CaseDataLiP.builder() + .applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder() + .hasAgreedFreeMediation(MediationDecision.No).build()) + .build(); + CaseData caseData = CaseDataBuilder.builder() + .caseDataLip(caseDataLiP) + .applicant1AcceptAdmitAmountPaidSpec(NO) + .atStateClaimIssued().build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertEquals(CaseState.JUDICIAL_REFERRAL.name(), response); + + } + + @Test + void shouldUpdateCaseStateToJudicialReferral_WhenNotReceivedPayment_NoMediation_ForPartAdmit() { + //Given + CaseDataLiP caseDataLiP = CaseDataLiP.builder() + .applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder() + .hasAgreedFreeMediation(MediationDecision.No).build()) + .build(); + CaseData caseData = CaseDataBuilder.builder() + .caseDataLip(caseDataLiP) + .applicant1PartAdmitConfirmAmountPaidSpec(NO) + .atStateClaimIssued().build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertEquals(CaseState.JUDICIAL_REFERRAL.name(), response); + + } + + @Test + void shouldUpdateCaseStateToJudicialReferral_WhenFullDefence_NotPaid_NoMediation() { + //Given + CaseDataLiP caseDataLiP = CaseDataLiP.builder() + .applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder() + .hasAgreedFreeMediation(MediationDecision.No).build()) + .build(); + CaseData caseData = + CaseDataBuilder.builder().caseDataLip(caseDataLiP).applicant1PartAdmitIntentionToSettleClaimSpec(NO) + .atStateClaimIssued() + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertEquals(CaseState.JUDICIAL_REFERRAL.name(), response); + + } + + @Test + void shouldUpdateCaseStateToJudicialReferral_WhenFullDefence_NotPaid_FastTrack() { + //Given + CaseData caseData = + CaseDataBuilder.builder().applicant1PartAdmitIntentionToSettleClaimSpec(NO) + .responseClaimTrack(FAST_CLAIM.name()) + .atStateClaimIssued() + .build(); + //When + var response = service.setUpCaseState(caseData); + //Then + assertEquals(CaseState.JUDICIAL_REFERRAL.name(), response); + + } + + @Test + void shouldUpdateCaseStateToJudicialReferral_WhenFullDefence() { + //Given + CaseDataLiP caseDataLiP = CaseDataLiP.builder() + .applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder() + .hasAgreedFreeMediation(MediationDecision.No).build()) + .build(); + CaseData caseData = + CaseDataBuilder.builder().caseDataLip(caseDataLiP).applicant1ProceedWithClaim(YES) + .atStateClaimIssued() + .build(); + //When + var response = service.setUpCaseState(caseData); + //Then + assertEquals(CaseState.JUDICIAL_REFERRAL.name(), response); + } + + @Test + void shouldUpdateCaseStateToCaseDismissed_WhenFullDefence_FastTrack() { + //Given + CaseData caseData = + CaseDataBuilder.builder().applicant1ProceedWithClaim(NO) + .responseClaimTrack(FAST_CLAIM.name()) + .atStateClaimIssued() + .build(); + //When + var response = service.setUpCaseState(caseData); + //Then + assertEquals(CaseState.CASE_DISMISSED.name(), response); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectClaimSettlementAndAgreeToMediation() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .applicant1PartAdmitConfirmAmountPaidSpec(NO) + .caseDataLip(CaseDataLiP.builder().applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder().hasAgreedFreeMediation( + MediationDecision.Yes).build()) + .build()) + .build().toBuilder() + .responseClaimMediationSpecRequired(YES).build(); + + //When + var response = service.setUpCaseState(caseData); + //Then + assertThat(response).isEqualTo(CaseState.IN_MEDIATION.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantAcceptRepaymentPlanAndChooseSettlementAgreement() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .applicant1AcceptPartAdmitPaymentPlanSpec(YesOrNo.YES) + .caseDataLip(CaseDataLiP.builder().applicant1LiPResponse(ClaimantLiPResponse.builder() + .applicant1SignedSettlementAgreement( + YesOrNo.YES).build()) + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.All_FINAL_ORDERS_ISSUED.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantAgreeClaimSettlement() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .applicant1PartAdmitIntentionToSettleClaimSpec(YES) + .applicant1PartAdmitConfirmAmountPaidSpec(YES) + .build().toBuilder() + .responseClaimMediationSpecRequired(YES).build(); + + //When + var response = service.setUpCaseState(caseData); + //Then + assertThat(response).isEqualTo(CaseState.CASE_SETTLED.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectRepaymentPlanAndIsCompany_toAllFinalOrdersIssued() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .applicant1AcceptPartAdmitPaymentPlanSpec(NO) + .caseDataLip(CaseDataLiP.builder().applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder().hasAgreedFreeMediation( + MediationDecision.No).build()).build()) + .applicant1(Party.builder().type(Party.Type.COMPANY).companyName("CLAIMANT_ORG_NAME").build()) + .respondent1(Party.builder() + .type(COMPANY) + .companyName("Test Inc") + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantAcceptedPartAdmitImmediatePayment() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .applicant1AcceptAdmitAmountPaidSpec(YES) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) + .applicant1RepaymentOptionForDefendantSpec(PaymentType.IMMEDIATELY) + .applicant1(Party.builder().type(Party.Type.COMPANY).companyName("CLAIMANT_ORG_NAME").build()) + .respondent1(Party.builder() + .type(COMPANY) + .companyName("Test Inc") + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.CASE_SETTLED.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectedRepaymentPlanAndRequestCCJ_CourtAcceptsClaimantDecision_ForPartAmit() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .applicant1(Party.builder().type(Party.Type.INDIVIDUAL).partyName("CLAIMANT_NAME").build()) + .caseDataLip(CaseDataLiP.builder() + .applicant1LiPResponse(ClaimantLiPResponse.builder() + .claimantCourtDecision(RepaymentDecisionType.IN_FAVOUR_OF_CLAIMANT) + .applicant1ChoosesHowToProceed(ChooseHowToProceed.REQUEST_A_CCJ) + .build()).build()) + .respondent1(Party.builder() + .type(Party.Type.INDIVIDUAL) + .partyName("CLAIMANT_NAME") + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectedRepaymentPlanAndRequestCCJ_RejectedManualDetermination_ForPartAmit_PayBySetDate() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .applicant1(Party.builder().type(Party.Type.INDIVIDUAL).partyName("CLAIMANT_NAME").build()) + .caseDataLip(CaseDataLiP.builder() + .applicant1LiPResponse(ClaimantLiPResponse.builder() + .claimantResponseOnCourtDecision( + ClaimantResponseOnCourtDecisionType.JUDGE_REPAYMENT_DATE + ) + .build()).build()) + .respondent1(Party.builder() + .type(Party.Type.INDIVIDUAL) + .partyName("CLAIMANT_NAME") + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectedRepaymentPlanAndRequestCCJ_AcceptManualDetermination_ForPartAmit_ForPayByInstalments() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .applicant1(Party.builder().type(Party.Type.INDIVIDUAL).partyName("CLAIMANT_NAME").build()) + .caseDataLip(CaseDataLiP.builder() + .applicant1LiPResponse(ClaimantLiPResponse.builder() + .claimantResponseOnCourtDecision( + ClaimantResponseOnCourtDecisionType.ACCEPT_REPAYMENT_PLAN + ) + .applicant1ChoosesHowToProceed(ChooseHowToProceed.REQUEST_A_CCJ) + .build()).build()) + .respondent1(Party.builder() + .type(Party.Type.INDIVIDUAL) + .partyName("CLAIMANT_NAME") + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectedRepaymentPlanAndRequestCCJ_AcceptManualDetermination_ForPartAmit_ForPayBySetDate() { + //Given + CaseData caseData = CaseDataBuilder.builder() + .applicant1(Party.builder().type(Party.Type.INDIVIDUAL).partyName("CLAIMANT_NAME").build()) + .caseDataLip(CaseDataLiP.builder() + .applicant1LiPResponse(ClaimantLiPResponse.builder() + .claimantResponseOnCourtDecision( + ClaimantResponseOnCourtDecisionType.ACCEPT_REPAYMENT_DATE + ) + .applicant1ChoosesHowToProceed(ChooseHowToProceed.REQUEST_A_CCJ) + .build()).build()) + .respondent1(Party.builder() + .type(Party.Type.INDIVIDUAL) + .partyName("CLAIMANT_NAME") + .build()) + .build(); + + //When + var response = service.setUpCaseState(caseData); + + //Then + assertThat(response).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/claimform/ClaimFormGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/claimform/ClaimFormGeneratorTest.java new file mode 100644 index 00000000000..03be90c4e0e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/claimform/ClaimFormGeneratorTest.java @@ -0,0 +1,117 @@ +package uk.gov.hmcts.reform.civil.service.docmosis.claimform; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; +import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; +import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; +import uk.gov.hmcts.reform.civil.model.docmosis.claimform.ClaimForm; +import uk.gov.hmcts.reform.civil.model.docmosis.claimform.ClaimFormMapper; +import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.verify; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_DRAFT_FORM; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.DRAFT_CLAIM_FORM; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.GENERATE_LIP_CLAIMANT_CLAIM_FORM; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.GENERATE_LIP_DEFENDANT_CLAIM_FORM; + +@ExtendWith(MockitoExtension.class) +class ClaimFormGeneratorTest { + + private static final String AUTHORISATION = "authorisation"; + @Mock + private ClaimFormMapper claimFormMapper; + @Mock + private DocumentManagementService documentManagementService; + @Mock + private DocumentGeneratorService documentGeneratorService; + + @Captor + ArgumentCaptor uploadDocumentArgumentCaptor; + + @InjectMocks + private ClaimFormGenerator generator; + + @Test + void shouldGenerateDraftClaimForm() { + //Given + CaseData caseData = CaseData.builder().build(); + ClaimForm claimForm = ClaimForm.builder().build(); + given(claimFormMapper.toClaimForm(any())).willReturn(claimForm); + DocmosisDocument docmosisDocument = DocmosisDocument.builder().build(); + given(documentGeneratorService.generateDocmosisDocument(any(ClaimForm.class), any())).willReturn( + docmosisDocument); + + //When + generator.generate(caseData, AUTHORISATION, GENERATE_DRAFT_FORM); + + //Then + verify(documentGeneratorService).generateDocmosisDocument(claimForm, DRAFT_CLAIM_FORM); + verify(documentManagementService).uploadDocument( + eq(AUTHORISATION), + uploadDocumentArgumentCaptor.capture() + ); + PDF document = uploadDocumentArgumentCaptor.getValue(); + assertThat(document.getDocumentType()).isEqualTo(DocumentType.DRAFT_CLAIM_FORM); + } + + @Test + void shouldGenerateClaimantClaimForm() { + //Given + CaseData caseData = CaseData.builder().build(); + ClaimForm claimForm = ClaimForm.builder().build(); + given(claimFormMapper.toClaimForm(any())).willReturn(claimForm); + DocmosisDocument docmosisDocument = DocmosisDocument.builder().build(); + given(documentGeneratorService.generateDocmosisDocument(any(ClaimForm.class), any())).willReturn( + docmosisDocument); + + //When + generator.generate(caseData, AUTHORISATION, CaseEvent.GENERATE_LIP_CLAIMANT_CLAIM_FORM_SPEC); + + //Then + verify(documentGeneratorService).generateDocmosisDocument(claimForm, GENERATE_LIP_CLAIMANT_CLAIM_FORM); + verify(documentManagementService).uploadDocument( + eq(AUTHORISATION), + uploadDocumentArgumentCaptor.capture() + ); + PDF document = uploadDocumentArgumentCaptor.getValue(); + assertThat(document.getDocumentType()).isEqualTo(DocumentType.CLAIMANT_CLAIM_FORM); + } + + @Test + void shouldGenerateDefendantClaimForm() { + //Given + CaseData caseData = CaseData.builder().build(); + ClaimForm claimForm = ClaimForm.builder().build(); + given(claimFormMapper.toClaimForm(any())).willReturn(claimForm); + DocmosisDocument docmosisDocument = DocmosisDocument.builder().build(); + given(documentGeneratorService.generateDocmosisDocument(any(ClaimForm.class), any())).willReturn( + docmosisDocument); + + //When + generator.generate(caseData, AUTHORISATION, GENERATE_LIP_DEFENDANT_CLAIM_FORM_SPEC); + + //Then + verify(documentGeneratorService).generateDocmosisDocument(claimForm, GENERATE_LIP_DEFENDANT_CLAIM_FORM); + verify(documentManagementService).uploadDocument( + eq(AUTHORISATION), + uploadDocumentArgumentCaptor.capture() + ); + PDF document = uploadDocumentArgumentCaptor.getValue(); + assertThat(document.getDocumentType()).isEqualTo(DocumentType.SEALED_CLAIM); + } + +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/draft/DraftClaimFormGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/draft/DraftClaimFormGeneratorTest.java deleted file mode 100644 index dd75f3e8801..00000000000 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/draft/DraftClaimFormGeneratorTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package uk.gov.hmcts.reform.civil.service.docmosis.draft; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; -import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; -import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; -import uk.gov.hmcts.reform.civil.model.CaseData; -import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; -import uk.gov.hmcts.reform.civil.model.docmosis.draft.DraftClaimForm; -import uk.gov.hmcts.reform.civil.model.docmosis.draft.DraftClaimFormMapper; -import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.DRAFT_CLAIM_FORM; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = { - DraftClaimFormGenerator.class, - JacksonAutoConfiguration.class, -}) -class DraftClaimFormGeneratorTest { - - private static final String AUTHORISATION = "authorisation"; - @MockBean - private DraftClaimFormMapper draftClaimFormMapper; - @MockBean - private DocumentManagementService documentManagementService; - @MockBean - private DocumentGeneratorService documentGeneratorService; - @Autowired - private DraftClaimFormGenerator generator; - @Captor - ArgumentCaptor uploadDocumentArgumentCaptor; - - @Test - void shouldGenerateDraftClaimForm() { - //Given - CaseData caseData = CaseData.builder().build(); - DraftClaimForm draftClaimForm = DraftClaimForm.builder().build(); - given(draftClaimFormMapper.toDraftClaimForm(any())).willReturn(draftClaimForm); - DocmosisDocument docmosisDocument = DocmosisDocument.builder().build(); - given(documentGeneratorService.generateDocmosisDocument(any(DraftClaimForm.class), any())).willReturn( - docmosisDocument); - //When - generator.generate(caseData, AUTHORISATION); - //Then - verify(documentGeneratorService).generateDocmosisDocument(draftClaimForm, DRAFT_CLAIM_FORM); - verify(documentManagementService).uploadDocument( - eq(AUTHORISATION), - uploadDocumentArgumentCaptor.capture() - ); - PDF document = uploadDocumentArgumentCaptor.getValue(); - assertThat(document.getDocumentType()).isEqualTo(DocumentType.DRAFT_CLAIM_FORM); - } - -} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipServiceTest.java new file mode 100644 index 00000000000..7b2e7253f24 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipServiceTest.java @@ -0,0 +1,166 @@ +package uk.gov.hmcts.reform.civil.service.mediation; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.Party; + +import java.math.BigDecimal; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@SpringBootTest(classes = { + MediationCSVLipVLipService.class +}) +public class MediationCSVLipVLipServiceTest { + + private static final String APPLICANT_COMPANY_NAME = "Applicant company name"; + private static final String APPLICANT_ORGANISATION_NAME = "Applicant organisation name"; + private static final String APPLICANT_EMAIL_ADDRESS = "Applicant@company.com"; + private static final String APPLICANT_PHONE_NUMBER = "7553072111"; + private static final String APPLICANT_INDIVIDUAL_FIST_NAME = "Applicant Individual First Name"; + private static final String APPLICANT_INDIVIDUAL_LAST_NAME = "Applicant Individual Last Name"; + private static final String APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME = "Applicant Sole Trader First Name"; + private static final String APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME = "Applicant Sole Trader Last Name"; + private static final String RESPONDENT_COMPANY_NAME = "Respondent company name"; + private static final String RESPONDENT_ORGANISATION_NAME = "Respondent organisation name"; + private static final String RESPONDENT_EMAIL_ADDRESS = "respondent@company.com"; + private static final String RESPONDENT_PHONE_NUMBER = "0022002200"; + private static final String RESPONDENT_INDIVIDUAL_FIST_NAME = "Respondent Individual First Name"; + private static final String RESPONDENT_INDIVIDUAL_LAST_NAME = "Respondent Individual Last Name"; + private static final String RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME = "Respondent Sole Trader First Name"; + private static final String RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME = "Respondent Sole Trader Last Name"; + private static final String TOTAL_AMOUNT = "9000"; + private static final String ID = "123456789"; + private static final String RESPONDENT = "2"; + private static final String APPLICANT = "1"; + + @Autowired + private MediationCSVLipVLipService service; + + @Test + void shouldReturn_properDataForFile_ForIndividual() { + //Given + CaseData caseData = getCaseData(Party.Type.INDIVIDUAL); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_INDIVIDUAL_FIST_NAME + " " + APPLICANT_INDIVIDUAL_LAST_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_INDIVIDUAL_FIST_NAME + " " + RESPONDENT_INDIVIDUAL_LAST_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForCompany() { + //Given + CaseData caseData = getCaseData(Party.Type.COMPANY); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_COMPANY_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_COMPANY_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForOrganisation() { + //Given + CaseData caseData = getCaseData(Party.Type.ORGANISATION); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_ORGANISATION_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_ORGANISATION_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForSoleTrader() { + //Given + CaseData caseData = getCaseData(Party.Type.SOLE_TRADER); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForBilingualFlag() { + //Given + CaseData caseData = getCaseData(Party.Type.SOLE_TRADER); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + private CaseData getCaseData(Party.Type partyType) { + CaseData caseData = CaseData.builder() + .legacyCaseReference(ID) + .totalClaimAmount(new BigDecimal(9000)) + .applicant1(Party.builder() + .type(partyType) + .companyName(APPLICANT_COMPANY_NAME) + .partyPhone(APPLICANT_PHONE_NUMBER) + .partyEmail(APPLICANT_EMAIL_ADDRESS) + .individualFirstName(APPLICANT_INDIVIDUAL_FIST_NAME) + .individualLastName(APPLICANT_INDIVIDUAL_LAST_NAME) + .soleTraderFirstName(APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME) + .soleTraderLastName(APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME) + .organisationName(APPLICANT_ORGANISATION_NAME) + .build()) + .respondent1(Party.builder() + .type(partyType) + .soleTraderFirstName(RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME) + .soleTraderLastName(RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME) + .individualFirstName(RESPONDENT_INDIVIDUAL_FIST_NAME) + .individualLastName(RESPONDENT_INDIVIDUAL_LAST_NAME) + .companyName(RESPONDENT_COMPANY_NAME) + .organisationName(RESPONDENT_ORGANISATION_NAME) + .partyPhone(RESPONDENT_PHONE_NUMBER) + .partyEmail(RESPONDENT_EMAIL_ADDRESS) + .build()) + .build(); + return caseData; + } +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java index 611e6dfaec8..ccdb35b0156 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java @@ -6,6 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.OrganisationService; import static org.assertj.core.api.Assertions.assertThat; @@ -14,6 +15,7 @@ @SpringBootTest(classes = { MediationCSVLrvLipService.class, MediationCSVLrvLrService.class, + MediationCSVLipVLipService.class, MediationCsvServiceFactory.class }) public class MediationCSVServiceFactoryTest { @@ -24,6 +26,9 @@ public class MediationCSVServiceFactoryTest { @MockBean private OrganisationService organisationService; + @MockBean + private FeatureToggleService toggleService; + @Autowired private MediationCsvServiceFactory mediationCsvServiceFactory; @@ -46,4 +51,16 @@ void shouldReturnMediationCSVLrvLip_whenDefendantLip() { //Then assertThat(mediationCSVService).isInstanceOf(MediationCSVLrvLipService.class); } + + @Test + void shouldReturnMediationCSVLipVLip_whenApplicantLip() { + //Given + given(toggleService.isLipVLipEnabled()).willReturn(true); + given(caseData.isApplicantLiP()).willReturn(true); + //When + MediationCSVService mediationCSVService = mediationCsvServiceFactory.getMediationCSVService(caseData); + //Then + assertThat(mediationCSVService).isInstanceOf(MediationCSVLipVLipService.class); + } } +