libeufin

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

commit e34e42758c4159d5dfeb8f2efad4b170e2425e09
parent b95b95b5d15eee3204c9c754835b5231ed0a3c3e
Author: Antoine A <>
Date:   Mon, 27 Nov 2023 14:04:53 +0000

Improve corebank API

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt | 2+-
Mbank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt | 5+++++
Mbank/src/test/kotlin/CoreBankApiTest.kt | 14+++++++-------
Mbank/src/test/kotlin/helpers.kt | 2--
Mintegration/test/IntegrationTest.kt | 4++--
5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt @@ -176,7 +176,7 @@ private fun Routing.coreBankAccountsApi(db: Database, ctx: BankConfig) { "Bank internalPayToUri reuse '${internalPayto.canonical}'", TalerErrorCode.BANK_REGISTER_PAYTO_URI_REUSE ) - AccountCreationResult.Success -> call.respond(HttpStatusCode.Created) + AccountCreationResult.Success -> call.respond(RegisterAccountResponse(internalPayto.canonical)) } } } diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt @@ -120,6 +120,11 @@ data class RegisterAccountRequest( val internal_payto_uri: IbanPayTo? = null ) +@Serializable +data class RegisterAccountResponse( + val internal_payto_uri: String +) + /** * Request of PATCH /accounts/{USERNAME} */ diff --git a/bank/src/test/kotlin/CoreBankApiTest.kt b/bank/src/test/kotlin/CoreBankApiTest.kt @@ -174,11 +174,11 @@ class CoreBankAccountsApiTest { // Check Ok client.post("/accounts") { json(req) - }.assertCreated() + }.assertOk() // Testing idempotency client.post("/accounts") { json(req) - }.assertCreated() + }.assertOk() // Test generate payto_uri client.post("/accounts") { @@ -187,7 +187,7 @@ class CoreBankAccountsApiTest { "password" to "password" "name" to "Joe" } - }.assertCreated() + }.assertOk() // Reserved account reservedAccounts.forEach { @@ -233,7 +233,7 @@ class CoreBankAccountsApiTest { json(req) { "username" to "foo$it" } - }.assertCreated() + }.assertOk() assertBalance("foo$it", "+KUDOS:100") } assertBalance("admin", "-KUDOS:10000") @@ -261,7 +261,7 @@ class CoreBankAccountsApiTest { "password" to "xyz" "name" to "Mallory" } - }.assertCreated() + }.assertOk() } // DELETE /accounts/USERNAME @@ -286,7 +286,7 @@ class CoreBankAccountsApiTest { "password" to "password" "name" to "John Smith" } - }.assertCreated() + }.assertOk() client.delete("/accounts/john") { pwAuth("admin") }.assertNoContent() @@ -456,7 +456,7 @@ class CoreBankAccountsApiTest { "name" to "Mr $it" "is_public" to (it%2 == 0) } - }.assertCreated() + }.assertOk() } // All public client.get("/public-accounts").run { diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt @@ -275,8 +275,6 @@ suspend fun HttpResponse.assertStatus(status: HttpStatusCode, err: TalerErrorCod } suspend fun HttpResponse.assertOk(): HttpResponse = assertStatus(HttpStatusCode.OK, null) -suspend fun HttpResponse.assertCreated(): HttpResponse - = assertStatus(HttpStatusCode.Created, null) suspend fun HttpResponse.assertNoContent(): HttpResponse = assertStatus(HttpStatusCode.NoContent, null) suspend fun HttpResponse.assertNotFound(err: TalerErrorCode?): HttpResponse diff --git a/integration/test/IntegrationTest.kt b/integration/test/IntegrationTest.kt @@ -98,7 +98,7 @@ class IntegrationTest { "phone" to "+99" } } - }.assertCreated() + }.assertOkJson<RegisterAccountResponse>() // Create exchange client.post("http://0.0.0.0:8080/accounts") { @@ -108,7 +108,7 @@ class IntegrationTest { "name" to "Mr Money" "is_taler_exchange" to true } - }.assertCreated() + }.assertOkJson<RegisterAccountResponse>() // Set conversion rates client.post("http://0.0.0.0:8080/conversion-info/conversion-rate") {