taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

api.rs (3987B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2025, 2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   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 Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 use std::sync::Arc;
     18 
     19 use jiff::{Timestamp, Zoned};
     20 use sqlx::PgPool;
     21 use taler_api::{api::TalerRouter as _, auth::AuthMethod, subject::OutgoingSubject};
     22 use taler_common::{
     23     api_revenue::RevenueConfig,
     24     api_wire::{OutgoingHistory, TransferState, WireConfig},
     25     types::{amount::amount, payto::payto},
     26 };
     27 use taler_magnet_bank::{
     28     api::MagnetApi,
     29     constants::CONFIG_SOURCE,
     30     db::{self, TxOutKind},
     31     magnet_api::types::TxStatus,
     32     magnet_payto,
     33 };
     34 use taler_test_utils::{
     35     Router,
     36     db::db_test_setup,
     37     routine::{admin_add_incoming_routine, revenue_routine, routine_pagination, transfer_routine},
     38     server::TestServer,
     39 };
     40 
     41 async fn setup() -> (Router, PgPool) {
     42     let (_, pool) = db_test_setup(CONFIG_SOURCE).await;
     43     let api = Arc::new(
     44         MagnetApi::start(
     45             pool.clone(),
     46             payto("payto://iban/HU02162000031000164800000000?receiver-name=name"),
     47         )
     48         .await,
     49     );
     50     let server = Router::new()
     51         .wire_gateway(api.clone(), AuthMethod::None)
     52         .revenue(api, AuthMethod::None)
     53         .finalize();
     54 
     55     (server, pool)
     56 }
     57 
     58 #[tokio::test]
     59 async fn config() {
     60     let (server, _) = setup().await;
     61     server
     62         .get("/taler-wire-gateway/config")
     63         .await
     64         .assert_ok_json::<WireConfig>();
     65     server
     66         .get("/taler-revenue/config")
     67         .await
     68         .assert_ok_json::<RevenueConfig>();
     69 }
     70 
     71 #[tokio::test]
     72 async fn transfer() {
     73     let (server, _) = setup().await;
     74     transfer_routine(
     75         &server,
     76         TransferState::pending,
     77         &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"),
     78     )
     79     .await;
     80 }
     81 
     82 #[tokio::test]
     83 async fn outgoing_history() {
     84     let (server, pool) = setup().await;
     85     routine_pagination::<OutgoingHistory, _>(
     86         &server,
     87         "/taler-wire-gateway/history/outgoing",
     88         |it| {
     89             it.outgoing_transactions
     90                 .into_iter()
     91                 .map(|it| *it.row_id as i64)
     92                 .collect()
     93         },
     94         async |_, i| {
     95             let mut conn = pool.acquire().await.unwrap();
     96             let now = Zoned::now().date();
     97             db::register_tx_out(
     98                 &mut conn,
     99                 &db::TxOut {
    100                     code: i as u64,
    101                     amount: amount("EUR:10"),
    102                     subject: "subject".to_owned(),
    103                     creditor: magnet_payto(
    104                         "payto://iban/HU30162000031000163100000000?receiver-name=name",
    105                     ),
    106                     value_date: now,
    107                     status: TxStatus::Completed,
    108                 },
    109                 &TxOutKind::Talerable(OutgoingSubject::rand()),
    110                 &Timestamp::now(),
    111             )
    112             .await
    113             .unwrap();
    114         },
    115     )
    116     .await;
    117 }
    118 
    119 #[tokio::test]
    120 async fn admin_add_incoming() {
    121     let (server, _) = setup().await;
    122     admin_add_incoming_routine(
    123         &server,
    124         &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"),
    125         true,
    126     )
    127     .await;
    128 }
    129 
    130 #[tokio::test]
    131 async fn revenue() {
    132     let (server, _) = setup().await;
    133     revenue_routine(
    134         &server,
    135         &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"),
    136         true,
    137     )
    138     .await;
    139 }