gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Testing facade deletion.


From: gnunet
Subject: [libeufin] branch master updated: Testing facade deletion.
Date: Mon, 20 Mar 2023 09:23:36 +0100

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 9ca3c129 Testing facade deletion.
9ca3c129 is described below

commit 9ca3c129cdba5e71e3d2f93b05099ba8bb6f85e3
Author: ms <ms@taler.net>
AuthorDate: Sun Mar 19 22:18:09 2023 +0100

    Testing facade deletion.
    
    And causing the facade state table to get
    also deleted via 'on delete cascade'.
---
 .../tech/libeufin/nexus/BankConnectionProtocol.kt  |  2 +-
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    |  2 +-
 .../tech/libeufin/nexus/bankaccount/BankAccount.kt |  5 ++--
 .../tech/libeufin/nexus/server/NexusServer.kt      | 28 ++++++++++++++--------
 nexus/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
index deaa007a..6a18db21 100644
--- 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
index b1e47d3d..f0af4499 100644
--- 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
index 416cd4ae..c71e5531 100644
--- 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
index 3a3c8733..dc69829a 100644
--- 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
index 4958e301..30763005 100644
--- 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() {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]