From 1c159413d95ea84c2457fb68b404e8ed2a97b781 Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 29 Aug 2025 11:26:49 +0200 Subject: [PATCH] refactor/Add CAN_SEE_TRANSACTION_STATUS constant to permissions list and enhance transaction status handling in tests --- .../scala/code/api/constant/constant.scala | 1 + .../AccountInformationServiceAISApiTest.scala | 9 ++--- .../setup/LocalMappedConnectorTestSetup.scala | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/obp-api/src/main/scala/code/api/constant/constant.scala b/obp-api/src/main/scala/code/api/constant/constant.scala index 97a116fe7..4896451b5 100644 --- a/obp-api/src/main/scala/code/api/constant/constant.scala +++ b/obp-api/src/main/scala/code/api/constant/constant.scala @@ -331,6 +331,7 @@ object Constant extends MdcLoggable { CAN_SEE_BANK_ACCOUNT_ROUTING_ADDRESS, CAN_SEE_BANK_ACCOUNT_CURRENCY, CAN_SEE_TRANSACTION_METADATA, + CAN_SEE_TRANSACTION_STATUS ) final val SYSTEM_VIEW_PERMISSION_COMMON = List( diff --git a/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala b/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala index bd835d848..9b3a1d3cb 100644 --- a/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala +++ b/obp-api/src/test/scala/code/api/berlin/group/v1_3/AccountInformationServiceAISApiTest.scala @@ -192,10 +192,8 @@ class AccountInformationServiceAISApiTest extends BerlinGroupServerSetupV1_3 wit Then("We should get a 200 ") response.code should equal(200) response.body.extract[TransactionsJsonV13].account.iban should not be ("") -// response.body.extract[TransactionsJsonV13].transactions.booked.head.length >0 should be (true) - response.body.extract[TransactionsJsonV13].transactions.pending.head.nonEmpty should be (true) - response.body.extract[TransactionsJsonV13].transactions.booked.nonEmpty should be (true) - + response.body.extract[TransactionsJsonV13].transactions.booked.head.length >0 should be (true) + response.body.extract[TransactionsJsonV13].transactions.pending.head.length >0 should be (true) val requestGet2 = (V1_3_BG / "accounts" / testAccountId1.value / "transactions").GET <@ (user1) < 0 should be (true) + response.body.extract[TransactionsJsonV13].transactions.pending.head.length > 0 should be (true) val transactionId = response.body.extract[TransactionsJsonV13].transactions.pending.head.head.transactionId val requestGet2 = (V1_3_BG / "accounts" / testAccountId.value / "transactions" / transactionId).GET <@ (user1) diff --git a/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala b/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala index bc189cda9..e0d7019ec 100644 --- a/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala +++ b/obp-api/src/test/scala/code/setup/LocalMappedConnectorTestSetup.scala @@ -14,6 +14,7 @@ import code.transactionrequests.MappedTransactionRequest import code.util.Helper.MdcLoggable import com.openbankproject.commons.model._ import com.openbankproject.commons.model.enums.AccountRoutingScheme +import com.openbankproject.commons.model.enums._ import net.liftweb.common.Box import net.liftweb.mapper.{By, MetaMapper} import net.liftweb.util.Helpers._ @@ -131,8 +132,43 @@ trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermis .CPOtherAccountSecondaryRoutingAddress(randomString(5)) .CPOtherBankRoutingScheme(randomString(5)) .CPOtherBankRoutingAddress(randomString(5)) + .status(TransactionRequestStatus.COMPLETED.toString) // 🆕 Add transaction status field .saveMe .toTransaction.orNull + + { + val accountBalanceBefore = mappedBankAccount.accountBalance.get + val transactionAmount = Random.nextInt(1000).toLong + val accountBalanceAfter = accountBalanceBefore + transactionAmount + + mappedBankAccount.accountBalance(accountBalanceAfter).save + + MappedTransaction.create + .bank(account.bankId.value) + .account(account.accountId.value) + .transactionType(randomString(5)) + .tStartDate(startDate) + .tFinishDate(finishDate) + .currency(account.currency) + .amount(transactionAmount) + .newAccountBalance(accountBalanceAfter) + .description(randomString(5)) + .counterpartyAccountHolder(randomString(5)) + .counterpartyAccountKind(randomString(5)) + .counterpartyAccountNumber(randomString(5)) + .counterpartyBankName(randomString(5)) + .counterpartyIban(randomString(5)) + .counterpartyNationalId(randomString(5)) + .CPOtherAccountRoutingScheme(randomString(5)) + .CPOtherAccountRoutingAddress(randomString(5)) + .CPOtherAccountSecondaryRoutingScheme(randomString(5)) + .CPOtherAccountSecondaryRoutingAddress(randomString(5)) + .CPOtherBankRoutingScheme(randomString(5)) + .CPOtherBankRoutingAddress(randomString(5)) + .status(TransactionRequestStatus.INITIATED.toString) // 🆕 Add transaction status field + .saveMe + .toTransaction.orNull + } } override protected def createTransactionRequest(account: BankAccount): List[MappedTransactionRequest] = {