taler-rust

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

api.rs (4127B)


      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::{str::FromStr, sync::Arc};
     18 
     19 use compact_str::CompactString;
     20 use jiff::Timestamp;
     21 use sqlx::PgPool;
     22 use taler_api::{api::TalerRouter as _, auth::AuthMethod, subject::OutgoingSubject};
     23 use taler_common::{
     24     api_revenue::RevenueConfig,
     25     api_wire::{OutgoingHistory, TransferState, WireConfig},
     26     types::{
     27         amount::{Currency, decimal},
     28         payto::payto,
     29     },
     30 };
     31 use taler_cyclos::{
     32     api::CyclosApi,
     33     constants::CONFIG_SOURCE,
     34     db::{self, TxOutKind},
     35 };
     36 use taler_test_utils::{
     37     Router,
     38     db::db_test_setup,
     39     routine::{admin_add_incoming_routine, revenue_routine, routine_pagination, transfer_routine},
     40     server::TestServer,
     41 };
     42 
     43 async fn setup() -> (Router, PgPool) {
     44     let (_, pool) = db_test_setup(CONFIG_SOURCE).await;
     45     let api = Arc::new(
     46         CyclosApi::start(
     47             pool.clone(),
     48             CompactString::const_new("localhost"),
     49             payto("payto://iban/HU02162000031000164800000000?receiver-name=name"),
     50             Currency::from_str("TEST").unwrap(),
     51         )
     52         .await,
     53     );
     54     let server = Router::new()
     55         .wire_gateway(api.clone(), AuthMethod::None)
     56         .revenue(api, AuthMethod::None)
     57         .finalize();
     58 
     59     (server, pool)
     60 }
     61 
     62 #[tokio::test]
     63 async fn config() {
     64     let (server, _) = setup().await;
     65     server
     66         .get("/taler-wire-gateway/config")
     67         .await
     68         .assert_ok_json::<WireConfig>();
     69     server
     70         .get("/taler-revenue/config")
     71         .await
     72         .assert_ok_json::<RevenueConfig>();
     73 }
     74 
     75 #[tokio::test]
     76 async fn transfer() {
     77     let (server, _) = setup().await;
     78     transfer_routine(
     79         &server,
     80         TransferState::pending,
     81         &payto("payto://cyclos/localhost/7762070814178012479?receiver-name=name"),
     82     )
     83     .await;
     84 }
     85 
     86 #[tokio::test]
     87 async fn outgoing_history() {
     88     let (server, pool) = setup().await;
     89     routine_pagination::<OutgoingHistory, _>(
     90         &server,
     91         "/taler-wire-gateway/history/outgoing",
     92         |it| {
     93             it.outgoing_transactions
     94                 .into_iter()
     95                 .map(|it| *it.row_id as i64)
     96                 .collect()
     97         },
     98         async |_, i| {
     99             db::register_tx_out(
    100                 &mut pool.acquire().await.unwrap(),
    101                 &db::TxOut {
    102                     transfer_id: i as i64,
    103                     tx_id: if i % 2 == 0 {
    104                         Some((i % 2) as i64)
    105                     } else {
    106                         None
    107                     },
    108                     amount: decimal("10"),
    109                     subject: "subject".to_owned(),
    110                     creditor_id: 31000163100000000,
    111                     creditor_name: "Name".to_string(),
    112                     valued_at: Timestamp::now(),
    113                 },
    114                 &TxOutKind::Talerable(OutgoingSubject::rand()),
    115                 &Timestamp::now(),
    116             )
    117             .await
    118             .unwrap();
    119         },
    120     )
    121     .await;
    122 }
    123 
    124 #[tokio::test]
    125 async fn admin_add_incoming() {
    126     let (server, _) = setup().await;
    127     admin_add_incoming_routine(
    128         &server,
    129         &payto("payto://cyclos/localhost/7762070814178012479?receiver-name=name"),
    130         true,
    131     )
    132     .await;
    133 }
    134 
    135 #[tokio::test]
    136 async fn revenue() {
    137     let (server, _) = setup().await;
    138     revenue_routine(
    139         &server,
    140         &payto("payto://cyclos/localhost/7762070814178012479?receiver-name=name"),
    141         true,
    142     )
    143     .await;
    144 }