FINERACT-1724 - Remove Restriction from faurd mark

This commit is contained in:
Janos Haber
2023-04-22 23:26:45 +02:00
committed by Adam Saghy
parent cefcb53424
commit 1d86a8f0cb
2 changed files with 47 additions and 43 deletions
@@ -2521,11 +2521,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
Loan loan = this.loanAssembler.assembleFrom(loanId);
final Map<String, Object> changes = new LinkedHashMap<>();
if (!loan.isOpen()) {
throw new GeneralPlatformDomainRuleException("error.msg.loan.mark.as.fraud.not.allowed",
"Loan Id: " + loanId + " mark as fraud is not allowed as loan status is not active", loan.getStatus().getCode());
}
final boolean fraud = command.booleanPrimitiveValueOfParameterNamed(LoanApiConstants.FRAUD_ATTRIBUTE_NAME);
if (loan.isFraud() != fraud) {
loan.markAsFraud(fraud);
@@ -32,7 +32,10 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.PutLoansLoanIdResponse;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
@@ -69,54 +72,60 @@ public class LoanAccountFraudTest {
@Test
public void testMarkLoanAsFraud() {
final String command = "markAsFraud";
// Client and Loan account creation
final Integer loanId = createAccounts(15, 1);
try {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, todaysDate);
final String command = "markAsFraud";
// Client and Loan account creation
final Integer loanId = createAccounts(15, 1);
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
// Default values Not Null and False
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
// Default values Not Null and False
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
String payload = loanTransactionHelper.getLoanFraudPayloadAsJSON("fraud", "true");
// Send the request expecting an error because the Loan is not active yet
PutLoansLoanIdResponse putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload,
this.responseSpecError);
String payload = loanTransactionHelper.getLoanFraudPayloadAsJSON("fraud", "true");
// Send the request, not expecting any errors (because only open loan restriction removed)
PutLoansLoanIdResponse putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload,
this.responseSpec);
String statusCode = getLoansLoanIdResponse.getStatus().getCode();
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
String statusCode = getLoansLoanIdResponse.getStatus().getCode();
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
// Approve the Loan active
approveAndDisburseLoan(loanId, this.operationDate, this.amountVal);
// Approve the Loan active
approveAndDisburseLoan(loanId, this.operationDate, this.amountVal);
// Default values Not Null and False
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
statusCode = getLoansLoanIdResponse.getStatus().getCode();
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
// Default values Not Null and False
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.TRUE, getLoansLoanIdResponse.getFraud());
statusCode = getLoansLoanIdResponse.getStatus().getCode();
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
// Mark On the Fraud
putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload, this.responseSpec);
assertNotNull(putLoansLoanIdResponse);
// Mark On the Fraud
putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload, this.responseSpec);
assertNotNull(putLoansLoanIdResponse);
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.TRUE, getLoansLoanIdResponse.getFraud());
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.TRUE, getLoansLoanIdResponse.getFraud());
// Mark Off the Fraud
payload = loanTransactionHelper.getLoanFraudPayloadAsJSON("fraud", "false");
putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload, this.responseSpec);
assertNotNull(putLoansLoanIdResponse);
// Mark Off the Fraud
payload = loanTransactionHelper.getLoanFraudPayloadAsJSON("fraud", "false");
putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload, this.responseSpec);
assertNotNull(putLoansLoanIdResponse);
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getFraud());
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
} finally {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
}
}
private Integer createAccounts(final Integer daysToSubtract, final Integer numberOfRepayments) {