use firefly_client::client::FireflyClient; use firefly_client::models::{TransactionSplitStore, TransactionStore}; use std::fs; use wiremock::matchers::{header, method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; #[tokio::test] async fn test_search_accounts() { let mock_server = MockServer::start().await; let fixture = fs::read_to_string("tests/fixtures/ff_accounts.json").unwrap(); Mock::given(method("GET")) .and(path("/api/v1/search/accounts")) .and(header("Authorization", "Bearer my-token")) .respond_with(ResponseTemplate::new(200).set_body_string(fixture)) .mount(&mock_server) .await; let client = FireflyClient::new(&mock_server.uri(), "my-token").unwrap(); let accounts = client.search_accounts("NL01").await.unwrap(); assert_eq!(accounts.data.len(), 1); assert_eq!(accounts.data[0].attributes.name, "Checking Account"); assert_eq!( accounts.data[0].attributes.iban.as_deref(), Some("NL01BANK0123456789") ); } #[tokio::test] async fn test_store_transaction() { let mock_server = MockServer::start().await; Mock::given(method("POST")) .and(path("/api/v1/transactions")) .and(header("Authorization", "Bearer my-token")) .respond_with(ResponseTemplate::new(200)) .mount(&mock_server) .await; let client = FireflyClient::new(&mock_server.uri(), "my-token").unwrap(); let tx = TransactionStore { transactions: vec![TransactionSplitStore { transaction_type: "withdrawal".to_string(), date: "2023-01-01".to_string(), amount: "10.00".to_string(), description: "Test".to_string(), source_id: Some("1".to_string()), destination_name: Some("Shop".to_string()), currency_code: None, foreign_amount: None, foreign_currency_code: None, external_id: None, source_name: None, destination_id: None, }], apply_rules: None, fire_webhooks: None, error_if_duplicate_hash: None, }; let result = client.store_transaction(tx).await; assert!(result.is_ok()); }