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
+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