adamsaghy commented on code in PR #4246:
URL: https://github.com/apache/fineract/pull/4246#discussion_r1916222993


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/RepaymentReverseExternalIdTest.java:
##########
@@ -0,0 +1,148 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.integrationtests;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.UUID;
+import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
+import org.apache.fineract.client.models.GetLoansLoanIdResponse;
+import org.apache.fineract.client.models.PostLoansLoanIdRequest;
+import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest;
+import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
+import org.apache.fineract.client.models.PutGlobalConfigurationsRequest;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import 
org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants;
+import org.apache.fineract.integrationtests.common.BusinessDateHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import 
org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import 
org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class RepaymentReverseExternalIdTest extends BaseLoanIntegrationTest {
+
+    private static final String loanAmount = "1000";
+    private static final String startDate = "20 December 2024";
+    private static final String firstRepaymentDate = "23 December 2024";
+    private static final String secondRepaymentDate = "26 December 2024";
+    private static final String reverseDate = "27 December 2024";
+    private static final Double firstRepaymentAmount = 1000.0;
+    private static final Double secondRepaymentAmount = 10.0;
+
+    private ResponseSpecification responseSpec;
+    private RequestSpecification requestSpec;
+    private ClientHelper clientHelper;
+    private LoanTransactionHelper loanTransactionHelper;
+
+    @BeforeEach
+    public void setup() {
+        Utils.initializeRESTAssured();
+        this.requestSpec = new 
RequestSpecBuilder().setContentType(ContentType.JSON).build();
+        this.requestSpec.header("Authorization", "Basic " + 
Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+        this.responseSpec = new 
ResponseSpecBuilder().expectStatusCode(200).build();
+        this.loanTransactionHelper = new 
LoanTransactionHelper(this.requestSpec, this.responseSpec);
+        this.clientHelper = new ClientHelper(this.requestSpec, 
this.responseSpec);
+    }
+
+    @Test
+    public void testReverseRepaymentUpdatesExternalIdCorrectlyForOverpayment() 
{
+        try {
+            // Set up the business date if required
+            final LocalDate todaysDate = Utils.getLocalDateOfTenant();
+            
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE,
+                    new PutGlobalConfigurationsRequest().enabled(true));
+            BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, 
BusinessDateType.BUSINESS_DATE, todaysDate);
+
+            // Create a client and a loan with externalId
+            final Integer clientId = 
clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId().intValue();
+            final GetLoanProductsProductIdResponse loanProduct = 
createLoanProduct(loanTransactionHelper, null);
+            final String loanExternalId = UUID.randomUUID().toString();
+            final Integer loanId = createLoanAccount(clientId, 
loanProduct.getId(), loanExternalId);
+
+            // First repayment to cover part of the loan
+            final PostLoansLoanIdTransactionsResponse repaymentTransaction1 = 
loanTransactionHelper.makeLoanRepayment(loanExternalId,
+                    new PostLoansLoanIdTransactionsRequest().dateFormat("dd 
MMMM yyyy").transactionDate(firstRepaymentDate).locale("en")
+                            .transactionAmount(firstRepaymentAmount));
+
+            // Second repayment to create overpayment
+            final PostLoansLoanIdTransactionsResponse repaymentTransaction2 = 
loanTransactionHelper.makeLoanRepayment(loanExternalId,
+                    new PostLoansLoanIdTransactionsRequest().dateFormat("dd 
MMMM yyyy").transactionDate(secondRepaymentDate).locale("en")
+                            .transactionAmount(secondRepaymentAmount)); // 
This creates an overpayment as total is now
+                                                                        // 1010
+
+            // Verify that the loan is marked as overpaid
+            GetLoansLoanIdResponse loanDetailsOverpaid = 
loanTransactionHelper.getLoanDetails((long) loanId);
+            assertTrue(loanDetailsOverpaid.getStatus().getOverpaid()); // 
Overpaid status should be true
+            assertNotNull(loanDetailsOverpaid.getOverpaidOnDate()); // 
Overpaid date should be set
+            assertEquals(loanDetailsOverpaid.getExternalId(), loanExternalId); 
// externalId should match the original
+
+            // Reverse the second repayment to remove the overpayment
+            loanTransactionHelper.reverseRepayment(loanId, 
repaymentTransaction2.getResourceId().intValue(), reverseDate);
+
+            // Verify that the loan is no longer overpaid and overpaid date is 
reset
+            GetLoansLoanIdResponse loanDetailsNotOverpaid = 
loanTransactionHelper.getLoanDetails((long) loanId);
+            assertFalse(loanDetailsNotOverpaid.getStatus().getOverpaid()); // 
Overpaid status should be false
+            assertNull(loanDetailsNotOverpaid.getOverpaidOnDate()); // 
Overpaid date should be reset
+            assertEquals(loanDetailsNotOverpaid.getExternalId(), 
loanExternalId); // externalId should remain unchanged

Review Comment:
   Please make sure you are validating whether the reversed transaction 
external id is not changed! We don't need to check whether the external id of 
the loan got changed!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to