api.rs (4116B)
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_common::ShortHashCode, 24 api_revenue::RevenueConfig, 25 api_wire::{OutgoingHistory, TransferState, WireConfig}, 26 types::{amount::amount, payto::payto, url}, 27 }; 28 use taler_test_utils::{ 29 Router, db_test_setup, 30 routine::{admin_add_incoming_routine, revenue_routine, routine_pagination, transfer_routine}, 31 server::TestServer, 32 }; 33 34 /* 35 36 async fn setup() -> (Router, PgPool) { 37 let pool = db_test_setup(CONFIG_SOURCE).await; 38 let api = Arc::new( 39 MagnetApi::start( 40 pool.clone(), 41 payto("payto://iban/HU02162000031000164800000000?receiver-name=name"), 42 ) 43 .await, 44 ); 45 let server = Router::new() 46 .wire_gateway(api.clone(), AuthMethod::None) 47 .revenue(api, AuthMethod::None) 48 .finalize(); 49 50 (server, pool) 51 } 52 53 #[tokio::test] 54 async fn config() { 55 let (server, _) = setup().await; 56 server 57 .get("/taler-wire-gateway/config") 58 .await 59 .assert_ok_json::<WireConfig>(); 60 server 61 .get("/taler-revenue/config") 62 .await 63 .assert_ok_json::<RevenueConfig>(); 64 } 65 66 #[tokio::test] 67 async fn transfer() { 68 let (server, _) = setup().await; 69 transfer_routine( 70 &server, 71 TransferState::pending, 72 &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"), 73 ) 74 .await; 75 } 76 77 #[tokio::test] 78 async fn outgoing_history() { 79 let (server, pool) = setup().await; 80 routine_pagination::<OutgoingHistory, _>( 81 &server, 82 "/taler-wire-gateway/history/outgoing", 83 |it| { 84 it.outgoing_transactions 85 .into_iter() 86 .map(|it| *it.row_id as i64) 87 .collect() 88 }, 89 |_, i| { 90 let acquire = pool.acquire(); 91 async move { 92 let mut conn = acquire.await.unwrap(); 93 let now = Zoned::now().date(); 94 db::register_tx_out( 95 &mut *conn, 96 &db::TxOut { 97 code: i as u64, 98 amount: amount("EUR:10"), 99 subject: "subject".to_owned(), 100 creditor: magnet_payto( 101 "payto://iban/HU30162000031000163100000000?receiver-name=name", 102 ), 103 value_date: now, 104 status: TxStatus::Completed, 105 }, 106 &TxOutKind::Talerable(OutgoingSubject( 107 ShortHashCode::rand(), 108 url("https://exchange.test"), 109 )), 110 &Timestamp::now(), 111 ) 112 .await 113 .unwrap(); 114 } 115 }, 116 ) 117 .await; 118 } 119 120 #[tokio::test] 121 async fn admin_add_incoming() { 122 let (server, _) = setup().await; 123 admin_add_incoming_routine( 124 &server, 125 &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"), 126 true, 127 ) 128 .await; 129 } 130 131 #[tokio::test] 132 async fn revenue() { 133 let (server, _) = setup().await; 134 revenue_routine( 135 &server, 136 &payto("payto://iban/HU02162000031000164800000000?receiver-name=name"), 137 true, 138 ) 139 .await; 140 } 141 */