From e8124698ff62cf797538964c5cc3a17ff90a7a01 Mon Sep 17 00:00:00 2001 From: bhagyashreesharma90 <114094319+bhagyashreesharma90@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:50:53 +0000 Subject: [PATCH] CIV-12112 do not allow event when claim amout is greater than 1000 (#3950) * CIV-12112 donotallow event when claimamout is greater than 1000 * CIV-12112 update error message --------- Co-authored-by: Azam <106387766+Azam-Hmcts@users.noreply.github.com> --- ...uestForReconsiderationCallbackHandler.java | 26 +++++++---- ...ForReconsiderationCallbackHandlerTest.java | 45 +++++++++++++++++++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandler.java index d3b14f14218..3e2eb9b9266 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandler.java @@ -20,6 +20,7 @@ import uk.gov.hmcts.reform.idam.client.models.UserInfo; import uk.gov.hmcts.reform.civil.model.common.Element; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; @@ -46,6 +47,7 @@ public class RequestForReconsiderationCallbackHandler extends CallbackHandler { protected final ObjectMapper objectMapper; private static final String ERROR_MESSAGE_DEADLINE_EXPIRED = "You can no longer request a reconsideration because the deadline has expired"; + private static final String ERROR_MESSAGE_SPEC_AMOUNT_GREATER_THAN_THOUSAND = "You can only request a reconsideration for claims of £1,000 or less."; private final UserService userService; private final CoreCaseUserService coreCaseUserService; private static final String CONFIRMATION_HEADER = "# Your request has been submitted"; @@ -64,15 +66,21 @@ protected Map callbacks() { private CallbackResponse validateRequestEligibilityAndGetPartyDetails(CallbackParams callbackParams) { List errors = new ArrayList<>(); - Optional> sdoDocLatest = callbackParams.getCaseData().getSystemGeneratedCaseDocuments() - .stream().filter(caseDocumentElement -> caseDocumentElement.getValue().getDocumentType() - .equals(DocumentType.SDO_ORDER)) - .sorted(Comparator.comparing(caseDocumentElement -> caseDocumentElement.getValue().getCreatedDatetime(), - Comparator.reverseOrder())).findFirst(); - if (sdoDocLatest.isPresent()) { - LocalDateTime sdoDocLatestDate = sdoDocLatest.get().getValue().getCreatedDatetime(); - if (LocalDateTime.now().isAfter(sdoDocLatestDate.plusDays(7))) { - errors.add(ERROR_MESSAGE_DEADLINE_EXPIRED); + if (callbackParams.getCaseData().getTotalClaimAmount().compareTo(BigDecimal.valueOf(1000)) > 0) { + errors.add(ERROR_MESSAGE_SPEC_AMOUNT_GREATER_THAN_THOUSAND); + } else { + Optional> sdoDocLatest = callbackParams.getCaseData().getSystemGeneratedCaseDocuments() + .stream().filter(caseDocumentElement -> caseDocumentElement.getValue().getDocumentType() + .equals(DocumentType.SDO_ORDER)) + .sorted(Comparator.comparing( + caseDocumentElement -> caseDocumentElement.getValue().getCreatedDatetime(), + Comparator.reverseOrder() + )).findFirst(); + if (sdoDocLatest.isPresent()) { + LocalDateTime sdoDocLatestDate = sdoDocLatest.get().getValue().getCreatedDatetime(); + if (LocalDateTime.now().isAfter(sdoDocLatestDate.plusDays(7))) { + errors.add(ERROR_MESSAGE_DEADLINE_EXPIRED); + } } } if (errors.isEmpty()) { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandlerTest.java index 6fef0121efc..856dd7d4f80 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestForReconsiderationCallbackHandlerTest.java @@ -25,6 +25,7 @@ import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.utils.ElementUtils; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; @@ -64,6 +65,8 @@ class RequestForReconsiderationCallbackHandlerTest extends BaseCallbackHandlerTe private static final String ERROR_MESSAGE_DEADLINE_EXPIRED = "You can no longer request a reconsideration because the deadline has expired"; + private static final String ERROR_MESSAGE_SPEC_AMOUNT_GREATER_THAN_THOUSAND = "You can only request a reconsideration for claims of £1,000 or less."; + @Test void handleEventsReturnsTheExpectedCallbackEvents() { assertThat(handler.handledEvents()).containsOnly(REQUEST_FOR_RECONSIDERATION); @@ -75,6 +78,7 @@ class AboutToStartCallback { void shouldAllowRequestIfLessThan7DaysElapsed() { //Given : Casedata containing an SDO order created 6 days ago CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .totalClaimAmount(BigDecimal.valueOf(800)) .systemGeneratedCaseDocuments(List.of(ElementUtils .element(CaseDocument.builder() .documentType(DocumentType.SDO_ORDER) @@ -95,6 +99,7 @@ void shouldAllowRequestIfLessThan7DaysElapsed() { void shouldAllowRequestIfLessThan7DaysElapsedForLatestSDO() { //Given : Casedata containing two SDO order and latest created 6 days ago CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .totalClaimAmount(BigDecimal.valueOf(800)) .systemGeneratedCaseDocuments(Arrays.asList( ElementUtils.element(CaseDocument.builder() .documentType(DocumentType.SDO_ORDER) @@ -119,6 +124,7 @@ void shouldAllowRequestIfLessThan7DaysElapsedForLatestSDO() { void shouldSendErrorMessageIf7DaysElapsedForLatestSDO() { //Given : Casedata containing two SDO order and latest created 7 days ago CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .totalClaimAmount(BigDecimal.valueOf(800)) .systemGeneratedCaseDocuments(Arrays.asList( ElementUtils.element(CaseDocument.builder() .documentType(DocumentType.SDO_ORDER) @@ -144,6 +150,7 @@ void shouldSendErrorMessageIf7DaysElapsedForLatestSDO() { void shouldSendErrorMessageIf7DaysElapsed() { //Given : Casedata containing an SDO order created 7 days ago CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .totalClaimAmount(BigDecimal.valueOf(800)) .systemGeneratedCaseDocuments(List.of(ElementUtils .element(CaseDocument.builder() .documentType(DocumentType.SDO_ORDER) @@ -166,6 +173,7 @@ void shouldSendErrorMessageIf7DaysElapsed() { void shouldGetSelectedUserRole(String userRole) { //Given : Casedata and return applicant solicitor role CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .totalClaimAmount(BigDecimal.valueOf(800)) .systemGeneratedCaseDocuments(List.of(ElementUtils .element(CaseDocument.builder() .documentType(DocumentType.SDO_ORDER) @@ -190,6 +198,43 @@ void shouldGetSelectedUserRole(String userRole) { .isEqualTo("Respondent2"); } } + + @Test + void shouldAllowEventForCaseWithClaimAmountLessThan1000() { + //Given : Casedata with small claim + CaseData caseData = CaseDataBuilder.builder().atStateClaimSubmittedSmallClaim() + .systemGeneratedCaseDocuments(List.of(ElementUtils + .element(CaseDocument.builder() + .documentType(DocumentType.SDO_ORDER) + .createdDatetime(LocalDateTime.now().minusDays(5)) + .build()))).build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_START); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.getUserCaseRoles(any(), any())).thenReturn(List.of("APPLICANTSOLICITORONE")); + + //When: handler is called with ABOUT_TO_START event + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + //Then: No errors should be displayed + assertThat(response.getErrors()).isNull(); + } + + @Test + void shouldNotAllowEventForCaseWithClaimAmountGreaterThan1000() { + //Given : Casedata with claim amount greater than 1000 + CaseData caseData = CaseDataBuilder.builder().atStateClaimSubmitted() + .totalClaimAmount(new BigDecimal(1200)) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_START); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.getUserCaseRoles(any(), any())).thenReturn(List.of("APPLICANTSOLICITORONE")); + + //When: handler is called with ABOUT_TO_START event + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + //Then: No errors should be displayed + assertThat(response.getErrors().contains(ERROR_MESSAGE_SPEC_AMOUNT_GREATER_THAN_THOUSAND)); + } } @Nested