libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 9ca3c129cdba5e71e3d2f93b05099ba8bb6f85e3
parent 79b3ce63052d8e5c87dd9abf78af780aff7c0707
Author: ms <ms@taler.net>
Date:   Sun, 19 Mar 2023 22:18:09 +0100

Testing facade deletion.

And causing the facade state table to get
also deleted via 'on delete cascade'.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/BankConnectionProtocol.kt | 2+-
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 2+-
Mnexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt | 5++---
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 28++++++++++++++++++----------
Mnexus/src/test/kotlin/NexusApiTest.kt | 16++++++++++++++++
5 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/BankConnectionProtocol.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/BankConnectionProtocol.kt @@ -41,7 +41,7 @@ interface BankConnectionProtocol { // Create a new connection from backup data. fun createConnectionFromBackup(connId: String, user: NexusUserEntity, passphrase: String?, backup: JsonNode) - // Create a new connection from a HTTP request. + // Create a new connection from an HTTP request. fun createConnection(connId: String, user: NexusUserEntity, data: JsonNode) // Merely a formatter of connection details coming from diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -399,7 +399,7 @@ object FacadeStateTable : LongIdTable() { // "statement", "report", "notification" val reserveTransferLevel = text("reserveTransferLevel") - val facade = reference("facade", FacadesTable) + val facade = reference("facade", FacadesTable, onDelete = ReferenceOption.CASCADE) /** * Highest ID seen in the raw transactions table. diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -465,11 +465,10 @@ fun importBankAccount(call: ApplicationCall, offeredBankAccountId: String, nexus if (this.iban != offeredAccount[OfferedBankAccountsTable.iban]) { throw NexusError( HttpStatusCode.Conflict, - // different accounts == different IBANs - "Cannot import two different accounts under one label: $nexusBankAccountId" + "$nexusBankAccountId exists already and its IBAN is different from $offeredBankAccountId" ) } - // a imported bank account already exists and + // an imported bank account already exists and // the user tried to import the same IBAN to it. Do nothing this } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -57,23 +57,29 @@ import tech.libeufin.util.* import java.net.BindException import java.net.URLEncoder import kotlin.system.exitProcess -/** - * Return facade state depending on the type. - */ + +// Return facade state depending on the type. fun getFacadeState(type: String, facade: FacadeEntity): JsonNode { return transaction { when (type) { - "taler-wire-gateway", "anastasis" -> { + "taler-wire-gateway", + "anastasis" -> { val state = FacadeStateEntity.find { FacadeStateTable.facade eq facade.id }.firstOrNull() - if (state == null) throw NexusError(HttpStatusCode.NotFound, "State of facade ${facade.id} not found") + if (state == null) throw NexusError( + HttpStatusCode.NotFound, + "State of facade ${facade.id} not found" + ) val node = jacksonObjectMapper().createObjectNode() node.put("bankConnection", state.bankConnection) node.put("bankAccount", state.bankAccount) node } - else -> throw NexusError(HttpStatusCode.NotFound, "Facade type $type not supported") + else -> throw NexusError( + HttpStatusCode.NotFound, + "Facade type $type not supported" + ) } } } @@ -783,6 +789,7 @@ val nexusApp: Application.() -> Unit = { NexusBankConnectionEntity.find { NexusBankConnectionsTable.connectionId eq body.name } .firstOrNull() if (existingConn != null) { + // FIXME: make idempotent. throw NexusError(HttpStatusCode.Conflict, "connection '${body.name}' exists already") } when (body) { @@ -884,9 +891,9 @@ val nexusApp: Application.() -> Unit = { NexusBankMessageEntity.find { NexusBankMessagesTable.bankConnection eq conn.id }.map { list.bankMessages.add( BankMessageInfo( - it.messageId, - it.code, - it.message.bytes.size.toLong() + messageId = it.messageId, + code = it.code, + length = it.message.bytes.size.toLong() ) ) } @@ -965,7 +972,8 @@ val nexusApp: Application.() -> Unit = { val fcid = ensureNonNull(call.parameters["fcid"]) transaction { val f = FacadeEntity.findByName(fcid) ?: throw NexusError( - HttpStatusCode.NotFound, "Facade $fcid does not exist" + HttpStatusCode.NotFound, + "Facade $fcid does not exist" ) f.delete() } diff --git a/nexus/src/test/kotlin/NexusApiTest.kt b/nexus/src/test/kotlin/NexusApiTest.kt @@ -11,6 +11,22 @@ import tech.libeufin.nexus.server.nexusApp */ class NexusApiTest { + // Testing basic operations on facades. + @Test + fun facades() { + // Deletes the facade (created previously by MakeEnv.kt) + withTestDatabase { + prepNexusDb() + testApplication { + application(nexusApp) + client.delete("/facades/taler") { + basicAuth("foo", "foo") + expectSuccess = true + } + } + } + } + // Testing the creation of scheduled tasks. @Test fun schedule() {