Skip to content

Commit

Permalink
FINERACT-1971: Delinquency evaluation should be happen only for Activ…
Browse files Browse the repository at this point in the history
…e Loans
  • Loading branch information
Jose Alberto Hernandez authored and adamsaghy committed Jan 18, 2024
1 parent 189b94b commit e169b5c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public CollectionData calculateLoanCollectionData(final Long loanId) {
if (optLoan.isPresent()) {
final Loan loan = optLoan.get();

// If the Loan is not Active yet, return template data
if (loan.isSubmittedAndPendingApproval() || loan.isApproved()) {
return CollectionData.template();
}

final List<LoanDelinquencyAction> savedDelinquencyList = retrieveLoanDelinquencyActions(loanId);
List<LoanDelinquencyActionData> effectiveDelinquencyList = delinquencyEffectivePauseHelper
.calculateEffectiveDelinquencyList(savedDelinquencyList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,58 @@ public void testDelinquencyWithMultiplePausePeriodsWithInstallmentLevelDelinquen
}
}

@Test
public void testLoanClassificationOnyForActiveLoan() {

// Given
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);

ArrayList<Integer> rangeIds = new ArrayList<>();
// First Range
String jsonRange = DelinquencyRangesHelper.getAsJSON(4, 30);
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
jsonRange);
rangeIds.add(delinquencyRangeResponse.getResourceId());

String jsonBucket = DelinquencyBucketsHelper.getAsJSON(rangeIds);
PostDelinquencyBucketResponse delinquencyBucketResponse = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec,
responseSpec, jsonBucket);
assertNotNull(delinquencyBucketResponse);
final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
delinquencyBucketResponse.getResourceId());

// Client and Loan account creation
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
Math.toIntExact(delinquencyBucket.getId()), null);
assertNotNull(getLoanProductsProductResponse);

final LocalDate todaysDate = Utils.getLocalDateOfTenant();
// Older date to have more than one overdue installment
LocalDate transactionDate = todaysDate.minusDays(37);
String operationDate = Utils.dateFormatter.format(transactionDate);

// Create Loan Application
final Integer loanId = createLoanApplication(loanTransactionHelper, clientId.toString(),
getLoanProductsProductResponse.getId().toString(), operationDate, null);

// Evaluate default delinquent values in No Active Loan
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getDelinquent());
assertEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentDays());
assertEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentAmount());

// Loan Disbursement
disburseLoanAccount(loanTransactionHelper, loanId, operationDate);
// Evaluate default delinquent values in No Active Loan
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getDelinquent());
assertNotEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentDays());
assertNotEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentAmount());
}

private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
final Integer delinquencyBucketId, final String inArrearsTolerance) {
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().withInArrearsTolerance(inArrearsTolerance).build(null,
Expand All @@ -1595,8 +1647,8 @@ private PutLoanProductsProductIdResponse updateLoanProduct(LoanTransactionHelper
return loanTransactionHelper.updateLoanProduct(id, requestModifyLoan);
}

private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
final String operationDate, final String inArrearsTolerance) {
private Integer createLoanApplication(final LoanTransactionHelper loanTransactionHelper, final String clientId,
final String loanProductId, final String operationDate, final String inArrearsTolerance) {
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount).withLoanTermFrequency("12")
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("12").withRepaymentEveryAfter("1")
.withRepaymentFrequencyTypeAsMonths() //
Expand All @@ -1608,7 +1660,17 @@ private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHel
.build(clientId, loanProductId, null);
final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON);
loanTransactionHelper.approveLoan(operationDate, principalAmount, loanId, null);
return loanId;
}

private void disburseLoanAccount(final LoanTransactionHelper loanTransactionHelper, final Integer loanId, final String operationDate) {
loanTransactionHelper.disburseLoanWithNetDisbursalAmount(operationDate, loanId, principalAmount);
}

private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
final String operationDate, final String inArrearsTolerance) {
final Integer loanId = createLoanApplication(loanTransactionHelper, clientId, loanProductId, operationDate, inArrearsTolerance);
disburseLoanAccount(loanTransactionHelper, loanId, operationDate);
return loanId;
}

Expand Down

0 comments on commit e169b5c

Please sign in to comment.