Skip to content

Commit

Permalink
FINERACT-2060: Progressive loan - final accrual calculation on closed…
Browse files Browse the repository at this point in the history
… loan
  • Loading branch information
Marta Jankovics committed Dec 12, 2024
1 parent bb8480a commit 3bdda96
Show file tree
Hide file tree
Showing 35 changed files with 674 additions and 753 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,18 @@ public static String wrongDataInDelinquentLastRepaymentDate(String actual, Strin
}

public static String wrongLoanStatus(Integer actual, Integer expected) {
return wrongLoanStatus(null, actual, expected);
}

public static String wrongLoanStatus(String resourceId, Integer actual, Integer expected) {
String actualToStr = actual.toString();
String expectedToStr = expected.toString();
return String.format("Wrong Loan status ID. Actual ID is: %s - But expected ID is: %s", actualToStr, expectedToStr);
String prefx = "Wrong Loan status ID";
String postfx = ". Actual ID is: %s - But expected ID is: %s";
if (resourceId != null) {
return String.format(prefx + " of resource %s" + postfx, resourceId, actualToStr, expectedToStr);
}
return String.format(prefx + postfx, actualToStr, expectedToStr);
}

public static String wrongFraudFlag(Boolean actualFraudStatus, Boolean expectedFraudStatus) {
Expand Down Expand Up @@ -519,6 +528,10 @@ public static String nrOfLinesWrongInTransactionsTab(String resourceId, int actu
}

public static String wrongValueInLineInChargesTab(int line, List<List<String>> actual, List<String> expected) {
return wrongValueInLineInChargesTab(null, line, actual, expected);
}

public static String wrongValueInLineInChargesTab(String resourceId, int line, List<List<String>> actual, List<String> expected) {
String lineStr = String.valueOf(line);
String expectedStr = expected.toString();
StringBuilder sb = new StringBuilder();
Expand All @@ -527,12 +540,20 @@ public static String wrongValueInLineInChargesTab(int line, List<List<String>> a
sb.append(System.lineSeparator());
}

return String.format(
"%nWrong value in Charges tab line %s. %nActual values in line (with the same date) are: %n%s %nExpected values in line: %n%s",
lineStr, sb.toString(), expectedStr);
String prefx = "%nWrong value in Charges tab";
String postfx = " line %s. %nActual values in line (with the same date) are: %n%s %nExpected values in line: %n%s";
if (resourceId != null) {
return String.format(prefx + " of resource %s" + postfx, resourceId, lineStr, sb, expectedStr);
}
return String.format(prefx + postfx, lineStr, sb.toString(), expectedStr);
}

public static String wrongValueInLineInJournalEntries(int line, List<List<List<String>>> actual, List<String> expected) {
return wrongValueInLineInJournalEntries(null, line, actual, expected);
}

public static String wrongValueInLineInJournalEntries(String resourceId, int line, List<List<List<String>>> actual,
List<String> expected) {
String lineStr = String.valueOf(line);
String expectedStr = expected.toString();
StringBuilder sb = new StringBuilder();
Expand All @@ -541,9 +562,12 @@ public static String wrongValueInLineInJournalEntries(int line, List<List<List<S
sb.append(System.lineSeparator());
}

return String.format(
"%nWrong value in Journal entries line %s. %nActual values for the possible transactions in line (with the same date) are: %n%s %nExpected values in line: %n%s",
lineStr, sb.toString(), expectedStr);
String prefx = "%nWrong value in Journal entries";
String postfx = " line %s. %nActual values for the possible transactions in line (with the same date) are: %n%s %nExpected values in line: %n%s";
if (resourceId != null) {
return String.format(prefx + " of resource %s" + postfx, resourceId, lineStr, sb, expectedStr);
}
return String.format(prefx + postfx, lineStr, sb.toString(), expectedStr);
}

public static String wrongDataInJournalEntriesGlAccountType(int line, String actual, String expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ public void givenLoanApproved(int nr) throws IOException {
Integer statusIdActual = status.getId();
Integer statusIdExpected = LoanStatus.APPROVED.value;

assertThat(statusIdActual).as(ErrorMessageHelper.wrongLoanStatus(statusIdActual, statusIdExpected)).isEqualTo(statusIdExpected);
String resourceId = String.valueOf(response.body().getId());
assertThat(statusIdActual).as(ErrorMessageHelper.wrongLoanStatus(resourceId, statusIdActual, statusIdExpected))
.isEqualTo(statusIdExpected);
}

@Then("Nr. {int} Client creation was rolled back")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void journalEntryDataCheck(String transactionType, String transactionDate
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

Response<GetLoansLoanIdResponse> loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "transactions", "", "").execute();
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
Expand Down Expand Up @@ -132,7 +133,8 @@ public void journalEntryDataCheck(String transactionType, String transactionDate
}
}
assertThat(containsAnyExpected)
.as(ErrorMessageHelper.wrongValueInLineInJournalEntries(i, possibleActualValuesList, expectedValues)).isTrue();
.as(ErrorMessageHelper.wrongValueInLineInJournalEntries(resourceId, i, possibleActualValuesList, expectedValues))
.isTrue();
}
}

