taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

WalletResponseTest.kt (2753B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2020 Taler Systems S.A.
      4  *
      5  * GNU Taler is free software; you can redistribute it and/or modify it under the
      6  * terms of the GNU General Public License as published by the Free Software
      7  * Foundation; either version 3, or (at your option) any later version.
      8  *
      9  * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License along with
     14  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 
     17 package net.taler.wallet.backend
     18 
     19 import kotlinx.serialization.json.Json
     20 import net.taler.wallet.balances.BalanceResponse
     21 import org.junit.Assert.assertEquals
     22 import org.junit.Test
     23 
     24 class WalletResponseTest {
     25 
     26     private val json = Json {
     27         ignoreUnknownKeys = true
     28     }
     29 
     30     @Test
     31     fun testBalanceResponse() {
     32         val serializer = WalletResponse.Success.serializer(BalanceResponse.serializer())
     33         val response = json.decodeFromString(
     34             serializer, """
     35             {
     36               "type": "response",
     37               "operation": "getBalances",
     38               "id": 2,
     39               "result": {
     40                 "balances": [
     41                   {
     42                     "scopeInfo": {
     43                       "currency": "TESTKUDOS",
     44                       "type": "exchange",
     45                       "url": "https://exchange.test.taler.net/"
     46                     },
     47                     "available": "TESTKUDOS:15.8",
     48                     "pendingIncoming": "TESTKUDOS:0",
     49                     "pendingOutgoing": "TESTKUDOS:0",
     50                     "hasPendingTransactions": false,
     51                     "requiresUserInput": false,
     52                     "disablePeerPayments": false
     53                   }
     54                 ]
     55               }
     56             }
     57         """.trimIndent()
     58         )
     59         assertEquals(1, response.result.balances.size)
     60     }
     61 
     62     @Test
     63     fun testWalletErrorInfo() {
     64         val infoJson = """
     65             {
     66                 "code":7001,
     67                 "hint":"Error: WALLET_UNEXPECTED_EXCEPTION",
     68                 "details":{
     69                   "httpStatusCode": 401,
     70                   "requestUrl": "https:\/\/backend.demo.taler.net\/-\/FSF\/orders\/2020.224-02XC8W52BHH3G\/claim",
     71                   "requestMethod": "POST"
     72                 },
     73                 "message":"unexpected exception: Error: BUG: invariant violation (purchase status)"
     74             }
     75         """.trimIndent()
     76         val info = json.decodeFromString(TalerErrorInfo.serializer(), infoJson)
     77         println(info.userFacingMsg)
     78     }
     79 }