libeufin

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

SyncApiTest.kt (3344B)


      1 /*
      2  * This file is part of LibEuFin.
      3  * Copyright (C) 2025 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.http.*
     21 import io.ktor.server.testing.*
     22 import io.ktor.client.request.*
     23 import io.ktor.client.request.forms.*
     24 import org.junit.Test
     25 import tech.libeufin.common.*
     26 import tech.libeufin.common.test.*
     27 import tech.libeufin.ebics.test.*
     28 import tech.libeufin.ebics.*
     29 import tech.libeufin.ebisync.api.*
     30 import kotlin.test.*
     31 
     32 class SynApiTest {
     33     // GET /config
     34     @Test
     35     fun config() = serverSetup { db, bank ->
     36         client.get("/config").assertOkJson<TalerEbiSyncConfig>()
     37     }
     38 
     39     // GET /submit
     40     @Test
     41     fun orders() = serverSetup { db, bank ->
     42         setMock(sequence {
     43             yield(bank::hkd)
     44             yield(bank::receiptOk)
     45         })
     46         val date = client.get("/submit").assertOkJson<ListSubmitOrders>()
     47         assertContentEquals(date.orders, listOf(
     48             SubmitOrder("BTU-SCT-pain.001", "Direct Debit"),
     49             SubmitOrder("BTU-SCI-DE-pain.001", "Instant Direct Debit"),
     50         ))
     51     }
     52 
     53     // POST /submit
     54     @Test
     55     fun submit() = serverSetup { db, bank ->
     56         client.submitFormWithBinaryData(
     57             url = "/submit",
     58             formData = formData {
     59             }
     60         ).assertBadRequest(TalerErrorCode.GENERIC_PARAMETER_MISSING)
     61         client.submitFormWithBinaryData(
     62             url = "/submit",
     63             formData = formData {
     64                 append("order", "UNKNOWN")
     65             }
     66         ).assertBadRequest(TalerErrorCode.GENERIC_PARAMETER_MISSING)
     67 
     68         setMock(sequence {
     69             yield(bank::hkd)
     70             yield(bank::receiptOk)
     71         })
     72         client.submitFormWithBinaryData(
     73             url = "/submit",
     74             formData = formData {
     75                 append("order", "UNKNOWN")
     76                 append("file", "test", Headers.build {
     77                     append(HttpHeaders.ContentType, "application/xml")
     78                     append(HttpHeaders.ContentDisposition, "filename=\"content.xml\"")
     79                 })
     80             }
     81         ).assertNotFound(TalerErrorCode.END)
     82 
     83         setMock(sequence {
     84             yield(bank::hkd)
     85             yield(bank::receiptOk)
     86             yield(bank::btuInit)
     87             yield(bank::btuPayload)
     88         })
     89         client.submitFormWithBinaryData(
     90             url = "/submit",
     91             formData = formData {
     92                 append("order", "BTU-SCI-DE-pain.001")
     93                 append("file", "test", Headers.build {
     94                     append(HttpHeaders.ContentType, "application/xml")
     95                     append(HttpHeaders.ContentDisposition, "filename=\"content.xml\"")
     96                 })
     97             }
     98         ).assertOkJson<SyncSubmit>()
     99     }
    100 }