Expand All @@ -141,6 +143,7 @@ public void revertedJournalEntryDataCheck(String transactionType, String transac
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

Response<GetLoansLoanIdResponse> loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "transactions", "", "").execute();
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
Expand Down Expand Up @@ -218,7 +221,8 @@ public void revertedJournalEntryDataCheck(String transactionType, String transac
}
}
assertThat(containsAnyExpected)
.as(ErrorMessageHelper.wrongValueInLineInJournalEntries(i, possibleActualValuesList, expectedValues)).isTrue();
.as(ErrorMessageHelper.wrongValueInLineInJournalEntries(resourceId, i, possibleActualValuesList, expectedValues))
.isTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,8 @@ public void failedLoanApproveWithAmount(String approveDate, String approvedAmoun
public void disburseLoan(String actualDisbursementDate, String transactionAmount) throws IOException {
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

PostLoansLoanIdRequest disburseRequest = LoanRequestFactory.defaultLoanDisburseRequest()
.actualDisbursementDate(actualDisbursementDate).transactionAmount(new BigDecimal(transactionAmount));

Expand All @@ -1310,7 +1312,7 @@ public void disburseLoan(String actualDisbursementDate, String transactionAmount
Long statusExpected = Long.valueOf(loanDetails.body().getStatus().getId());

assertThat(statusActual)//
.as(ErrorMessageHelper.wrongLoanStatus(Math.toIntExact(statusActual), Math.toIntExact(statusExpected)))//
.as(ErrorMessageHelper.wrongLoanStatus(resourceId, Math.toIntExact(statusActual), Math.toIntExact(statusExpected)))//
.isEqualTo(statusExpected);//
eventCheckHelper.disburseLoanEventCheck(loanId);
eventCheckHelper.loanDisbursalTransactionEventCheck(loanDisburseResponse);
Expand All @@ -1320,6 +1322,8 @@ public void disburseLoan(String actualDisbursementDate, String transactionAmount
public void disburseLoanWithoutAutoDownpayment(String actualDisbursementDate, String transactionAmount) throws IOException {
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

PostLoansLoanIdRequest disburseRequest = LoanRequestFactory.defaultLoanDisburseRequest()
.actualDisbursementDate(actualDisbursementDate).transactionAmount(new BigDecimal(transactionAmount));

Expand All @@ -1333,7 +1337,7 @@ public void disburseLoanWithoutAutoDownpayment(String actualDisbursementDate, St
Long statusExpected = Long.valueOf(loanDetails.body().getStatus().getId());

assertThat(statusActual)//
.as(ErrorMessageHelper.wrongLoanStatus(Math.toIntExact(statusActual), Math.toIntExact(statusExpected)))//
.as(ErrorMessageHelper.wrongLoanStatus(resourceId, Math.toIntExact(statusActual), Math.toIntExact(statusExpected)))//
.isEqualTo(statusExpected);//
eventCheckHelper.disburseLoanEventCheck(loanId);
eventCheckHelper.loanDisbursalTransactionEventCheck(loanDisburseResponse);
Expand Down Expand Up @@ -1773,6 +1777,7 @@ public void loanTransactionsGivenTransactionNotReverted(String transactionType,
public void loanChargesGivenChargeDataCheck(DataTable table) throws IOException {
Response<PostLoansResponse> loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanCreateResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

Response<GetLoansLoanIdResponse> loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "charges", "", "").execute();
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
Expand All @@ -1786,14 +1791,15 @@ public void loanChargesGivenChargeDataCheck(DataTable table) throws IOException

boolean containsExpectedValues = actualValuesList.stream().anyMatch(actualValues -> actualValues.equals(expectedValues));

assertThat(containsExpectedValues).as(ErrorMessageHelper.wrongValueInLineInChargesTab(1, actualValuesList, expectedValues))
.isTrue();
assertThat(containsExpectedValues)
.as(ErrorMessageHelper.wrongValueInLineInChargesTab(resourceId, 1, actualValuesList, expectedValues)).isTrue();
}

@Then("Loan Charges tab has the following data:")
public void loanChargesTabCheck(DataTable table) throws IOException {
Response<PostLoansResponse> loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanCreateResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

Response<GetLoansLoanIdResponse> loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "charges", "", "").execute();
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
Expand All @@ -1808,8 +1814,8 @@ public void loanChargesTabCheck(DataTable table) throws IOException {

boolean containsExpectedValues = actualValuesList.stream().anyMatch(actualValues -> actualValues.equals(expectedValues));

assertThat(containsExpectedValues).as(ErrorMessageHelper.wrongValueInLineInChargesTab(i, actualValuesList, expectedValues))
.isTrue();
assertThat(containsExpectedValues)
.as(ErrorMessageHelper.wrongValueInLineInChargesTab(resourceId, i, actualValuesList, expectedValues)).isTrue();
}
}

Expand Down Expand Up @@ -1846,6 +1852,7 @@ private List<List<String>> getActualValuesList(List<GetLoansLoanIdLoanChargeData
public void loanStatus(String statusExpected) throws IOException {
Response<PostLoansResponse> loanCreateResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
long loanId = loanCreateResponse.body().getLoanId();
String resourceId = String.valueOf(loanId);

Response<GetLoansLoanIdResponse> loanDetailsResponse = loansApi.retrieveLoan(loanId, false, "", "", "").execute();
ErrorHelper.checkSuccessfulApiCall(loanDetailsResponse);
Expand All @@ -1855,7 +1862,7 @@ public void loanStatus(String statusExpected) throws IOException {
LoanStatus loanStatusExpected = LoanStatus.valueOf(statusExpected);
Integer loanStatusExpectedValue = loanStatusExpected.getValue();

assertThat(loanStatusActualValue).as(ErrorMessageHelper.wrongLoanStatus(loanStatusActualValue, loanStatusExpectedValue))
assertThat(loanStatusActualValue).as(ErrorMessageHelper.wrongLoanStatus(resourceId, loanStatusActualValue, loanStatusExpectedValue))
.isEqualTo(loanStatusExpectedValue);
}

Expand Down Expand Up @@ -2776,7 +2783,9 @@ private void performLoanDisbursementAndVerifyStatus(final long loanId, final Pos
assertNotNull(loanDetails.body().getStatus());
final Long statusExpected = Long.valueOf(loanDetails.body().getStatus().getId());

assertThat(statusActual).as(ErrorMessageHelper.wrongLoanStatus(Math.toIntExact(statusActual), Math.toIntExact(statusExpected)))
String resourceId = String.valueOf(loanId);
assertThat(statusActual)
.as(ErrorMessageHelper.wrongLoanStatus(resourceId, Math.toIntExact(statusActual), Math.toIntExact(statusExpected)))
.isEqualTo(statusExpected);
eventCheckHelper.disburseLoanEventCheck(loanId);
eventCheckHelper.loanDisbursalTransactionEventCheck(loanDisburseResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fineract-test.api.password=${TEST_PASSWORD:password}
fineract-test.api.strong-password=${TEST_STRONG_PASSWORD:A1b2c3d4e5f$}
fineract-test.api.tenant-id=${TEST_TENANT_ID:default}

fineract-test.initialization.enabled=${INITIALIZATION_ENABLED:false}
fineract-test.initialization.enabled=${INITIALIZATION_ENABLED:true}

fineract-test.testrail.enabled=${TESTRAIL_ENABLED:false}
fineract-test.testrail.base-url=${TESTRAIL_BASEURL:}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5231,6 +5231,7 @@ Feature: EMI calculation and repayment schedule checks for interest bearing loan
| 22 January 2021 | Accrual | 5.7 | 0.0 | 5.7 | 0.0 | 0.0 | 0.0 | false | false |
| 22 January 2021 | Merchant Issued Refund | 1000.0 | 914.37 | 5.42 | 0.0 | 0.0 | 0.0 | false | true |
| 22 January 2021 | Interest Refund | 5.42 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | false | true |
| 22 January 2021 | Accrual Adjustment | 0.28 | 0.0 | 0.28 | 0.0 | 0.0 | 0.0 | false | false |

@TestRailId:C3302
Scenario: UC18-2 - In case of repayment reversal the Interest Refund transaction needs to be recalculated
Expand Down Expand Up @@ -5288,6 +5289,7 @@ Feature: EMI calculation and repayment schedule checks for interest bearing loan
| 22 January 2021 | Merchant Issued Refund | 1000.0 | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | false | true |
| 22 January 2021 | Interest Refund | 5.7 | 0.0 | 5.7 | 0.0 | 0.0 | 0.0 | false | true |
| 23 January 2021 | Credit Balance Refund | 85.63 | 85.63 | 0.0 | 0.0 | 0.0 | 85.63 | false | true |
| 22 January 2021 | Accrual | 5.42 | 0.0 | 5.42 | 0.0 | 0.0 | 0.0 | false | false |
And In Loan Transactions the "2"th Transaction has Transaction type="Repayment" and is reverted

@TestRailId:C3303
Expand Down
Loading

0 comments on commit 3bdda96

Please sign in to comment.