api.rs (3432B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024-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 axum::http::StatusCode; 18 use common::setup; 19 use taler_common::{ 20 api_common::{HashCode, ShortHashCode}, 21 api_revenue::RevenueConfig, 22 api_wire::{OutgoingHistory, TransferResponse, TransferState, WireConfig}, 23 error_code::ErrorCode, 24 types::{amount::amount, payto::payto, url}, 25 }; 26 use taler_test_utils::{ 27 json, 28 routine::{admin_add_incoming_routine, revenue_routine, routine_pagination, transfer_routine}, 29 server::TestServer as _, 30 }; 31 32 mod common; 33 34 #[tokio::test] 35 async fn errors() { 36 let (server, _) = setup().await; 37 server 38 .get("/unknown") 39 .await 40 .assert_error(ErrorCode::GENERIC_ENDPOINT_UNKNOWN); 41 server 42 .post("/taler-revenue/config") 43 .await 44 .assert_error(ErrorCode::GENERIC_METHOD_INVALID); 45 } 46 47 #[tokio::test] 48 async fn config() { 49 let (server, _) = setup().await; 50 server 51 .get("/taler-wire-gateway/config") 52 .await 53 .assert_ok_json::<WireConfig>(); 54 server 55 .get("/taler-revenue/config") 56 .await 57 .assert_ok_json::<RevenueConfig>(); 58 } 59 60 #[tokio::test] 61 async fn transfer() { 62 let (server, _) = setup().await; 63 transfer_routine(&server, TransferState::success, &payto("payto://test")).await; 64 } 65 66 #[tokio::test] 67 async fn outgoing_history() { 68 let (server, _) = setup().await; 69 routine_pagination::<OutgoingHistory, _>( 70 &server, 71 "/taler-wire-gateway/history/outgoing", 72 |it| { 73 it.outgoing_transactions 74 .into_iter() 75 .map(|it| *it.row_id as i64) 76 .collect() 77 }, 78 |server, i| async move { 79 server 80 .post("/taler-wire-gateway/transfer") 81 .json(&json!({ 82 "request_uid": HashCode::rand(), 83 "amount": amount(&format!("EUR:0.0{i}")), 84 "exchange_base_url": url("http://exchange.taler"), 85 "wtid": ShortHashCode::rand(), 86 "credit_account": url("payto://test"), 87 })) 88 .await 89 .assert_ok_json::<TransferResponse>(); 90 }, 91 ) 92 .await; 93 } 94 95 #[tokio::test] 96 async fn admin_add_incoming() { 97 let (server, _) = setup().await; 98 admin_add_incoming_routine(&server, &payto("payto://test"), true).await; 99 } 100 101 #[tokio::test] 102 async fn revenue() { 103 let (server, _) = setup().await; 104 revenue_routine(&server, &payto("payto://test"), true).await; 105 } 106 107 #[tokio::test] 108 async fn account_check() { 109 let (server, _) = setup().await; 110 server 111 .get("/taler-wire-gateway/account/check") 112 .query("account", "payto://test") 113 .await 114 .assert_status(StatusCode::NOT_IMPLEMENTED); 115 }