FINERACT-2081: Added tests for validation of batch api call with steps to charge off a loan
This commit is contained in:
committed by
Adam Saghy
parent
8c5606ea8e
commit
786789c446
+65
@@ -931,6 +931,71 @@ public class BatchApiStepDef extends AbstractStepDef {
|
||||
.isEqualTo(errorsDeveloperMessageExpected);
|
||||
}
|
||||
|
||||
@When("Admin runs Batch API call with chargeOff command on {string}")
|
||||
public void runBatchApiCallWithChargeOffCommand(String chargeOffDate) throws IOException {
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.body().getLoanId();
|
||||
String idempotencyKey = UUID.randomUUID().toString();
|
||||
|
||||
List<BatchRequest> requestList = new ArrayList<>();
|
||||
|
||||
requestList.add(createChargeOffRequest(1L, loanId, idempotencyKey, chargeOffDate));
|
||||
|
||||
Response<List<BatchResponse>> batchResponseList = batchApiApi.handleBatchRequests(requestList, false).execute();
|
||||
testContext().set(TestContextKey.BATCH_API_CALL_RESPONSE, batchResponseList);
|
||||
testContext().set(TestContextKey.BATCH_API_CALL_IDEMPOTENCY_KEY, idempotencyKey);
|
||||
|
||||
if (batchResponseList.isSuccessful() && batchResponseList.body() != null && !batchResponseList.body().isEmpty()) {
|
||||
BatchResponse response = batchResponseList.body().get(0);
|
||||
log.info("Batch charge-off API status code: {}", response.getStatusCode());
|
||||
log.info("Batch charge-off API response body: {}", response.getBody());
|
||||
} else {
|
||||
log.info("Batch charge-off API call failed or returned empty response");
|
||||
}
|
||||
}
|
||||
|
||||
private BatchRequest createChargeOffRequest(Long requestId, Long loanId, String idempotencyKey, String chargeOffDate) {
|
||||
// Create a charge-off request with the specified date
|
||||
Map<String, Object> requestMap = new HashMap<>();
|
||||
requestMap.put("transactionDate", chargeOffDate);
|
||||
requestMap.put("dateFormat", DATE_FORMAT);
|
||||
requestMap.put("locale", DEFAULT_LOCALE);
|
||||
requestMap.put("note", "Charge-off due to delinquency");
|
||||
|
||||
String bodyChargeOffRequest = GSON.toJson(requestMap);
|
||||
|
||||
Set<Header> headers = new HashSet<>();
|
||||
headers.add(HEADER);
|
||||
if (idempotencyKey != null) {
|
||||
headers.add(new Header().name("Idempotency-Key").value(idempotencyKey));
|
||||
}
|
||||
|
||||
BatchRequest batchRequest = new BatchRequest();
|
||||
batchRequest.requestId(requestId);
|
||||
batchRequest.relativeUrl("loans/" + loanId + "/transactions?command=charge-off");
|
||||
batchRequest.method(BATCH_API_METHOD_POST);
|
||||
batchRequest.headers(headers);
|
||||
batchRequest.body(bodyChargeOffRequest);
|
||||
|
||||
return batchRequest;
|
||||
}
|
||||
|
||||
@Then("Admin checks the loan has been charged-off on {string}")
|
||||
public void checkLoanChargedOff(String chargeOffDate) throws IOException {
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
long loanId = loanResponse.body().getLoanId();
|
||||
|
||||
Response<GetLoansLoanIdResponse> loanDetails = loansApi.retrieveLoan(loanId, false, "all", "", "").execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(loanDetails);
|
||||
|
||||
// Check loan has a CHARGE_OFF transaction on the specified date
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
|
||||
boolean hasChargeOffTransaction = loanDetails.body().getTransactions().stream().anyMatch(
|
||||
t -> t.getType().getCode().equals("loanTransactionType.chargeOff") && formatter.format(t.getDate()).equals(chargeOffDate));
|
||||
|
||||
assertThat(hasChargeOffTransaction).as("Loan should have a CHARGE_OFF transaction on " + chargeOffDate).isTrue();
|
||||
}
|
||||
|
||||
private String getHeaderValueByHeaderKey(List<Header> headersList, String headerKey) {
|
||||
for (Header header : headersList) {
|
||||
if (Objects.requireNonNull(header.getName()).equals(headerKey)) {
|
||||
|
||||
@@ -78,3 +78,66 @@ Feature: Batch API
|
||||
And Batch API call with steps: queryDatatable, updateDatatable runs, with empty queryDatatable response
|
||||
Then Verify that step Nr. 1 results 200
|
||||
Then Verify that step Nr. 2 results 400
|
||||
|
||||
@TestRailId:C3509 @ChargeOffFeature
|
||||
Scenario: Verify Batch API call with steps to charge-off a loan
|
||||
When Admin sets the business date to "01 January 2024"
|
||||
When Admin creates a client with random data
|
||||
When Admin creates a fully customized loan with the following data:
|
||||
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
|
||||
| LP2_ADV_PYMNT_ZERO_INTEREST_CHARGE_OFF | 01 January 2024 | 100 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
|
||||
And Admin successfully approves the loan on "01 January 2024" with "100" amount and expected disbursement date on "01 January 2024"
|
||||
When Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount
|
||||
Then Loan Repayment schedule has 6 periods, with the following data for periods:
|
||||
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
|
||||
| 1 | 31 | 01 February 2024 | | 83.57 | 16.43 | 0.58 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 2 | 29 | 01 March 2024 | | 67.05 | 16.52 | 0.49 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 3 | 31 | 01 April 2024 | | 50.43 | 16.62 | 0.39 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 4 | 30 | 01 May 2024 | | 33.71 | 16.72 | 0.29 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 5 | 31 | 01 June 2024 | | 16.9 | 16.81 | 0.2 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 16.9 | 0.1 | 0.0 | 0.0 | 17.0 | 0.0 | 0.0 | 0.0 | 17.0 |
|
||||
Then Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100 | 2.05 | 0 | 0 | 102.05 | 0 | 0 | 0 | 102.05 |
|
||||
Then Loan Transactions tab has the following data:
|
||||
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance |
|
||||
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 |
|
||||
When Admin sets the business date to "01 February 2024"
|
||||
And Customer makes "AUTOPAY" repayment on "01 February 2024" with 17.01 EUR transaction amount
|
||||
Then Loan Repayment schedule has 6 periods, with the following data for periods:
|
||||
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
|
||||
| 1 | 31 | 01 February 2024 | 01 February 2024 | 83.57 | 16.43 | 0.58 | 0.0 | 0.0 | 17.01 | 17.01 | 0.0 | 0.0 | 0.0 |
|
||||
| 2 | 29 | 01 March 2024 | | 67.05 | 16.52 | 0.49 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 3 | 31 | 01 April 2024 | | 50.43 | 16.62 | 0.39 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 4 | 30 | 01 May 2024 | | 33.71 | 16.72 | 0.29 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 5 | 31 | 01 June 2024 | | 16.9 | 16.81 | 0.2 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 16.9 | 0.1 | 0.0 | 0.0 | 17.0 | 0.0 | 0.0 | 0.0 | 17.0 |
|
||||
Then Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100 | 2.05 | 0 | 0 | 102.05 | 17.01 | 0 | 0 | 85.04 |
|
||||
Then Loan Transactions tab has the following data:
|
||||
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance |
|
||||
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 |
|
||||
| 01 February 2024 | Repayment | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 |
|
||||
When Admin runs Batch API call with chargeOff command on "01 February 2024"
|
||||
Then Admin checks that all steps result 200OK
|
||||
Then Loan Repayment schedule has 6 periods, with the following data for periods:
|
||||
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| | | 01 January 2024 | | 100.0 | | | 0.0 | | 0.0 | 0.0 | | | |
|
||||
| 1 | 31 | 01 February 2024 | 01 February 2024 | 83.57 | 16.43 | 0.58 | 0.0 | 0.0 | 17.01 | 17.01 | 0.0 | 0.0 | 0.0 |
|
||||
| 2 | 29 | 01 March 2024 | | 66.56 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 3 | 31 | 01 April 2024 | | 49.55 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 4 | 30 | 01 May 2024 | | 32.54 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 5 | 31 | 01 June 2024 | | 15.53 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 | 0.0 | 0.0 | 0.0 | 17.01 |
|
||||
| 6 | 30 | 01 July 2024 | | 0.0 | 15.53 | 0.0 | 0.0 | 0.0 | 15.53 | 0.0 | 0.0 | 0.0 | 15.53 |
|
||||
Then Loan Repayment schedule has the following data in Total row:
|
||||
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
|
||||
| 100 | 0.58 | 0 | 0 | 100.58 | 17.01 | 0 | 0 | 83.57 |
|
||||
Then Loan Transactions tab has the following data:
|
||||
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance |
|
||||
| 01 January 2024 | Disbursement | 100.0 | 0.0 | 0.0 | 0.0 | 0.0 | 100.0 |
|
||||
| 01 February 2024 | Repayment | 17.01 | 16.43 | 0.58 | 0.0 | 0.0 | 83.57 |
|
||||
| 01 February 2024 | Charge-off | 83.57 | 83.57 | 0.0 | 0.0 | 0.0 | 0.0 |
|
||||
And Admin checks the loan has been charged-off on "01 February 2024"
|
||||
Reference in New Issue
Block a user