Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading