Skip to content

Commit

Permalink
FINERACT-2081: Fix incorrect usage of appuser_id instead of created_b…
Browse files Browse the repository at this point in the history
…y for m_savings_account_transaction table
  • Loading branch information
Jaswanth-Sriram-Veturi committed Oct 20, 2024
1 parent c8e6adb commit c527241
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public String savingsTxnSchema() {
sqlBuilder.append(" left join m_savings_account sav on sav_txn.savings_account_id = sav.id ");
sqlBuilder.append(" left join m_client cl on sav.client_id = cl.id ");
sqlBuilder.append(" left join m_office o on cl.office_id = o.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.appuser_id = user.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.created_by = user.id ");
sqlBuilder.append(" left join m_staff staff on user.staff_id = staff.id ");
sqlBuilder.append(" left join m_cashiers c on c.staff_id = staff.id ");
sqlBuilder.append(" left join m_payment_detail payDetails on payDetails.id = sav_txn.payment_detail_id ");
Expand Down Expand Up @@ -752,7 +752,7 @@ public String cashierTxnSummarySchema() {
sqlBuilder.append(" left join m_savings_account sav on sav_txn.savings_account_id = sav.id ");
sqlBuilder.append(" left join m_client cl on sav.client_id = cl.id ");
sqlBuilder.append(" left join m_office o on cl.office_id = o.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.appuser_id = user.id ");
sqlBuilder.append(" left join m_appuser user on sav_txn.created_by = user.id ");
sqlBuilder.append(" left join m_staff staff on user.staff_id = staff.id ");
sqlBuilder.append(" left join m_cashiers c on c.staff_id = staff.id ");
sqlBuilder.append(" left join m_payment_detail payDetails on payDetails.id = sav_txn.payment_detail_id ");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* 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.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

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.util.List;
import org.apache.fineract.accounting.common.AccountingConstants;
import org.apache.fineract.client.models.CashierTransactionData;
import org.apache.fineract.client.models.GetFinancialActivityAccountsResponse;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersResponse;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.accounting.Account;
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
import org.apache.fineract.integrationtests.common.accounting.FinancialActivityAccountHelper;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.apache.fineract.integrationtests.teller.TellerHelper;
import org.apache.fineract.integrationtests.useradministration.roles.RolesHelper;
import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TellerCashierIntegrationTest {

private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private Account CASH_AT_MAINVAULT_ACCOUNT;
private Account CASH_AT_TELLER_ACCOUNT;

@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();
AccountHelper accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);

CASH_AT_MAINVAULT_ACCOUNT = accountHelper.createAssetAccount();
CASH_AT_TELLER_ACCOUNT = accountHelper.createAssetAccount();
setProperFinancialActivity();
}

private void setProperFinancialActivity() {
FinancialActivityAccountHelper financialActivityAccountHelper = new FinancialActivityAccountHelper(requestSpec);

// Clear any existing financial mappings before creating new ones
List<GetFinancialActivityAccountsResponse> financialMappings = financialActivityAccountHelper.getAllFinancialActivityAccounts();
financialMappings.forEach(mapping -> financialActivityAccountHelper.deleteFinancialActivityAccount(mapping.getId()));

// Map CASH_AT_MAINVAULT to a new asset account
Integer financialActivityCashAtMainVaultAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
AccountingConstants.FinancialActivity.CASH_AT_MAINVAULT.getValue(), CASH_AT_MAINVAULT_ACCOUNT.getAccountID(), responseSpec,
CommonConstants.RESPONSE_RESOURCE_ID);
assertNotNull(financialActivityCashAtMainVaultAccountId);

// Map CASH_AT_TELLER to a new asset account
Integer financialActivityCashAtTellerAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
AccountingConstants.FinancialActivity.CASH_AT_TELLER.getValue(), CASH_AT_TELLER_ACCOUNT.getAccountID(), responseSpec,
CommonConstants.RESPONSE_RESOURCE_ID);
assertNotNull(financialActivityCashAtTellerAccountId);
}

@Test
public void shouldReturnCashierTransactionsAfterAllocatingCash() {
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
Assertions.assertNotNull(roleId);

final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
Assertions.assertNotNull(staffId);

final Integer userId = UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId);
Assertions.assertNotNull(userId);

final Integer tellerId = TellerHelper.createTeller(requestSpec, responseSpec);
Assertions.assertNotNull(tellerId);

TellerHelper.createCashier(requestSpec, responseSpec, tellerId, staffId);

final GetTellersTellerIdCashiersResponse cashiersResponse = TellerHelper.getCashiers(this.requestSpec, this.responseSpec, tellerId);
Assertions.assertNotNull(cashiersResponse);

final Long cashierId = cashiersResponse.getCashiers().get(0).getId();

final BigDecimal allocatedAmount = new BigDecimal(1000);
TellerHelper.allocateCashToCashier(requestSpec, responseSpec, tellerId, cashierId, allocatedAmount);

final GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse summaryResponse = TellerHelper
.getCashierSummaryAndTransactions(requestSpec, responseSpec, tellerId, cashierId);
Assertions.assertNotNull(summaryResponse);

// Verify allocated cash
assertThat(allocatedAmount).isEqualByComparingTo(summaryResponse.getNetCash());

// Verify cashier transactions
List<CashierTransactionData> cashierTransactions = summaryResponse.getCashierTransactions().getPageItems();
Assertions.assertEquals(1, cashierTransactions.size());
assertThat(allocatedAmount).isEqualByComparingTo(cashierTransactions.get(0).getTxnAmount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* 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.teller;

import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse;
import org.apache.fineract.client.models.GetTellersTellerIdCashiersResponse;
import org.apache.fineract.client.util.JSON;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.organisation.teller.domain.TellerStatus;

public final class TellerHelper {

private static final Gson GSON = new JSON().getGson();

private static final String TELLER_API_URL_START = "/fineract-provider/api/v1/tellers/";

private TellerHelper() {}

public static Integer createTeller(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String url = TELLER_API_URL_START + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, url, createTellerAsJSON(), "resourceId");
}

public static Object createCashier(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer tellerId, final Integer staffId) {
final String url = TELLER_API_URL_START + tellerId + "/cashiers?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, url, createCashierAsJSON(staffId));
}

public static Object allocateCashToCashier(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer tellerId, final Long cashierId, final BigDecimal txnAmount) {
final String url = TELLER_API_URL_START + tellerId + "/cashiers/" + cashierId + "/allocate?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, url, allocateCashAsJSON(txnAmount));
}

public static GetTellersTellerIdCashiersResponse getCashiers(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final Integer tellerId) {
final String url = TELLER_API_URL_START + tellerId + "/cashiers?" + Utils.TENANT_IDENTIFIER;
final String response = Utils.performServerGet(requestSpec, responseSpec, url, null);
return GSON.fromJson(response, GetTellersTellerIdCashiersResponse.class);
}

public static GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse getCashierSummaryAndTransactions(
final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer tellerId,
final Long cashierId) {
final String url = TELLER_API_URL_START + tellerId + "/cashiers/" + cashierId + "/summaryandtransactions?currencyCode=USD&"
+ Utils.TENANT_IDENTIFIER;
final String response = Utils.performServerGet(requestSpec, responseSpec, url, null);
return GSON.fromJson(response, GetTellersTellerIdCashiersCashiersIdSummaryAndTransactionsResponse.class);
}

public static String allocateCashAsJSON(final BigDecimal txnAmount) {

final Map<String, Object> map = getMapWithDate();

map.put("txnDate", "1 October 2024");
map.put("currencyCode", "USD");
map.put("txnAmount", txnAmount);
map.put("txnNote", "allocate cash");

return GSON.toJson(map);
}

public static String createCashierAsJSON(final Integer staffId) {

final Map<String, Object> map = getMapWithDate();

map.put("staffId", staffId);
map.put("description", "");
map.put("isFullDay", true);
map.put("startDate", "1 October 2024");
map.put("endDate", "1 October 2025");

return GSON.toJson(map);
}

public static String createTellerAsJSON() {

final Map<String, Object> map = getMapWithDate();

map.put("officeId", 1);
map.put("name", Utils.uniqueRandomStringGenerator("john_", 5));
map.put("status", TellerStatus.ACTIVE.getValue());
map.put("description", "");
map.put("startDate", "1 October 2020");
map.put("endDate", "");

return GSON.toJson(map);
}

public static Map<String, Object> getMapWithDate() {
HashMap<String, Object> map = new HashMap<>();

map.put("locale", "en");
map.put("dateFormat", "dd MMMM yyyy");

return map;
}
}

0 comments on commit c527241

Please sign in to comment.