diff options
| author | Joe Carstairs <me@joeac.net> | 2024-11-30 22:50:17 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-11-30 22:51:25 +0000 |
| commit | 48973ceda54950c4da11b131108f642a5df48dce (patch) | |
| tree | 62fa393f8b20967f6bbe7fb75cef87fbbee14f90 /rust/actualbudget_to_schist_transformer/tests/run.rs | |
| parent | 283475af457c71db280fe7732218450a3163614b (diff) | |
Integration test for AB transformer
Diffstat (limited to 'rust/actualbudget_to_schist_transformer/tests/run.rs')
| -rw-r--r-- | rust/actualbudget_to_schist_transformer/tests/run.rs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/rust/actualbudget_to_schist_transformer/tests/run.rs b/rust/actualbudget_to_schist_transformer/tests/run.rs new file mode 100644 index 0000000..3a55812 --- /dev/null +++ b/rust/actualbudget_to_schist_transformer/tests/run.rs @@ -0,0 +1,90 @@ +pub mod common; + +use actualbudget_to_schist_transformer::run::run; +use common::{get_account_matchers, get_account_transfer_matchers, get_budget_drip_matchers, get_category_matchers, get_category_transfer_matchers, get_transaction_categorisation_matchers, get_transaction_matchers, TestContext, TEST_IN_DB_URL, TEST_OUT_DB_URL}; +use diesel::{Connection, SqliteConnection}; +use schist_queries::{account_transfers::get_all_account_transfers, accounts::get_all_accounts, budget_drips::get_all_budget_drips, categories::get_all_categories, category_transfers::get_all_category_transfers, transaction_categorisations::get_all_transaction_categorisations, transactions::get_all_transactions}; + +#[test] +fn given_test_database_when_run_then_exports_expected_schist_state() { + let _context = TestContext::new(); + run(TEST_IN_DB_URL, TEST_OUT_DB_URL).unwrap(); + let connection = &mut SqliteConnection::establish(TEST_OUT_DB_URL).unwrap(); + let accounts = get_all_accounts(connection).unwrap(); + let account_transfers = get_all_account_transfers(connection).unwrap(); + let budget_drips = get_all_budget_drips(connection).unwrap(); + let categories = get_all_categories(connection).unwrap(); + let category_transfers = get_all_category_transfers(connection).unwrap(); + let transactions = get_all_transactions(connection).unwrap(); + let transaction_categorisations = get_all_transaction_categorisations(connection).unwrap(); + + let account_matchers = get_account_matchers(); + assert_eq!(account_matchers.len(), accounts.len()); + for account in accounts { + assert!( + account_matchers.iter().any(|m| m(&account)), + "no match found for account {:?}", + account, + ); + } + + let account_transfer_matchers = get_account_transfer_matchers(); + assert_eq!(account_transfer_matchers.len(), account_transfers.len()); + for account_transfer in account_transfers { + assert!( + account_transfer_matchers.iter().any(|m| m(&account_transfer)), + "no match found for account_transfer {:?}", + account_transfer, + ); + } + + let budget_drip_matchers = get_budget_drip_matchers(); + assert_eq!(budget_drip_matchers.len(), budget_drips.len()); + for budget_drip in budget_drips { + assert!( + budget_drip_matchers.iter().any(|m| m(&budget_drip)), + "no match found for budget_drip {:?}", + budget_drip, + ); + } + + let category_matchers = get_category_matchers(); + assert_eq!(category_matchers.len(), categories.len()); + for category in categories { + assert!( + category_matchers.iter().any(|m| m(&category)), + "no match found for category {:?}", + category, + ); + } + + let category_transfer_matchers = get_category_transfer_matchers(); + assert_eq!(category_transfer_matchers.len(), category_transfers.len()); + for category_transfer in category_transfers { + assert!( + category_transfer_matchers.iter().any(|m| m(&category_transfer)), + "no match found for category_transfer {:?}", + category_transfer, + ); + } + + let transaction_matchers = get_transaction_matchers(); + assert_eq!(transaction_matchers.len(), transactions.len()); + for transaction in transactions { + assert!( + transaction_matchers.iter().any(|m| m(&transaction)), + "no match found for transaction {:?}", + transaction, + ); + } + + let transaction_categorisation_matchers = get_transaction_categorisation_matchers(); + assert_eq!(transaction_categorisation_matchers.len(), transaction_categorisations.len()); + for transaction_categorisation in transaction_categorisations { + assert!( + transaction_categorisation_matchers.iter().any(|m| m(&transaction_categorisation)), + "no match found for transaction_categorisation {:?}", + transaction_categorisation, + ); + } +} |
