From 3e37748b652b12f10eb908e2f3a9ef5013b6a1df Mon Sep 17 00:00:00 2001 From: awaneet Date: Wed, 18 Mar 2026 19:25:45 +0530 Subject: [PATCH] FINERACT-2533: Add E2E test scenarios for SavingsAccount isufficient balance withdrawal --- .../stepdef/saving/SavingsAccountStepDef.java | 42 +++++++++++++++++++ .../resources/features/SavingsAccount.feature | 12 ++++++ 2 files changed, 54 insertions(+) diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/saving/SavingsAccountStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/saving/SavingsAccountStepDef.java index c52c96e4850..480f3d3cf1b 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/saving/SavingsAccountStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/saving/SavingsAccountStepDef.java @@ -19,8 +19,10 @@ package org.apache.fineract.test.stepdef.saving; import static org.apache.fineract.client.feign.util.FeignCalls.ok; +import static org.assertj.core.api.Assertions.assertThat; import io.cucumber.java.en.And; +import io.cucumber.java.en.Then; import java.math.BigDecimal; import java.util.Map; import org.apache.fineract.client.feign.FineractFeignClient; @@ -32,8 +34,10 @@ import org.apache.fineract.client.models.PostSavingsAccountsRequest; import org.apache.fineract.client.models.PostSavingsAccountsResponse; import org.apache.fineract.test.factory.SavingsAccountRequestFactory; +import org.apache.fineract.test.helper.ErrorResponse; import org.apache.fineract.test.stepdef.AbstractStepDef; import org.apache.fineract.test.support.TestContextKey; +import org.assertj.core.api.Assertions; import org.springframework.beans.factory.annotation.Autowired; public class SavingsAccountStepDef extends AbstractStepDef { @@ -170,4 +174,42 @@ public void createUsdWithdraw(double withdrawAmount, String transcationDate) { .transaction2(savingsAccountID, withdrawRequest, Map.of("command", "withdrawal"))); testContext().set(TestContextKey.USD_SAVINGS_ACCOUNT_WITHDRAW_RESPONSE, withdrawalResponse); } + + @And("Client tries to withdraw {double} {string} from savings account on {string} date and expects an error") + public void withdrawWithInsufficientBalance(double withdrawAmount, String currency, String transactionDate) { + + String contextKey = currency.equalsIgnoreCase("EUR") ? TestContextKey.EUR_SAVINGS_ACCOUNT_CREATE_RESPONSE + : TestContextKey.USD_SAVINGS_ACCOUNT_CREATE_RESPONSE; + + PostSavingsAccountsResponse savingsAccountResponse = testContext().get(contextKey); + long savingsAccountID = savingsAccountResponse.getSavingsId(); + + PostSavingsAccountTransactionsRequest withdrawRequest = SavingsAccountRequestFactory.defaultWithdrawRequest() + .transactionDate(transactionDate).transactionAmount(BigDecimal.valueOf(withdrawAmount)); + + try { + fineractClient.savingsAccountTransactions().transaction2(savingsAccountID, withdrawRequest, Map.of("command", "withdrawal")); + + Assertions.fail("Expected withdrawal to fail due to insufficient funds, but it succeeded."); + + } catch (org.apache.fineract.client.feign.FeignException e) { + ErrorResponse errorResponse = ErrorResponse.fromFeignException(e); + testContext().set(TestContextKey.ERROR_RESPONSE, errorResponse); + } + } + + @Then("The savings account withdrawal error response has an HTTP status of {int}") + public void verifySavingsWithdrawalHttpStatus(int expectedStatus) { + ErrorResponse errorResponse = testContext().get(TestContextKey.ERROR_RESPONSE); + assertThat(errorResponse).isNotNull(); + assertThat(errorResponse.getHttpStatusCode()).isEqualTo(expectedStatus); + } + + @And("The savings account withdrawal developer message contains {string}") + public void verifySavingsWithdrawalErrorMessage(String expectedMessage) { + ErrorResponse errorResponse = testContext().get(TestContextKey.ERROR_RESPONSE); + assertThat(errorResponse).isNotNull(); + String developerMessage = errorResponse.getErrors().get(0).getDeveloperMessage(); + assertThat(developerMessage).contains(expectedMessage); + } } diff --git a/fineract-e2e-tests-runner/src/test/resources/features/SavingsAccount.feature b/fineract-e2e-tests-runner/src/test/resources/features/SavingsAccount.feature index b4f9b18c941..07163f0f4fc 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/SavingsAccount.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/SavingsAccount.feature @@ -34,3 +34,15 @@ And Client successfully deposits 1000 EUR to the savings account on "1 June 2022" date And Client successfully withdraw 1000 EUR from the savings account on "1 June 2022" date And Client successfully deposits 1000 USD to the savings account on "1 June 2022" date + + @Skip @TestRailId:C2441 + Scenario: As a user I would like to verify that withdrawal fails when balance is insufficient + When Admin sets the business date to "1 June 2022" + And Admin creates a client with random data + And Client creates a new EUR savings account with "1 June 2022" submitted on date + And Approve EUR savings account on "1 June 2022" date + And Activate EUR savings account on "1 June 2022" date + And Client successfully deposits 500 EUR to the savings account on "1 June 2022" date + And Client tries to withdraw 1000 "EUR" from savings account on "1 June 2022" date and expects an error + Then The savings account withdrawal error response has an HTTP status of 403 + And The savings account withdrawal developer message contains "insufficient.account.balance"