[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Calculate balance per bank account ent
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Calculate balance per bank account entity, and not per IBAN. |
Date: |
Tue, 24 Aug 2021 01:06:45 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 3485530 Calculate balance per bank account entity, and not per IBAN.
3485530 is described below
commit 34855306d980eb6fede98328d5604dffeb3d565e
Author: MS <ms@taler.net>
AuthorDate: Mon Aug 23 12:04:12 2021 -1100
Calculate balance per bank account entity, and not per IBAN.
---
.../tech/libeufin/sandbox/EbicsProtocolBackend.kt | 2 +-
.../src/main/kotlin/tech/libeufin/sandbox/Main.kt | 3 +-
.../kotlin/tech/libeufin/sandbox/bankAccount.kt | 28 ++++++-------
sandbox/src/test/kotlin/BalanceTest.kt | 47 ++++++++--------------
4 files changed, 31 insertions(+), 49 deletions(-)
diff --git
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index a3ede1b..9c17085 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -446,7 +446,7 @@ private fun constructCamtResponse(type: Int, subscriber:
EbicsSubscriberEntity):
*/
val bankAccount = getBankAccountFromSubscriber(subscriber)
logger.info("getting history for account with iban ${bankAccount.iban}")
- val history = historyForAccount(bankAccount.iban)
+ val history = historyForAccount(bankAccount)
return buildCamtString(type, bankAccount.iban, history)
}
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index bdc592b..a6fa319 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -519,7 +519,8 @@ fun serverMain(dbName: String, port: Int) {
// only reason for a post is to hide the iban (to some degree.)
post("/admin/payments/camt") {
val body = call.receiveJson<CamtParams>()
- val history = historyForAccount(body.iban)
+ val bankAccount = getBankAccountFromIban(body.iban)
+ val history = historyForAccount(bankAccount)
SandboxAssert(body.type == 53, "Only Camt.053 is implemented")
val camt53 = buildCamtString(body.type, body.iban, history)
call.respondText(camt53, ContentType.Text.Xml,
HttpStatusCode.OK)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index a2e09ee..cafe2ea 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -55,22 +55,19 @@ fun balanceForAccount(bankAccount: BankAccountEntity):
BigDecimal {
return balance
}
-fun historyForAccount(iban: String): List<RawPayment> {
+fun historyForAccount(bankAccount: BankAccountEntity): List<RawPayment> {
val history = mutableListOf<RawPayment>()
- logger.debug("Querying transactions involving: ${iban}")
transaction {
- BankAccountTransactionsTable.select {
- BankAccountTransactionsTable.creditorIban eq iban or
- (BankAccountTransactionsTable.debtorIban eq iban)
- /**
- FIXME: add the following condition too:
- and (BankAccountTransactionsTable.date.between(start.millis,
end.millis))
- */
- /**
- FIXME: add the following condition too:
- and (BankAccountTransactionsTable.date.between(start.millis,
end.millis))
- */
- }.forEach {
+ /**
+ FIXME: add the following condition too:
+ and (BankAccountTransactionsTable.date.between(start.millis,
end.millis))
+ */
+ /**
+ FIXME: add the following condition too:
+ and (BankAccountTransactionsTable.date.between(start.millis,
end.millis))
+ */
+ BankAccountTransactionsTable.select {
BankAccountTransactionsTable.account eq bankAccount.id }
+ }.forEach {
history.add(
RawPayment(
subject = it[BankAccountTransactionsTable.subject],
@@ -92,6 +89,5 @@ fun historyForAccount(iban: String): List<RawPayment> {
)
)
}
- }
return history
-}
+}
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/BalanceTest.kt
b/sandbox/src/test/kotlin/BalanceTest.kt
index 98c0a64..5a579e6 100644
--- a/sandbox/src/test/kotlin/BalanceTest.kt
+++ b/sandbox/src/test/kotlin/BalanceTest.kt
@@ -3,6 +3,7 @@ import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.Test
+import tech.libeufin.sandbox.BankAccountEntity
import tech.libeufin.sandbox.BankAccountTransactionsTable
import tech.libeufin.sandbox.BankAccountsTable
import tech.libeufin.sandbox.balanceForAccount
@@ -17,8 +18,15 @@ class BalanceTest {
withTestDatabase {
transaction {
SchemaUtils.create(BankAccountTransactionsTable)
+ val one = BankAccountEntity.new {
+ name = "Person 1"
+ iban = "IBAN 1"
+ bic = "BIC"
+ label = "label 1"
+ currency = "EUR"
+ }
BankAccountTransactionsTable.insert {
- it[account] = EntityID(0, BankAccountsTable)
+ it[account] = one.id
it[creditorIban] = "earns"
it[creditorBic] = "BIC"
it[creditorName] = "Creditor Name"
@@ -30,11 +38,11 @@ class BalanceTest {
it[date] = LocalDateTime.now().millis()
it[currency] = "EUR"
it[pmtInfId] = "0"
- it[direction] = "DBIT"
+ it[direction] = "CRDT"
it[accountServicerReference] =
"test-account-servicer-reference"
}
BankAccountTransactionsTable.insert {
- it[account] = EntityID(0, BankAccountsTable)
+ it[account] = one.id
it[creditorIban] = "earns"
it[creditorBic] = "BIC"
it[creditorName] = "Creditor Name"
@@ -46,15 +54,15 @@ class BalanceTest {
it[date] = LocalDateTime.now().millis()
it[currency] = "EUR"
it[pmtInfId] = "0"
- it[direction] = "DBIT"
+ it[direction] = "CRDT"
it[accountServicerReference] =
"test-account-servicer-reference"
}
BankAccountTransactionsTable.insert {
- it[account] = EntityID(0, BankAccountsTable)
- it[creditorIban] = "other"
+ it[account] = one.id
+ it[creditorIban] = "earns"
it[creditorBic] = "BIC"
it[creditorName] = "Creditor Name"
- it[debtorIban] = "earns"
+ it[debtorIban] = "spends"
it[debtorBic] = "BIC"
it[debtorName] = "Debitor Name"
it[subject] = "deal"
@@ -65,30 +73,7 @@ class BalanceTest {
it[direction] = "DBIT"
it[accountServicerReference] =
"test-account-servicer-reference"
}
- BankAccountTransactionsTable.insert {
- it[account] = EntityID(0, BankAccountsTable)
- it[creditorIban] = "other"
- it[creditorBic] = "BIC"
- it[creditorName] = "Creditor Name"
- it[debtorIban] = "earns-bad-amount"
- it[debtorBic] = "BIC"
- it[debtorName] = "Debitor Name"
- it[subject] = "deal"
- it[amount] = "not a number"
- it[date] = LocalDateTime.now().millis()
- it[currency] = "EUR"
- it[pmtInfId] = "0"
- it[direction] = "DBIT"
- it[accountServicerReference] =
"test-account-servicer-reference"
- }
- assert(java.math.BigDecimal.ONE == balanceForAccount("earns"))
- try {
- balanceForAccount("earns-bad-amount")
- } catch (e: UtilError) {
- return@transaction
- }
- // here the expected exception wasn't thrown.
- assert(false)
+ assert(java.math.BigDecimal.ONE == balanceForAccount(one))
}
}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Calculate balance per bank account entity, and not per IBAN.,
gnunet <=