FINERACT-1724: Batch API support for Loan chargeback and fineract client adjustments
This commit is contained in:
committed by
Arnold Gálovics
parent
729316e4a0
commit
1899b517b4
+1
-1
@@ -94,7 +94,7 @@ public class CommandStrategyProvider {
|
||||
"getChargeByIdCommandStrategy");
|
||||
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/transactions\\?(\\w+(\\=[\\w]+))").method("POST").build(),
|
||||
"createTransactionLoanCommandStrategy");
|
||||
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/transactions\\/\\d+").method("POST").build(),
|
||||
commandStrategies.put(CommandContext.resource("loans\\/\\d+\\/transactions\\/\\d+(\\?command=[\\w]+)?").method("POST").build(),
|
||||
"adjustTransactionCommandStrategy");
|
||||
commandStrategies.put(CommandContext.resource("clients\\/\\d+\\?command=activate").method("POST").build(),
|
||||
"activateClientCommandStrategy");
|
||||
|
||||
+9
-1
@@ -59,7 +59,15 @@ public class AdjustTransactionCommandStrategy implements CommandStrategy {
|
||||
// Get the loan and transaction ids for use in loanTransactionsApiResource
|
||||
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrl);
|
||||
Long loanId = Long.parseLong(pathParameters.get(1));
|
||||
Long transactionId = Long.parseLong(pathParameters.get(3));
|
||||
|
||||
final String transactionIdPathParameter = pathParameters.get(3);
|
||||
Long transactionId;
|
||||
if (transactionIdPathParameter.contains("?")) {
|
||||
transactionId = Long.parseLong(pathParameters.get(3).substring(0, pathParameters.get(3).indexOf("?")));
|
||||
} else {
|
||||
transactionId = Long.parseLong(pathParameters.get(3));
|
||||
}
|
||||
|
||||
Map<String, String> queryParameters = CommandStrategyUtils.getQueryParameters(relativeUrl);
|
||||
String command = queryParameters.get("command");
|
||||
|
||||
|
||||
+4
@@ -976,6 +976,8 @@ final class LoansApiResourceSwagger {
|
||||
public GetDelinquencyRangesResponse delinquencyRange;
|
||||
@Schema(example = "false")
|
||||
public Boolean fraud;
|
||||
@Schema(example = "250.000000")
|
||||
public Double totalOverpaid;
|
||||
}
|
||||
|
||||
@Schema(description = "GetLoansResponse")
|
||||
@@ -1049,6 +1051,8 @@ final class LoansApiResourceSwagger {
|
||||
public List<PostLoansDisbursementData> disbursementData;
|
||||
@Schema(description = "Maximum allowed outstanding balance")
|
||||
public BigDecimal maxOutstandingLoanBalance;
|
||||
@Schema(example = "[2011, 10, 20]")
|
||||
public LocalDate repaymentsStartingFromDate;
|
||||
}
|
||||
|
||||
@Schema(description = "PostLoansResponse")
|
||||
|
||||
+4
@@ -1175,6 +1175,10 @@ final class LoanProductsApiResourceSwagger {
|
||||
|
||||
public GetLoanCharge charge;
|
||||
public GetLoanAccountingMappings.GetLoanIncomeFromFeeAccount incomeAccount;
|
||||
@Schema(example = "10")
|
||||
public Long chargeId;
|
||||
@Schema(example = "39")
|
||||
public Long incomeAccountId;
|
||||
}
|
||||
|
||||
@Schema(example = "11")
|
||||
|
||||
+2
@@ -88,6 +88,8 @@ public class CommandStrategyProviderTest {
|
||||
mock(CreateTransactionLoanCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions/123", HttpMethod.POST, "adjustTransactionCommandStrategy",
|
||||
mock(AdjustTransactionCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions/123?command=chargeback", HttpMethod.POST, "adjustTransactionCommandStrategy",
|
||||
mock(AdjustTransactionCommandStrategy.class)),
|
||||
Arguments.of("clients/456?command=activate", HttpMethod.POST, "activateClientCommandStrategy",
|
||||
mock(ActivateClientCommandStrategy.class)),
|
||||
Arguments.of("loans/123?command=approve", HttpMethod.POST, "approveLoanCommandStrategy",
|
||||
|
||||
+37
-3
@@ -25,6 +25,7 @@ import static org.mockito.BDDMockito.given;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
||||
@@ -39,13 +40,13 @@ public class AdjustTransactionCommandStrategyTest {
|
||||
* Test {@link AdjustTransactionCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccessScenario() {
|
||||
public void testExecuteWithoutCommandSuccessScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long transactionId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId);
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId, null);
|
||||
final String responseBody = "{\"officeId\":1,\"clientId\":107,\"loanId\":71,\"resourceId\":193,\"changes\""
|
||||
+ ":{\"transactionDate\":\"03 October 2022\",\"transactionAmount\":\"500\",\"locale\":\"en\",\"dateFormat\":"
|
||||
+ "\"dd MMMM yyyy\",\"paymentTypeId\":\"\"}}";
|
||||
@@ -63,6 +64,34 @@ public class AdjustTransactionCommandStrategyTest {
|
||||
assertEquals(response.getBody(), responseBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link AdjustTransactionCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithCommandSuccessScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long transactionId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId, "chargeback");
|
||||
final String responseBody = "{\"officeId\":1,\"clientId\":107,\"loanId\":71,\"resourceId\":193,\"changes\""
|
||||
+ ":{\"transactionDate\":\"03 October 2022\",\"transactionAmount\":\"500\",\"locale\":\"en\",\"dateFormat\":"
|
||||
+ "\"dd MMMM yyyy\",\"paymentTypeId\":\"\"}}";
|
||||
|
||||
given(testContext.loanTransactionsApiResource.adjustLoanTransaction(eq(loanId), eq(transactionId), eq(request.getBody()),
|
||||
eq("chargeback"))).willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
|
||||
assertEquals(response.getRequestId(), request.getRequestId());
|
||||
assertEquals(response.getHeaders(), request.getHeaders());
|
||||
assertEquals(response.getBody(), responseBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id and transaction id.
|
||||
*
|
||||
@@ -70,15 +99,20 @@ public class AdjustTransactionCommandStrategyTest {
|
||||
* the loan id
|
||||
* @param transactionId
|
||||
* the transaction id
|
||||
* @param transactionCommand
|
||||
* the optional transaction command
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final Long loanId, final Long transactionId) {
|
||||
private BatchRequest getBatchRequest(final Long loanId, final Long transactionId, final String transactionCommand) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = String.format("loans/%s/transactions/%s", loanId, transactionId);
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
if (StringUtils.isNotBlank(transactionCommand)) {
|
||||
br.setRelativeUrl(br.getRelativeUrl() + String.format("?command=%s", transactionCommand));
|
||||
}
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{\"locale\":\"en\",\"dateFormat\":\"dd MMMM yyyy\",\"transactionDate\":\"03 October 2022\",\"transactionAmount\":500}");
|
||||
|
||||
Reference in New Issue
Block a user