libeufin

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

commit 5ba09a22bc3d943d421e448639cbf41f58b9577b
parent 626e04e9aba2aee76ab2f5e1d052e3435874b39d
Author: MS <ms@taler.net>
Date:   Sat,  7 Jan 2023 09:40:58 +0100

Test Access API's wire transfer.

Diffstat:
Mnexus/src/test/kotlin/MakeEnv.kt | 5+++++
Mnexus/src/test/kotlin/SandboxAccessApiTest.kt | 50++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt @@ -180,6 +180,11 @@ fun prepSandboxDb() { passwordHash = CryptoUtil.hashpw("foo") name = "Foo" } + DemobankCustomerEntity.new { + username = "bar" + passwordHash = CryptoUtil.hashpw("bar") + name = "Bar" + } } } diff --git a/nexus/src/test/kotlin/SandboxAccessApiTest.kt b/nexus/src/test/kotlin/SandboxAccessApiTest.kt @@ -10,6 +10,56 @@ import tech.libeufin.sandbox.* class SandboxAccessApiTest { val mapper = ObjectMapper() + + // Move funds between accounts. + @Test + fun wireTransfer() { + withTestDatabase { + prepSandboxDb() + testApplication { + application(sandboxApp) + runBlocking { + // Foo gives 20 to Bar + client.post("/demobanks/default/access-api/accounts/foo/transactions") { + expectSuccess = true + contentType(ContentType.Application.Json) + basicAuth("foo", "foo") + setBody("""{ + "paytoUri": "payto://iban/${BAR_USER_IBAN}?message=test", + "amount": "TESTKUDOS:20" + }""".trimIndent() + ) + } + // Foo checks its balance: -20 + var R = client.get("/demobanks/default/access-api/accounts/foo") { + basicAuth("foo", "foo") + } + val mapper = ObjectMapper() + var j = mapper.readTree(R.readBytes()) + assert(j.get("balance").get("amount").asText() == "TESTKUDOS:20") + assert(j.get("balance").get("credit_debit_indicator").asText().lowercase() == "debit") + // Bar checks its balance: 20 + R = client.get("/demobanks/default/access-api/accounts/bar") { + basicAuth("bar", "bar") + } + j = mapper.readTree(R.readBytes()) + assert(j.get("balance").get("amount").asText() == "TESTKUDOS:20") + assert(j.get("balance").get("credit_debit_indicator").asText().lowercase() == "credit") + // Foo tries with an invalid amount + R = client.post("/demobanks/default/access-api/accounts/foo/transactions") { + contentType(ContentType.Application.Json) + basicAuth("foo", "foo") + setBody("""{ + "paytoUri": "payto://iban/${BAR_USER_IBAN}?message=test", + "amount": "TESTKUDOS:20.001" + }""".trimIndent() + ) + } + assert(R.status.value == HttpStatusCode.BadRequest.value) + } + } + } + } // Check successful and failing case due to insufficient funds. @Test fun debitWithdraw() {