Skip to content

Commit

Permalink
FINERACT-1971 Credit balance refund for future date shall be rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
reluxa authored and adamsaghy committed Nov 30, 2023
1 parent 5e5511f commit 8505145
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ private void updateLoanTransaction(final Long loanTransactionId, final LoanTrans
@Override
public LoanTransaction creditBalanceRefund(final Loan loan, final LocalDate transactionDate, final BigDecimal transactionAmount,
final String noteText, final ExternalId externalId, PaymentDetail paymentDetail) {
if (transactionDate.isAfter(DateUtils.getBusinessLocalDate())) {
throw new GeneralPlatformDomainRuleException("error.msg.transaction.date.cannot.be.in.the.future",
"Loan: " + loan.getId() + ", Credit Balance Refund transaction cannot be created for the future.", loan.getId());
}
if (loan.isChargedOff() && DateUtils.isBefore(transactionDate, loan.getChargedOffOnDate())) {
throw new GeneralPlatformDomainRuleException("error.msg.transaction.date.cannot.be.earlier.than.charge.off.date", "Loan: "
+ loan.getId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ protected void disburseLoan(Long loanId, BigDecimal amount, String date) {
.transactionAmount(amount).locale("en"));
}

protected void verifyJournalEntries(Long loanId, JournalEntry... entries) {
protected void verifyJournalEntries(Long loanId, Journal... entries) {
GetJournalEntriesTransactionIdResponse journalEntriesForLoan = journalEntryHelper.getJournalEntriesForLoan(loanId);
Assertions.assertEquals(entries.length, journalEntriesForLoan.getPageItems().size());
Arrays.stream(entries).forEach(journalEntry -> {
Expand Down Expand Up @@ -405,8 +405,8 @@ protected void updateBusinessDate(String date) {
new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en"));
}

protected JournalEntry journalEntry(double principalAmount, Account account, String type) {
return new JournalEntry(principalAmount, account, type);
protected Journal journalEntry(double principalAmount, Account account, String type) {
return new Journal(principalAmount, account, type);
}

protected Transaction transaction(double principalAmount, String type, String date) {
Expand Down Expand Up @@ -454,7 +454,7 @@ public static class TransactionExt {

@ToString
@AllArgsConstructor
public static class JournalEntry {
public static class Journal {

Double amount;
Account account;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
@SuppressWarnings({ "rawtypes", "unchecked" })
@ExtendWith(LoanTestLifecycleExtension.class)
@Slf4j
public class ClientLoanCreditBalanceRefundandRepaymentTypeIntegrationTest {
public class ClientLoanCreditBalanceRefundandRepaymentTypeIntegrationTest extends BaseLoanIntegrationTest {

private ResponseSpecification responseSpec;
private ResponseSpecification responseSpec403;
Expand Down Expand Up @@ -251,7 +251,56 @@ public void fullRefundChangesStatusToClosedObligationMetTest(LoanProductTestBuil
totalOverpaidAtEnd = floatZero;
}
assertEquals(totalOverpaidAtEnd, floatZero);
}

@ParameterizedTest
@MethodSource("loanProductFactory")
public void refundAcceptedOnTheCurrentBusinessDate(LoanProductTestBuilder loanProductTestBuilder) {
runAt("09 January 2022", () -> {
disburseLoanOfAccountingRule(ACCRUAL_PERIODIC, loanProductTestBuilder);
HashMap loanStatusHashMap = makeRepayment("06 January 2022", 20000.00f); // overpayment
LoanStatusChecker.verifyLoanAccountIsOverPaid(loanStatusHashMap);

final Float totalOverpaid = (Float) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec,
disbursedLoanID, "totalOverpaid");

final String creditBalanceRefundDate = "09 January 2022";
final String externalId = null;
loanTransactionHelper.creditBalanceRefund(creditBalanceRefundDate, totalOverpaid, externalId, disbursedLoanID, null);
loanStatusHashMap = (HashMap) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, disbursedLoanID,
"status");
LoanStatusChecker.verifyLoanAccountIsClosed(loanStatusHashMap);

final Float floatZero = 0.0f;
Float totalOverpaidAtEnd = (Float) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec,
disbursedLoanID, "totalOverpaid");
if (totalOverpaidAtEnd == null) {
totalOverpaidAtEnd = floatZero;
}
assertEquals(totalOverpaidAtEnd, floatZero);
});
}

@ParameterizedTest
@MethodSource("loanProductFactory")
public void refundCannotBeDuneForFutureDate(LoanProductTestBuilder loanProductTestBuilder) {
runAt("06 January 2022", () -> {
disburseLoanOfAccountingRule(ACCRUAL_PERIODIC, loanProductTestBuilder);
HashMap loanStatusHashMap = makeRepayment("06 January 2022", 20000.00f); // overpayment
LoanStatusChecker.verifyLoanAccountIsOverPaid(loanStatusHashMap);

final Float totalOverpaid = (Float) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec,
disbursedLoanID, "totalOverpaid");

final String creditBalanceRefundDate = "09 January 2022";
final String externalId = null;

ArrayList<HashMap> cbrErrors = (ArrayList<HashMap>) loanTransactionHelperValidationError.creditBalanceRefund(
creditBalanceRefundDate, totalOverpaid, externalId, disbursedLoanID, CommonConstants.RESPONSE_ERROR);

assertEquals("error.msg.transaction.date.cannot.be.in.the.future",
cbrErrors.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
});
}

@ParameterizedTest
Expand Down

0 comments on commit 8505145

Please sign in to comment.