gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (d11290f -> 107a5bc)


From: gnunet
Subject: [libeufin] branch master updated (d11290f -> 107a5bc)
Date: Wed, 08 Apr 2020 19:33:45 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a change to branch master
in repository libeufin.

    from d11290f  payto / amount parsers (untested)
     new 9e55ab8  test skeleton
     new 107a5bc  testing payto/amount parsers

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt |  9 ++---
 nexus/src/test/kotlin/XPathTest.kt                 |  2 --
 nexus/src/test/kotlin/taler.kt                     | 38 ++++++++++++++++++++++
 3 files changed, 43 insertions(+), 6 deletions(-)
 create mode 100644 nexus/src/test/kotlin/taler.kt

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
index c2d2472..2d9f338 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -76,7 +76,7 @@ class Taler(app: Route) {
     data class Payto(
         val name: String,
         val iban: String,
-        val bic: String?
+        val bic: String // empty string in case no BIC was given
     )
     data class AmountWithCurrency(
         val currency: String,
@@ -86,10 +86,11 @@ class Taler(app: Route) {
     /** Helper functions */
 
     fun parsePayto(paytoUri: String): Payto {
-        val match = 
Regex("payto://.*/([A-Z0-9]+)/([A-Z0-9]+)?\\?name=(\\w+)").find(paytoUri) ?: 
throw
+        // payto://iban/BIC?/IBAN?name=<name>
+        val match = 
Regex("payto://iban/([A-Z0-9]+/)?([A-Z0-9]+)\\?name=(\\w+)").find(paytoUri) ?: 
throw
                 NexusError(HttpStatusCode.BadRequest, "invalid payto URI 
($paytoUri)")
-        val (iban, bic, name) = match.destructured
-        return Payto(name, iban, bic)
+        val (bic, iban, name) = match.destructured
+        return Payto(name, iban, bic.replace("/", ""))
     }
 
     fun parseAmount(amount: String): AmountWithCurrency {
diff --git a/nexus/src/test/kotlin/XPathTest.kt 
b/nexus/src/test/kotlin/XPathTest.kt
index 388fb6d..f381175 100644
--- a/nexus/src/test/kotlin/XPathTest.kt
+++ b/nexus/src/test/kotlin/XPathTest.kt
@@ -2,10 +2,8 @@ package tech.libeufin.nexus
 
 import org.junit.Test
 import org.w3c.dom.Document
-import org.w3c.dom.Node
 import tech.libeufin.util.XMLUtil
 
-
 class XPathTest {
 
     @Test
diff --git a/nexus/src/test/kotlin/taler.kt b/nexus/src/test/kotlin/taler.kt
new file mode 100644
index 0000000..d582a97
--- /dev/null
+++ b/nexus/src/test/kotlin/taler.kt
@@ -0,0 +1,38 @@
+package tech.libeufin.nexus
+
+import io.ktor.routing.RootRouteSelector
+import io.ktor.routing.Route
+import io.ktor.routing.RouteSelector
+import io.ktor.routing.RouteSelectorEvaluation
+import io.ktor.util.InternalAPI
+import org.junit.Before
+import org.junit.Test
+import tech.libeufin.nexus.Taler
+import tech.libeufin.util.Amount
+import java.math.BigDecimal
+
+class TalerTest {
+
+    @InternalAPI
+    val taler = Taler(Route(null, RootRouteSelector("unused")))
+
+    @InternalAPI
+    @Test
+    fun paytoParserTest() {
+        val payto = taler.parsePayto("payto://iban/ABC/XYZ?name=foo")
+        assert(payto.bic == "ABC" && payto.iban == "XYZ" && payto.name == 
"foo")
+        val paytoNoBic = taler.parsePayto("payto://iban/XYZ?name=foo")
+        assert(paytoNoBic.bic == "" && paytoNoBic.iban == "XYZ" && 
paytoNoBic.name == "foo")
+    }
+
+    @InternalAPI
+    @Test
+    fun amountParserTest() {
+        val amount = taler.parseAmount("EUR:1")
+        assert(amount.currency == "EUR" && amount.amount.equals(BigDecimal(1)))
+        val amount299 = taler.parseAmount("EUR:2.99")
+        assert(amount299.amount.compareTo(Amount("2.99")) == 0)
+        val amount25 = taler.parseAmount("EUR:2.5")
+        assert(amount25.amount.compareTo(Amount("2.5")) == 0)
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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