libeufin

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

commit 1aa9682001fd635e24270baaa0e661912a14db29
parent d15577e374f2752e27bc44887b28ccda960777a8
Author: MS <ms@taler.net>
Date:   Tue, 31 Jan 2023 17:21:47 +0100

tests

Diffstat:
Mnexus/src/test/kotlin/MakeEnv.kt | 52+++++++++++++++++++++++++++++++++++++++++++++++-----
Anexus/src/test/kotlin/TalerTest.kt | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 135 insertions(+), 5 deletions(-)

diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt @@ -1,9 +1,13 @@ +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.statements.api.ExposedBlob import org.jetbrains.exposed.sql.transactions.transaction +import org.jetbrains.exposed.sql.transactions.transactionManager import tech.libeufin.nexus.* import tech.libeufin.nexus.dbCreateTables import tech.libeufin.nexus.dbDropTables +import tech.libeufin.nexus.server.FetchLevel +import tech.libeufin.nexus.server.FetchSpecAllJson import tech.libeufin.sandbox.* import tech.libeufin.util.CryptoUtil import tech.libeufin.util.EbicsInitState @@ -59,11 +63,10 @@ fun withTestDatabase(f: () -> Unit) { } } Database.connect("jdbc:sqlite:$TEST_DB_FILE") + // ).transactionManager.defaultIsolationLevel = java.sql.Connection.TRANSACTION_SERIALIZABLE dbDropTables(TEST_DB_CONN) tech.libeufin.sandbox.dbDropTables(TEST_DB_CONN) - try { - f() - } + try { f() } finally { File(TEST_DB_FILE).also { if (it.exists()) { @@ -73,13 +76,22 @@ fun withTestDatabase(f: () -> Unit) { } } +val reportSpec: String = jacksonObjectMapper(). +writerWithDefaultPrettyPrinter(). +writeValueAsString( + FetchSpecAllJson( + level = FetchLevel.REPORT, + "foo" + ) +) + fun prepNexusDb() { dbCreateTables(TEST_DB_CONN) transaction { val u = NexusUserEntity.new { username = "foo" - passwordHash = "foo" - superuser = false + passwordHash = CryptoUtil.hashpw("foo") + superuser = true } val c = NexusBankConnectionEntity.new { connectionId = "foo" @@ -118,6 +130,36 @@ fun prepNexusDb() { highestSeenBankMessageSerialId = 0 accountHolder = "bar" } + NexusScheduledTaskEntity.new { + resourceType = "bank-account" + resourceId = "foo" + this.taskCronspec = "* * *" // Every second. + this.taskName = "read-report" + this.taskType = "fetch" + this.taskParams = reportSpec + } + NexusScheduledTaskEntity.new { + resourceType = "bank-account" + resourceId = "foo" + this.taskCronspec = "* * *" // Every second. + this.taskName = "send-payment" + this.taskType = "submit" + this.taskParams = "{}" + } + // Giving 'foo' a Taler facade. + val f = FacadeEntity.new { + facadeName = "taler" + type = "taler-wire-gateway" + creator = u + } + FacadeStateEntity.new { + bankAccount = "foo" + bankConnection = "foo" + currency = "TESTKUDOS" + reserveTransferLevel = "report" + facade = f + highestSeenMessageSerialId = 0 + } } } diff --git a/nexus/src/test/kotlin/TalerTest.kt b/nexus/src/test/kotlin/TalerTest.kt @@ -0,0 +1,87 @@ +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import io.ktor.client.plugins.* +import io.ktor.client.request.* +import io.ktor.http.* +import io.ktor.server.testing.* +import kotlinx.coroutines.* +import org.jetbrains.exposed.sql.transactions.TransactionManager +import org.jetbrains.exposed.sql.transactions.transaction +import org.junit.Ignore +import org.junit.Test +import tech.libeufin.nexus.* +import tech.libeufin.nexus.bankaccount.fetchBankAccountTransactions +import tech.libeufin.nexus.server.FetchLevel +import tech.libeufin.nexus.server.FetchSpecAllJson +import tech.libeufin.nexus.server.client +import tech.libeufin.nexus.server.nexusApp +import tech.libeufin.sandbox.sandboxApp +import tech.libeufin.sandbox.wireTransfer + +// This class tests the features related to the Taler facade. +class TalerTest { + + @Ignore // Ignoring because no assert takes place. + @Test // Triggering a refund because of a duplicate reserve pub. + fun refundTest() { + withNexusAndSandboxUser { + // Creating a Taler facade for the user 'foo'. + testApplication { + application(nexusApp) + client.post("/facades") { + expectSuccess = true + contentType(ContentType.Application.Json) + basicAuth("foo", "foo") + setBody(""" + { "name":"foo-facade", + "type":"taler-wire-gateway", + "config": { + "bankAccount":"foo", + "bankConnection":"foo", + "currency":"TESTKUDOS", + "reserveTransferLevel":"report" + } + }""".trimIndent() + ) + } + } + wireTransfer( + "bar", + "foo", + demobank = "default", + "5WFM8PXN7Y315RVZFJ280299B94W1HR1AAHH6XNDYEJBC0T3E5N0", + "TESTKUDOS:3" + ) + testApplication { + application(sandboxApp) + // Nexus downloads the fresh transaction. + fetchBankAccountTransactions( + client, + fetchSpec = FetchSpecAllJson( + level = FetchLevel.REPORT, + "foo" + ), + "foo" + ) + } + wireTransfer( + "bar", + "foo", + demobank = "default", + "5WFM8PXN7Y315RVZFJ280299B94W1HR1AAHH6XNDYEJBC0T3E5N0", + "TESTKUDOS:3" + ) + testApplication { + application(sandboxApp) + // Nexus downloads the new transaction, having a duplicate subject. + fetchBankAccountTransactions( + client, + fetchSpec = FetchSpecAllJson( + level = FetchLevel.REPORT, + "foo" + ), + "foo" + ) + } + } + } +} +\ No newline at end of file