libeufin

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

commit e4746ba6a85dc2b0f05b76ea7b2542ac4a87fe5a
parent eb937c60e48893409012fbe0584a270e91452a79
Author: ms <ms@taler.net>
Date:   Thu,  5 May 2022 13:44:47 +0200

Make registrations optional.

That requires to override the --allow-registrations flag
(to be given along the --override flag) passed to the default
demobank, and the injection of a new LIBEUFIN_UI_ALLOW_REGISTRATIONS
value to the SPA.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 26+++++++++++++++++++++++---
Msandbox/src/test/kotlin/StringsTest.kt | 6++++++
2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -136,6 +136,9 @@ class Config : CliktCommand( private val nameArgument by argument( "NAME", help = "Name of this configuration" ) + private val overrideOption by option( + "--override", help = "Override an existing demobank." + ).flag("--no-override", default = false) private val currencyOption by option("--currency").default("EUR") private val bankDebtLimitOption by option("--bank-debt-limit").int().default(1000000) private val usersDebtLimitOption by option("--users-debt-limit").int().default(1000) @@ -153,10 +156,18 @@ class Config : CliktCommand( execThrowableOrTerminate { dbCreateTables(dbConnString) transaction { - val checkExist = DemobankConfigEntity.find { + val maybeDemobank = DemobankConfigEntity.find { DemobankConfigsTable.name eq nameArgument }.firstOrNull() - if (checkExist != null) { + if (maybeDemobank != null) { + if (overrideOption) { + maybeDemobank.currency = currencyOption + maybeDemobank.bankDebtLimit = bankDebtLimitOption + maybeDemobank.usersDebtLimit = usersDebtLimitOption + maybeDemobank.allowRegistrations = allowRegistrationsOption + maybeDemobank.withSignupBonus = withSignupBonusOption + return@transaction + } println("Error, demobank ${nameArgument} exists already, not overriding it.") exitProcess(1) } @@ -1006,7 +1017,10 @@ val sandboxApp: Application.() -> Unit = { val surveyUrl = System.getenv( "TALER_ENV_URL_MERCHANT_SURVEY") ?: "https://demo.taler.net/survey/" content = content.replace("%DEMO_SITE_SURVEY_URL%", surveyUrl) - logger.debug("after links replacement + $content") + content = content.replace( + "%LIBEUFIN_UI_ALLOW_REGISTRATIONS%", + demobank.allowRegistrations.toString() + ) call.respondText(content, ContentType.Text.Html) return@get } @@ -1415,6 +1429,12 @@ val sandboxApp: Application.() -> Unit = { post("/testing/register") { // Check demobank was created. val demobank = ensureDemobank(call) + if (!demobank.allowRegistrations) { + throw SandboxError( + HttpStatusCode.UnprocessableEntity, + "The bank doesn't allow new registrations at the moment." + ) + } val req = call.receiveJson<CustomerRegistration>() val checkExist = transaction { DemobankCustomerEntity.find { diff --git a/sandbox/src/test/kotlin/StringsTest.kt b/sandbox/src/test/kotlin/StringsTest.kt @@ -19,4 +19,10 @@ class StringsTest { ) println(content) } + + @Test + fun booleanToString() { + assert(true.toString() == "true") + assert(false.toString() == "false") + } } \ No newline at end of file