diff --git a/crime-evidence/src/test/java/uk/gov/justice/laa/crime/evidence/service/EvidenceServiceTest.java b/crime-evidence/src/test/java/uk/gov/justice/laa/crime/evidence/service/EvidenceServiceTest.java index 8ec2c2a..dcaa543 100644 --- a/crime-evidence/src/test/java/uk/gov/justice/laa/crime/evidence/service/EvidenceServiceTest.java +++ b/crime-evidence/src/test/java/uk/gov/justice/laa/crime/evidence/service/EvidenceServiceTest.java @@ -147,7 +147,7 @@ void givenCommittedForTrialAndEvidenceFeeLevelIsNotNull_WhenIsCalcRequired_False } @Test - void givenNoEvidenceItems_whenUpdateEvidenceIsInvoked_thenEvidenceIsNotUpdated() { + void givenNoEvidenceItems_whenUpdateEvidenceIsInvoked_thenExceptionIsThrown() { UpdateEvidenceDTO updateEvidenceDTO = TestModelDataBuilder.getUpdateEvidenceRequest(); assertThatThrownBy(() -> evidenceService.updateEvidence(updateEvidenceDTO)) @@ -156,7 +156,7 @@ void givenNoEvidenceItems_whenUpdateEvidenceIsInvoked_thenEvidenceIsNotUpdated() } @Test - void givenValidationErrorOnEvidenceReceivedDate_whenUpdateEvidenceIsInvoked_thenEvidenceIsNotUpdated() { + void givenValidationErrorOnEvidenceReceivedDate_whenUpdateEvidenceIsInvoked_thenExceptionIsThrown() { LocalDate applicationReceivedDate = LocalDate.of(2024, 8, 30); LocalDate evidenceItemReceivedDate = LocalDate.of(2024, 8, 29); @@ -179,7 +179,7 @@ void givenValidationErrorOnEvidenceReceivedDate_whenUpdateEvidenceIsInvoked_then } @Test - void givenValidationErrorOnEvidenceDueDate_whenUpdateEvidenceIsInvoked_thenEvidenceIsNotUpdated() { + void givenValidationErrorOnEvidenceDueDate_whenUpdateEvidenceIsInvoked_thenExceptionIsThrown() { LocalDate applicationReceivedDate = LocalDate.of(2024, 8, 30); LocalDate evidenceItemReceivedDate = LocalDate.of(2024, 8, 31); LocalDate evidenceDueDate = LocalDate.of(2024, 9, 30); @@ -270,6 +270,59 @@ void givenEvidenceHasNotBeenReceivedAndIncomeEvidenceHasReceivedDate_whenUpdateE verify(meansAssessmentApiService, atLeastOnce()).update(expectedRequest); } + @Test + void givenOnlyPartnerEvidenceIsProvided_whenUpdateEvidenceIsInvoked_thenIncomeEvidenceIsUpdated() { + LocalDate applicationReceivedDate = LocalDate.of(2024, 8, 30); + LocalDate evidenceItemReceivedDate = LocalDate.of(2024, 9, 1); + LocalDate evidenceDueDate = LocalDate.of(2024, 9, 30); + LocalDate evidenceReceivedDate = LocalDate.of(2024, 9, 1); + + List partnerEvidenceItems = List.of( + new ApiIncomeEvidence(1, evidenceItemReceivedDate, IncomeEvidenceType.ACCOUNTS, false, "Company accounts") + ); + + UpdateEvidenceDTO updateEvidenceDTO = TestModelDataBuilder.getUpdateEvidenceRequest( + applicationReceivedDate, + buildApplicantDetails(1, EmploymentStatus.EMPLOY), + null, + evidenceDueDate, + evidenceReceivedDate); + updateEvidenceDTO.setPartnerDetails(buildApplicantDetails(2, EmploymentStatus.EMPLOYED_CASH)); + updateEvidenceDTO.setPartnerIncomeEvidenceItems(partnerEvidenceItems); + + ApiIncomeEvidenceSummary incomeEvidenceSummary = buildIncomeEvidenceSummary(evidenceDueDate, evidenceReceivedDate); + ApiGetMeansAssessmentResponse getMeansAssessmentResponse = buildGetMeansAssessmentResponse(incomeEvidenceSummary); + + when(meansAssessmentApiService.find(TestModelDataBuilder.FINANCIAL_ASSESSMENT_ID)).thenReturn(getMeansAssessmentResponse); + + List incomeEvidenceItems = List.of( + new uk.gov.justice.laa.crime.common.model.meansassessment.ApiIncomeEvidence(1, DateUtil.convertDateToDateTime(evidenceItemReceivedDate), null, null, new ApiEvidenceType(IncomeEvidenceType.ACCOUNTS.getName(), IncomeEvidenceType.ACCOUNTS.getDescription()), null, 2, null, null) + ); + + when(incomeEvidenceService.checkEvidenceReceived( + eq(updateEvidenceDTO.getPartnerIncomeEvidenceItems()), + any(), + any(), + any(), + any(), + eq(ApplicantType.PARTNER))) + .thenReturn(false); + + ApiMeansAssessmentResponse updateAssessmentResponse = new ApiMeansAssessmentResponse(); + updateAssessmentResponse.setIncomeEvidence(incomeEvidenceItems); + + when(meansAssessmentApiService.update(any())).thenReturn(updateAssessmentResponse); + + evidenceService.updateEvidence(updateEvidenceDTO); + + ApiUpdateMeansAssessmentRequest expectedRequest = new ApiUpdateMeansAssessmentRequest() + .withFinancialAssessmentId(TestModelDataBuilder.FINANCIAL_ASSESSMENT_ID) + .withIncomeEvidence(incomeEvidenceItems) + .withIncomeEvidenceSummary(incomeEvidenceSummary); + + verify(meansAssessmentApiService, atLeastOnce()).update(expectedRequest); + } + private ApiApplicantDetails buildApplicantDetails(int applicantId, EmploymentStatus employmentStatus) { ApiApplicantDetails applicantDetails = new ApiApplicantDetails(); applicantDetails.setId(applicantId);