libeufin

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

commit 0fafe97aec9cf4b13274d12ea03e09d798653ad3
parent d84b94617f562056d7a87d38f5302c1701e7d3e2
Author: Antoine A <>
Date:   Wed,  4 Oct 2023 12:54:11 +0000

Improve JSON DSL

Diffstat:
Mbank/src/test/kotlin/LibeuFinApiTest.kt | 6+++---
Mbank/src/test/kotlin/TalerApiTest.kt | 38+++++++++++++++++++-------------------
Mbank/src/test/kotlin/helpers.kt | 6+++---
3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/bank/src/test/kotlin/LibeuFinApiTest.kt b/bank/src/test/kotlin/LibeuFinApiTest.kt @@ -723,7 +723,7 @@ class LibeuFinApiTest { } assertNotNull(db.customerCreate(customerFoo)) val validReq = json { - put("is_exchange", true) + "is_exchange" to true } // First call expects 500, because foo lacks a bank account client.patch("/accounts/foo") { @@ -749,7 +749,7 @@ class LibeuFinApiTest { client.patch("/accounts/foo") { basicAuth("foo", "pw") jsonBody(json { - put("name", "Another Foo") + "name" to "Another Foo" }) }.assertStatus(HttpStatusCode.Forbidden) // Finally checking that admin does get to patch foo's name. @@ -761,7 +761,7 @@ class LibeuFinApiTest { client.patch("/accounts/foo") { basicAuth("admin", "secret") jsonBody(json { - put("name", "Another Foo") + "name" to "Another Foo" }) }.assertStatus(HttpStatusCode.NoContent) val fooFromDb = db.customerGetFromLogin("foo") diff --git a/bank/src/test/kotlin/TalerApiTest.kt b/bank/src/test/kotlin/TalerApiTest.kt @@ -67,11 +67,11 @@ class TalerApiTest { } val valid_req = json { - put("request_uid", randHashCode()) - put("amount", "KUDOS:55") - put("exchange_base_url", "http://exchange.example.com/") - put("wtid", randShortHashCode()) - put("credit_account", "${stripIbanPayto(bankAccountBar.internalPaytoUri)}") + "request_uid" to randHashCode() + "amount" to "KUDOS:55" + "exchange_base_url" to "http://exchange.example.com/" + "wtid" to randShortHashCode() + "credit_account" to "${stripIbanPayto(bankAccountBar.internalPaytoUri)}" }; // Unkown account @@ -119,8 +119,8 @@ class TalerApiTest { basicAuth("foo", "pw") jsonBody( json(valid_req) { - put("wtid", randShortHashCode()) - put("exchange_base_url", "http://different-exchange.example.com/") + "wtid" to randShortHashCode() + "exchange_base_url" to "http://different-exchange.example.com/" } ) }.assertStatus(HttpStatusCode.Conflict) @@ -130,9 +130,9 @@ class TalerApiTest { basicAuth("foo", "pw") jsonBody( json(valid_req) { - put("request_uid", randHashCode()) - put("wtid", randShortHashCode()) - put("amount", "EUR:33") + "request_uid" to randHashCode() + "wtid" to randShortHashCode() + "amount" to "EUR:33" } ) }.assertBadRequest() @@ -142,7 +142,7 @@ class TalerApiTest { basicAuth("foo", "pw") jsonBody( json(valid_req) { - put("wtid", "I love chocolate") + "wtid" to "I love chocolate" } ) }.assertBadRequest() @@ -152,7 +152,7 @@ class TalerApiTest { basicAuth("foo", "pw") jsonBody( json(valid_req) { - put("wtid", randBase32Crockford(31)) + "wtid" to randBase32Crockford(31) } ) }.assertBadRequest() @@ -162,7 +162,7 @@ class TalerApiTest { basicAuth("foo", "pw") jsonBody( json(valid_req) { - put("request_uid", "I love chocolate") + "request_uid" to "I love chocolate" } ) }.assertBadRequest() @@ -172,7 +172,7 @@ class TalerApiTest { basicAuth("foo", "pw") jsonBody( json(valid_req) { - put("request_uid", randBase32Crockford(65)) + "request_uid" to randBase32Crockford(65) } ) }.assertBadRequest() @@ -280,9 +280,9 @@ class TalerApiTest { corebankWebApp(db, ctx) } val valid_req = json { - put("amount", "KUDOS:44") - put("reserve_pub", randEddsaPublicKey()) - put("debit_account", "${"payto://iban/BAR-IBAN-ABC"}") + "amount" to "KUDOS:44" + "reserve_pub" to randEddsaPublicKey() + "debit_account" to "${"payto://iban/BAR-IBAN-ABC"}" }; client.post("/accounts/foo/taler-wire-gateway/admin/add-incoming") { basicAuth("foo", "pw") @@ -293,7 +293,7 @@ class TalerApiTest { client.post("/accounts/foo/taler-wire-gateway/admin/add-incoming") { basicAuth("foo", "pw") jsonBody(json(valid_req) { - put("reserve_pub", "I love chocolate") + "reserve_pub" to "I love chocolate" }) }.assertBadRequest() @@ -301,7 +301,7 @@ class TalerApiTest { client.post("/accounts/foo/taler-wire-gateway/admin/add-incoming") { basicAuth("foo", "pw") jsonBody(json(valid_req) { - put("reserve_pub", randBase32Crockford(31)) + "reserve_pub" to randBase32Crockford(31) }) }.assertBadRequest() } diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt @@ -48,9 +48,9 @@ inline fun json(from: JsonObject = JsonObject(emptyMap()), builderAction: JsonBu class JsonBuilder(from: JsonObject) { val content: MutableMap<String, JsonElement> = from.toMutableMap() - inline fun <reified B> put(name: String, b: B) { - val json = Json.encodeToJsonElement(kotlinx.serialization.serializer<B>(), b); - content.put(name, json) + infix inline fun <reified T> String.to(v: T) { + val json = Json.encodeToJsonElement(kotlinx.serialization.serializer<T>(), v); + content.put(this, json) } }