Implement logic
This commit is contained in:
62
firefly-client/tests/client_test.rs
Normal file
62
firefly-client/tests/client_test.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use firefly_client::client::FireflyClient;
|
||||
use firefly_client::models::{TransactionStore, TransactionSplitStore};
|
||||
use wiremock::matchers::{method, path, header};
|
||||
use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
use std::fs;
|
||||
|
||||
#[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());
|
||||
}
|
||||
22
firefly-client/tests/fixtures/ff_accounts.json
vendored
Normal file
22
firefly-client/tests/fixtures/ff_accounts.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"type": "accounts",
|
||||
"id": "2",
|
||||
"attributes": {
|
||||
"name": "Checking Account",
|
||||
"type": "asset",
|
||||
"iban": "NL01BANK0123456789"
|
||||
}
|
||||
}
|
||||
],
|
||||
"meta": {
|
||||
"pagination": {
|
||||
"total": 1,
|
||||
"count": 1,
|
||||
"per_page": 20,
|
||||
"current_page": 1,
|
||||
"total_pages": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user