api.rs (4121B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2025 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 |_, i| { 95 let acquire = pool.acquire(); 96 async move { 97 let mut conn = acquire.await.unwrap(); 98 let now = Zoned::now().date(); 99 db::register_tx_out( 100 &mut *conn, 101 &db::TxOut { 102 code: i as u64, 103 amount: amount("EUR:10"), 104 subject: "subject".to_owned(), 105 creditor: magnet_payto( 106 "payto://iban/HU30162000031000163100000000?receiver-name=name", 107 ), 108 value_date: now, 109 status: TxStatus::Completed, 110 }, 111 &TxOutKind::Talerable(OutgoingSubject::rand()), 112 &Timestamp::now(), 113 ) 114 .await 115 .unwrap(); 116 } 117 }, 118 ) 119 .await; 120 } 121 122 #[tokio::test] 123 async fn admin_add_incoming() { 124 let (server, _) = setup().await; 125 admin_add_incoming_routine( 126 &server, 127 &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"), 128 true, 129 ) 130 .await; 131 } 132 133 #[tokio::test] 134 async fn revenue() { 135 let (server, _) = setup().await; 136 revenue_routine( 137 &server, 138 &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"), 139 true, 140 ) 141 .await; 142 }