PaytoTest.kt (3342B)
1 /* 2 * This file is part of LibEuFin. 3 * Copyright (C) 2024 Taler Systems S.A. 4 5 * LibEuFin is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation; either version 3, or 8 * (at your option) any later version. 9 10 * LibEuFin is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General 13 * Public License for more details. 14 15 * You should have received a copy of the GNU Affero General Public 16 * License along with LibEuFin; see the file COPYING. If not, see 17 * <http://www.gnu.org/licenses/> 18 */ 19 20 import io.ktor.client.request.* 21 import org.junit.Test 22 import tech.libeufin.bank.BankAccountTransactionInfo 23 import tech.libeufin.bank.RegisterAccountResponse 24 import tech.libeufin.bank.TransactionCreateResponse 25 import tech.libeufin.common.* 26 import tech.libeufin.common.test.* 27 import kotlin.test.assertEquals 28 29 class PaytoTest { 30 // x-taler-bank 31 @Test 32 fun xTalerBank() = bankSetup("test_x_taler_bank.conf") { 33 // Check Ok 34 client.post("/accounts") { 35 json { 36 "username" to "john" 37 "password" to "john-password" 38 "name" to "John" 39 } 40 }.assertOkJson<RegisterAccountResponse> { 41 assertEquals("payto://x-taler-bank/localhost/john?receiver-name=John", it.internal_payto_uri) 42 } 43 44 // Bad IBAN payto 45 client.post("/accounts") { 46 json { 47 "username" to "foo" 48 "password" to "foo-password" 49 "name" to "Jane" 50 "payto_uri" to IbanPayto.rand() 51 } 52 }.assertBadRequest() 53 // Bad payto username 54 client.post("/accounts") { 55 json { 56 "username" to "foo" 57 "password" to "foo-password" 58 "name" to "Jane" 59 "payto_uri" to "payto://x-taler-bank/localhost/not-foo" 60 } 61 }.assertBadRequest() 62 // Check Ok 63 client.post("/accounts") { 64 json { 65 "username" to "foo" 66 "password" to "foo-password" 67 "name" to "Jane" 68 "payto_uri" to "payto://x-taler-bank/localhost/foo" 69 } 70 }.assertOkJson<RegisterAccountResponse> { 71 assertEquals("payto://x-taler-bank/localhost/foo?receiver-name=Jane", it.internal_payto_uri) 72 } 73 74 // Check payto canonicalisation 75 client.postA("/accounts/john/transactions") { 76 json { 77 "payto_uri" to "payto://x-taler-bank/ignored/foo?message=payout&amount=KUDOS:0.3" 78 } 79 }.assertOkJson<TransactionCreateResponse> { 80 client.getA("/accounts/john/transactions/${it.row_id}") 81 .assertOkJson<BankAccountTransactionInfo> { tx -> 82 assertEquals("payout", tx.subject) 83 assertEquals("payto://x-taler-bank/localhost/foo?receiver-name=Jane", tx.creditor_payto_uri) 84 assertEquals("payto://x-taler-bank/localhost/john?receiver-name=John", tx.debtor_payto_uri) 85 assertEquals(TalerAmount("KUDOS:0.3"), tx.amount) 86 } 87 } 88 } 89 }