Error with withdraw/deposit transactions after initiating hold transaction (#2540)

Co-authored-by: Dhaval Maniyar <dhavalmaniyar@Dhavals-MacBook-Pro.local>
This commit is contained in:
logoutdhaval
2022-08-25 18:04:22 +05:30
committed by GitHub
co-authored by Dhaval Maniyar
parent 5dd199f34d
commit 2479dd1289
2 changed files with 46 additions and 1 deletions
@@ -1015,7 +1015,7 @@ public class SavingsAccount extends AbstractPersistableCustom {
if (!transaction.getRunningBalance(transactionAmount.getCurrency()).isEqualTo(transactionAmount)) {
transaction.updateRunningBalance(runningBalance);
}
if (overdraftAmount.isZero() && runningBalance.isLessThanZero()) {
if (overdraftAmount.isZero() && runningBalance.isLessThanZero() && !transaction.isAmountOnHold()) {
overdraftAmount = overdraftAmount.plus(runningBalance.getAmount().negate());
}
if (transaction.getId() == null && overdraftAmount.isGreaterThanZero()) {
@@ -3114,6 +3114,51 @@ public class ClientSavingsIntegrationTest {
Assertions.assertFalse(reversalFlag);
}
@Test
public void testSavingsAccountDepositAfterHoldAmount() {
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse);
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
final String minBalanceForInterestCalculation = null;
final boolean enforceMinRequiredBalance = false;
final boolean allowOverdraft = true;
final boolean lienAllowed = false;
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, "0", minBalanceForInterestCalculation,
enforceMinRequiredBalance, allowOverdraft, lienAllowed);
Assertions.assertNotNull(savingsProductID);
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
Assertions.assertNotNull(savingsProductID);
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
this.savingsAccountHelper.holdAmountInSavingsAccount(savingsId, "100", lienAllowed, SavingsAccountHelper.TRANSACTION_DATE,
CommonConstants.RESPONSE_RESOURCE_ID);
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "200",
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
Assertions.assertNotNull(depositTransactionId);
List<HashMap> error = (List) validationErrorHelper.withdrawalFromSavingsAccount(savingsId, "200",
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
}
private Integer createSavingsAccountDailyPostingOverdraft(final Integer clientID, final String startDate) {
final Integer savingsProductID = createSavingsProductDailyPostingOverdraft();
Assertions.assertNotNull(savingsProductID);