Implement logic

This commit is contained in:
2025-11-19 21:18:37 +00:00
parent a0a7236752
commit c21242d206
31 changed files with 4802 additions and 139 deletions

View File

@@ -0,0 +1,55 @@
use gocardless_client::client::GoCardlessClient;
use gocardless_client::models::TokenResponse;
use wiremock::matchers::{method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
use std::fs;
#[tokio::test]
async fn test_get_transactions_parsing() {
// 1. Setup WireMock
let mock_server = MockServer::start().await;
// Mock Token Endpoint
Mock::given(method("POST"))
.and(path("/api/v2/token/new/"))
.respond_with(ResponseTemplate::new(200).set_body_json(TokenResponse {
access: "fake_access_token".to_string(),
access_expires: 3600,
refresh: Some("fake_refresh".to_string()),
refresh_expires: Some(86400),
}))
.mount(&mock_server)
.await;
// Mock Transactions Endpoint
let fixture = fs::read_to_string("tests/fixtures/gc_transactions.json").unwrap();
Mock::given(method("GET"))
.and(path("/api/v2/accounts/ACC123/transactions/"))
.respond_with(ResponseTemplate::new(200).set_body_string(fixture))
.mount(&mock_server)
.await;
// 2. Run Client
let mut client = GoCardlessClient::new(&mock_server.uri(), "id", "key").unwrap();
client.obtain_access_token().await.unwrap();
let resp = client.get_transactions("ACC123", None, None).await.unwrap();
// 3. Assertions
assert_eq!(resp.transactions.booked.len(), 2);
let tx1 = &resp.transactions.booked[0];
assert_eq!(tx1.transaction_id.as_deref(), Some("TX123"));
assert_eq!(tx1.transaction_amount.amount, "100.00");
assert_eq!(tx1.transaction_amount.currency, "EUR");
let tx2 = &resp.transactions.booked[1];
assert_eq!(tx2.transaction_id.as_deref(), Some("TX124"));
assert_eq!(tx2.transaction_amount.amount, "-10.00");
// Verify Multi-Currency parsing
let exchange = tx2.currency_exchange.as_ref().unwrap();
assert_eq!(exchange[0].source_currency.as_deref(), Some("USD"));
assert_eq!(exchange[0].exchange_rate.as_deref(), Some("1.10"));
}

View File

@@ -0,0 +1,34 @@
{
"transactions": {
"booked": [
{
"transactionId": "TX123",
"bookingDate": "2023-10-01",
"transactionAmount": {
"amount": "100.00",
"currency": "EUR"
},
"debtorName": "John Doe",
"remittanceInformationUnstructured": "Payment for services"
},
{
"transactionId": "TX124",
"bookingDate": "2023-10-02",
"transactionAmount": {
"amount": "-10.00",
"currency": "EUR"
},
"currencyExchange": [
{
"sourceCurrency": "USD",
"exchangeRate": "1.10",
"targetCurrency": "EUR"
}
],
"creditorName": "US Store",
"remittanceInformationUnstructured": "US Purchase"
}
],
"pending": []
}
}