Skip to content

Commit

Permalink
CIV-12112 do not allow event when claim amout is greater than 1000 (#…
Browse files Browse the repository at this point in the history
…3950)

* CIV-12112 donotallow event when claimamout is greater than 1000

* CIV-12112 update error message

---------

Co-authored-by: Azam <[email protected]>
  • Loading branch information
bhagyashreesharma90 and Azam-Hmcts authored Jan 31, 2024
1 parent 3010bc8 commit e812469
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -64,15 +66,21 @@ protected Map<String, Callback> callbacks() {

private CallbackResponse validateRequestEligibilityAndGetPartyDetails(CallbackParams callbackParams) {
List<String> errors = new ArrayList<>();
Optional<Element<CaseDocument>> 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<Element<CaseDocument>> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit e812469

Please sign in to comment.