diff options
| author | Joe Carstairs <me@joeac.net> | 2024-12-12 08:28:04 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-12-12 08:28:04 +0000 |
| commit | 54894f9de9bad4fecb2a116d59a03cdd003f84c0 (patch) | |
| tree | 6ce5517cecf23d4e93d7a381a374e1fa6c810cee /rust/actualbudget_to_schist_transformer/tests | |
| parent | 8a30bcbdf9264d235bf93da3df8e170cfde53d02 (diff) | |
Moves rust workspace to root
Diffstat (limited to 'rust/actualbudget_to_schist_transformer/tests')
14 files changed, 0 insertions, 845 deletions
diff --git a/rust/actualbudget_to_schist_transformer/tests/common/account_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/account_matchers.rs deleted file mode 100644 index 599f31f..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/account_matchers.rs +++ /dev/null @@ -1,32 +0,0 @@ -use schist_models::account::Account; - -pub fn get_account_matchers() -> Vec<Box<dyn Fn(&Account) -> bool>> { - vec![ - Box::new(|a| matches_bank_account(a)), - Box::new(|a| matches_cash_account(a)), - ] -} - -fn matches_bank_account(account: &Account) -> bool { - match account { - Account { - name, - opening_balance: 0, - opening_date, - .. - } => name == "My bank account" && *opening_date == "2024-08-01".parse().unwrap(), - _ => false, - } -} - -fn matches_cash_account(account: &Account) -> bool { - match account { - Account { - name, - opening_balance: 0, - opening_date, - .. - } => name == "My cash account" && *opening_date == "2024-08-01".parse().unwrap(), - _ => false, - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/common/account_names.rs b/rust/actualbudget_to_schist_transformer/tests/common/account_names.rs deleted file mode 100644 index 1abee4b..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/account_names.rs +++ /dev/null @@ -1,17 +0,0 @@ -pub const ACCOUNT_NAMES: &[&'static str] = &[ - "My bank account", - "My cash account", - "Category transfers", -]; - -pub struct AccountNamesDict { - pub bank_account: &'static str, - pub cash_account: &'static str, - pub transfers_account: &'static str, -} - -pub const ACCOUNT_NAMES_DICT: AccountNamesDict = AccountNamesDict { - bank_account: ACCOUNT_NAMES[0], - cash_account: ACCOUNT_NAMES[1], - transfers_account: ACCOUNT_NAMES[2], -}; diff --git a/rust/actualbudget_to_schist_transformer/tests/common/account_transfer_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/account_transfer_matchers.rs deleted file mode 100644 index ea3180e..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/account_transfer_matchers.rs +++ /dev/null @@ -1,45 +0,0 @@ -use anyhow::Context; -use schist_models::{account::Account, account_transfer::AccountTransfer}; - -use super::ACCOUNT_NAMES_DICT; - -pub fn get_account_transfer_matchers( -) -> Vec<Box<dyn Fn(&AccountTransfer, &[Account]) -> bool>> { - vec![ - Box::new(|at, a| matches_cash_withdrawal_10_sept_2024(at, a)), - ] -} - -fn matches_cash_withdrawal_10_sept_2024( - account_transfer: &AccountTransfer, - accounts: &[Account], -) -> bool { - let bank_account = accounts - .iter() - .filter(|a| a.name == ACCOUNT_NAMES_DICT.bank_account) - .next() - .with_context(|| "failed to find bank account") - .unwrap(); - - let cash_account = accounts - .iter() - .filter(|a| a.name == ACCOUNT_NAMES_DICT.cash_account) - .next() - .with_context(|| "failed to find cash account") - .unwrap(); - - match account_transfer { - AccountTransfer { - id: _id, - date, - description, - quantity: 80_00, - from_account_id, - to_account_id, - } => *date == "2024-09-10".parse().unwrap() - && *description == "" - && *from_account_id == bank_account.id - && *to_account_id == cash_account.id, - _ => false, - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/common/budget_drip_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/budget_drip_matchers.rs deleted file mode 100644 index 04be584..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/budget_drip_matchers.rs +++ /dev/null @@ -1,207 +0,0 @@ -use std::sync::LazyLock; - -use schist_models::{budget_drip::BudgetDrip, category::Category, date_utc::DateUtc}; -use schist_traits::dateable::Dateable; - -use crate::common::category_names::{CATEGORY_NAME_BILLS, CATEGORY_NAME_BILLS_FLEXIBLE, CATEGORY_NAME_FOOD, CATEGORY_NAME_GENERAL, CATEGORY_NAME_SAVINGS}; - -pub fn get_num_expected_budget_drips() -> usize { - let num_expected_dates = DATES.len(); - let num_expected_categories = 5; - num_expected_dates * num_expected_categories -} - -pub fn assert_budget_drip_matches( - budget_drip: &BudgetDrip, - categories: &[Category], -) { - assert!( - DATES.iter().any(|date| *LazyLock::force(date) == budget_drip.date), - "budget drip had unexpected date: {:?}", - budget_drip, - ); - - let category_name = categories - .iter() - .find(|c| c.id == budget_drip.category_id) - .map(|c| c.name.clone()) - .expect(format!( - "budget drip {:?} had unexpected category ID. categories were: {:?}", - budget_drip, - categories, - ).as_str()); - - let expected_quantity = match ( - category_name.as_str(), - budget_drip.date.month(), - budget_drip.date.day(), - ) { - (CATEGORY_NAME_FOOD, 8 | 10, 1) => 6_50, - (CATEGORY_NAME_FOOD, 8 | 10, _) => 6_45, - (CATEGORY_NAME_FOOD, 9 | 11, 1) => 6_86, - (CATEGORY_NAME_FOOD, 9 | 11, _) => 6_66, - (CATEGORY_NAME_FOOD, _, _) => panic!("budget drip {:?} had unexpected date", budget_drip), - - (CATEGORY_NAME_GENERAL, 8 | 10, 1) => 3_40, - (CATEGORY_NAME_GENERAL, 8 | 10, _) => 3_22, - (CATEGORY_NAME_GENERAL, 9 | 11, 1) => 3_43, - (CATEGORY_NAME_GENERAL, 9 | 11, _) => 3_33, - (CATEGORY_NAME_GENERAL, _, _) => panic!("budget drip {:?} had unexpected date", budget_drip), - - (CATEGORY_NAME_BILLS, 8 | 10, 1) => 4_10, - (CATEGORY_NAME_BILLS, 8 | 10, _) => 4_03, - (CATEGORY_NAME_BILLS, 9 | 11, 1) => 4_36, - (CATEGORY_NAME_BILLS, 9 | 11, _) => 4_16, - (CATEGORY_NAME_BILLS, _, _) => panic!("budget drip {:?} had unexpected date", budget_drip), - - (CATEGORY_NAME_BILLS_FLEXIBLE, 8 | 10, 1) => 1_00, - (CATEGORY_NAME_BILLS_FLEXIBLE, 8 | 10, _) => 80, - (CATEGORY_NAME_BILLS_FLEXIBLE, 9 | 11, 1) => 93, - (CATEGORY_NAME_BILLS_FLEXIBLE, 9 | 11, _) => 83, - (CATEGORY_NAME_BILLS_FLEXIBLE, _, _) => panic!("budget drip {:?} had unexpected date", budget_drip), - - (CATEGORY_NAME_SAVINGS, 8 | 10, 1) => 13_00, - (CATEGORY_NAME_SAVINGS, 8 | 10, _) => 12_90, - (CATEGORY_NAME_SAVINGS, 9 | 11, 1) => 13_43, - (CATEGORY_NAME_SAVINGS, 9 | 11, _) => 13_33, - (CATEGORY_NAME_SAVINGS, _, _) => panic!("budget drip {:?} had unexpected date", budget_drip), - - (_, _, _) => panic!( - "budget drip {:?} had unexpected category name {}", - budget_drip, - category_name, - ), - }; - - assert_eq!( - expected_quantity, - budget_drip.quantity, - "budget drip {:?} had unexpected quantity", - budget_drip, - ); -} - -static DATES: [LazyLock<DateUtc>; 122] = [ - LazyLock::<DateUtc>::new(|| "2024-08-01".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-02".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-03".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-04".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-05".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-06".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-07".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-08".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-09".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-10".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-11".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-12".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-13".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-14".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-15".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-16".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-17".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-18".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-19".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-20".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-21".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-22".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-23".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-24".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-25".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-26".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-27".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-28".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-29".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-30".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-08-31".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-01".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-02".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-03".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-04".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-05".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-06".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-07".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-08".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-09".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-10".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-11".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-12".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-13".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-14".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-15".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-16".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-17".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-18".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-19".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-20".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-21".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-22".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-23".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-24".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-25".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-26".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-27".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-28".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-29".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-09-30".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-01".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-02".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-03".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-04".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-05".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-06".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-07".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-08".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-09".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-10".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-11".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-12".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-13".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-14".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-15".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-16".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-17".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-18".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-19".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-20".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-21".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-22".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-23".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-24".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-25".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-26".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-27".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-28".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-29".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-30".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-10-31".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-01".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-02".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-03".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-04".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-05".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-06".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-07".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-08".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-09".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-10".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-11".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-12".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-13".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-14".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-15".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-16".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-17".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-18".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-19".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-20".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-21".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-22".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-23".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-24".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-25".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-26".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-27".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-28".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-29".parse().unwrap()), - LazyLock::<DateUtc>::new(|| "2024-11-30".parse().unwrap()), -]; diff --git a/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs deleted file mode 100644 index 6660add..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs +++ /dev/null @@ -1,34 +0,0 @@ -use schist_models::{budget_period_unit::BudgetPeriodUnit, category::Category}; - -use super::category_names::{CATEGORY_NAMES, CATEGORY_NAME_BILLS, CATEGORY_NAME_BILLS_FLEXIBLE, CATEGORY_NAME_FOOD, CATEGORY_NAME_GENERAL, CATEGORY_NAME_INCOME, CATEGORY_NAME_SAVINGS, CATEGORY_NAME_STARTING_BALANCES}; - -pub fn get_category_matchers( -) -> Vec<Box<dyn Fn(&Category) -> bool>> { - CATEGORY_NAMES - .iter() - .map(|category_name| -> Box<dyn Fn(&Category) -> bool> { - Box::new(|c| matches_category(c, category_name)) - }).collect() -} - -fn matches_category(category: &Category, category_name: &str,) -> bool { - category.name == category_name - && category.balance == 0 - && category.balance_date < "2024-08-01".parse().unwrap() - && category.budget_period == 1 - && category.budget_period_unit == BudgetPeriodUnit::Month - && category.budget_quantity == get_expected_budget_quantity(category_name) -} - -fn get_expected_budget_quantity(category_name: &str) -> i32 { - match category_name { - CATEGORY_NAME_FOOD => 200_00, - CATEGORY_NAME_GENERAL => 100_00, - CATEGORY_NAME_BILLS => 125_00, - CATEGORY_NAME_BILLS_FLEXIBLE => 25_00, - CATEGORY_NAME_SAVINGS => 400_00, - CATEGORY_NAME_STARTING_BALANCES => 0, - CATEGORY_NAME_INCOME => 0, - _ => panic!("unexpected category name {}", category_name), - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/common/category_names.rs b/rust/actualbudget_to_schist_transformer/tests/common/category_names.rs deleted file mode 100644 index 601f294..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/category_names.rs +++ /dev/null @@ -1,37 +0,0 @@ -pub const CATEGORY_NAME_FOOD: &str = "Food"; -pub const CATEGORY_NAME_GENERAL: &str = "General"; -pub const CATEGORY_NAME_BILLS: &str = "Bills"; -pub const CATEGORY_NAME_BILLS_FLEXIBLE: &str = "Bills (Flexible)"; -pub const CATEGORY_NAME_SAVINGS: &str = "Savings"; -pub const CATEGORY_NAME_STARTING_BALANCES: &str = "Starting Balances"; -pub const CATEGORY_NAME_INCOME: &str = "Income"; - -pub const CATEGORY_NAMES: &[&'static str] = &[ - CATEGORY_NAME_FOOD, - CATEGORY_NAME_GENERAL, - CATEGORY_NAME_BILLS, - CATEGORY_NAME_BILLS_FLEXIBLE, - CATEGORY_NAME_SAVINGS, - CATEGORY_NAME_STARTING_BALANCES, - CATEGORY_NAME_INCOME, -]; - -pub struct CategoryNamesDict { - pub food: &'static str, - pub general: &'static str, - pub bills: &'static str, - pub bills_flexible: &'static str, - pub savings: &'static str, - pub starting_balances: &'static str, - pub income: &'static str, -} - -pub const CATEGORY_NAMES_DICT: CategoryNamesDict = CategoryNamesDict { - food: CATEGORY_NAME_FOOD, - general: CATEGORY_NAME_GENERAL, - bills: CATEGORY_NAME_BILLS, - bills_flexible: CATEGORY_NAME_BILLS_FLEXIBLE, - savings: CATEGORY_NAME_SAVINGS, - starting_balances: CATEGORY_NAME_STARTING_BALANCES, - income: CATEGORY_NAME_INCOME, -}; diff --git a/rust/actualbudget_to_schist_transformer/tests/common/category_transfer_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/category_transfer_matchers.rs deleted file mode 100644 index 6d11c8a..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/category_transfer_matchers.rs +++ /dev/null @@ -1,38 +0,0 @@ -use schist_models::{category::Category, category_transfer::CategoryTransfer}; - -use super::category_names::{CATEGORY_NAME_GENERAL, CATEGORY_NAME_SAVINGS}; - -pub fn get_category_transfer_matchers( -) -> Vec<Box<dyn Fn(&CategoryTransfer, &[Category]) -> bool>> { - vec![ - Box::new(|ct, c| matches_120_savings_to_general_23_oct_2024(ct, c)), - ] -} - -fn matches_120_savings_to_general_23_oct_2024( - category_transfer: &CategoryTransfer, - categories: &[Category], -) -> bool { - let savings_category = categories - .iter() - .find(|c| c.name == CATEGORY_NAME_SAVINGS) - .expect("failed to find savings category"); - - let general_category = categories - .iter() - .find(|c| c.name == CATEGORY_NAME_GENERAL) - .expect("failed to find general category"); - - match category_transfer { - CategoryTransfer { - id: _id, - description, - quantity: 120_00, - from_category_id, - to_category_id, - } => *from_category_id == savings_category.id - && *to_category_id == general_category.id - && description.as_str() == "", - _ => false, - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/common/db_url.rs b/rust/actualbudget_to_schist_transformer/tests/common/db_url.rs deleted file mode 100644 index 9cd8e39..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/db_url.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub const TEST_IN_DB_URL: &str = "tests/resources/actualbudget_test_db.sqlite"; -pub const TEST_OUT_DB_URL: &str = "tests/resources/.schist_test_out_db.sqlite"; diff --git a/rust/actualbudget_to_schist_transformer/tests/common/mod.rs b/rust/actualbudget_to_schist_transformer/tests/common/mod.rs deleted file mode 100644 index c67f62e..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -mod account_matchers; -mod account_names; -mod account_transfer_matchers; -mod budget_drip_matchers; -mod category_matchers; -mod category_names; -mod category_transfer_matchers; -mod db_url; -mod test_context; -mod transaction_matchers; -mod transaction_categorisation_matchers; - -pub use account_matchers::get_account_matchers; -pub use account_names::ACCOUNT_NAMES_DICT; -pub use account_transfer_matchers::get_account_transfer_matchers; -pub use budget_drip_matchers::assert_budget_drip_matches; -pub use budget_drip_matchers::get_num_expected_budget_drips; -pub use category_names::CATEGORY_NAMES_DICT; -pub use category_matchers::get_category_matchers; -pub use category_transfer_matchers::get_category_transfer_matchers; -pub use db_url::TEST_IN_DB_URL; -pub use db_url::TEST_OUT_DB_URL; -pub use test_context::TestContext; -pub use transaction_matchers::get_transaction_matchers; -pub use transaction_matchers::matches_bank_account_initial_transaction; -pub use transaction_matchers::matches_cash_account_initial_transaction; -pub use transaction_matchers::matches_food_transaction; -pub use transaction_matchers::matches_income_transaction; -pub use transaction_categorisation_matchers::get_transaction_categorisation_matchers; diff --git a/rust/actualbudget_to_schist_transformer/tests/common/test_context.rs b/rust/actualbudget_to_schist_transformer/tests/common/test_context.rs deleted file mode 100644 index e59c5f8..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/test_context.rs +++ /dev/null @@ -1,42 +0,0 @@ -use anyhow::Context; -use diesel::{Connection, SqliteConnection}; -use diesel_migrations::MigrationHarness; -use schist_queries::clear::clear; -use schist_models::migrations::MIGRATIONS; - -use super::{TEST_IN_DB_URL, TEST_OUT_DB_URL}; - -pub struct TestContext { -} - -impl TestContext { - pub fn new() -> Self { - let _in_connection = &mut SqliteConnection - ::establish(&TEST_IN_DB_URL) - .with_context(|| format!("failed to establish connection to in database at {}", TEST_IN_DB_URL)) - .unwrap(); - - let out_connection = &mut SqliteConnection - ::establish(&TEST_OUT_DB_URL) - .with_context(|| format!("failed to establish connection to out database at {}", TEST_OUT_DB_URL)) - .unwrap(); - - out_connection - .run_pending_migrations(MIGRATIONS) - .expect("failed to run migrations on out database"); - - clear(out_connection) - .expect("failed to clear database"); - - Self { - } - } -} - -impl Drop for TestContext { - fn drop(&mut self) { - std::fs::remove_file(&TEST_OUT_DB_URL) - .with_context(|| format!("failed to delete out database at {}", TEST_OUT_DB_URL)) - .unwrap(); - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/common/transaction_categorisation_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/transaction_categorisation_matchers.rs deleted file mode 100644 index 04ce6a7..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/transaction_categorisation_matchers.rs +++ /dev/null @@ -1,141 +0,0 @@ -use schist_models::{account::Account, category::Category, transaction::Transaction, transaction_categorisation::TransactionCategorisation}; - -use super::{category_names::{CATEGORY_NAME_FOOD, CATEGORY_NAME_INCOME, CATEGORY_NAME_STARTING_BALANCES}, matches_bank_account_initial_transaction, matches_cash_account_initial_transaction, matches_food_transaction, matches_income_transaction}; - -pub fn get_transaction_categorisation_matchers( -) -> Vec<Box<dyn Fn(&TransactionCategorisation, &[Transaction], &[Category], &[Account]) -> bool>> { - vec![ - Box::new(|tc, t, c, a| matches_bank_account_initial_transaction_categorisation(tc, t, c, a)), - Box::new(|tc, t, c, a| matches_cash_account_initial_transaction_categorisation(tc, t, c, a)), - Box::new(|tc, t, c, a| matches_income_transaction_categorisation(tc, t, c, a, "08")), - Box::new(|tc, t, c, a| matches_income_transaction_categorisation(tc, t, c, a, "09")), - Box::new(|tc, t, c, a| matches_income_transaction_categorisation(tc, t, c, a, "10")), - Box::new(|tc, t, c, a| matches_income_transaction_categorisation(tc, t, c, a, "11")), - Box::new(|tc, t, c, a| matches_food_transaction_categorisation(tc, t, c, a, "08")), - Box::new(|tc, t, c, a| matches_food_transaction_categorisation(tc, t, c, a, "09")), - Box::new(|tc, t, c, a| matches_food_transaction_categorisation(tc, t, c, a, "10")), - Box::new(|tc, t, c, a| matches_food_transaction_categorisation(tc, t, c, a, "11")), - ] -} - -fn matches_bank_account_initial_transaction_categorisation( - transaction_categorisation: &TransactionCategorisation, - transactions: &[Transaction], - categories: &[Category], - accounts: &[Account], -) -> bool { - let bank_account_initial_transaction = transactions - .iter() - .find(|t| matches_bank_account_initial_transaction(t, accounts)) - .expect("failed to find bank account initial transaction"); - - let starting_balance_category = categories - .iter() - .find(|c| c.name == CATEGORY_NAME_STARTING_BALANCES) - .expect("failed to find starting balance category"); - - match transaction_categorisation { - TransactionCategorisation { - id: _id, - description, - quantity: 1200_00, - transaction_id, - category_id, - } => description == "" - && *transaction_id == bank_account_initial_transaction.id - && *category_id == starting_balance_category.id, - _ => false, - } -} - -fn matches_cash_account_initial_transaction_categorisation( - transaction_categorisation: &TransactionCategorisation, - transactions: &[Transaction], - categories: &[Category], - accounts: &[Account], -) -> bool { - let cash_account_initial_transaction = transactions - .iter() - .find(|t| matches_cash_account_initial_transaction(t, accounts)) - .expect("failed to find cash account initial transaction"); - - let starting_balance_category = categories - .iter() - .find(|c| c.name == CATEGORY_NAME_STARTING_BALANCES) - .expect("failed to find starting balance category"); - - match transaction_categorisation { - TransactionCategorisation { - id: _id, - description, - quantity: 45_10, - transaction_id, - category_id, - } => description == "" - && *transaction_id == cash_account_initial_transaction.id - && *category_id == starting_balance_category.id, - _ => false, - } -} - -fn matches_income_transaction_categorisation( - transaction_categorisation: &TransactionCategorisation, - transactions: &[Transaction], - categories: &[Category], - accounts: &[Account], - month: &str, -) -> bool { - let income_transaction = transactions - .iter() - .find(|t| matches_income_transaction(t, accounts, month)) - .expect(format!("failed to find income transaction for month {}", month).as_str()); - - let income_category = categories - .iter() - .find(|c| c.name == CATEGORY_NAME_INCOME) - .expect("failed to find income category"); - - match transaction_categorisation { - TransactionCategorisation { - id: _id, - description, - quantity: 846_46, - transaction_id, - category_id, - } => description == "" - && *transaction_id == income_transaction.id - && *category_id == income_category.id, - _ => false, - } -} - -fn matches_food_transaction_categorisation( - transaction_categorisation: &TransactionCategorisation, - transactions: &[Transaction], - categories: &[Category], - accounts: &[Account], - month: &str, -) -> bool { - let food_transaction = transactions - .iter() - .find(|t| matches_food_transaction(t, accounts, month)) - .expect(format!("failed to find food transaction for month {}", month).as_str()); - - let food_category = categories - .iter() - .find(|c| c.name == CATEGORY_NAME_FOOD) - .expect("failed to find food category"); - - match transaction_categorisation { - TransactionCategorisation { - id: _id, - description, - quantity: -200_00, - transaction_id, - category_id, - } => description == "" - && *transaction_id == food_transaction.id - && *category_id == food_category.id, - _ => false, - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs deleted file mode 100644 index c3763c1..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs +++ /dev/null @@ -1,130 +0,0 @@ -use schist_models::{account::Account, transaction::Transaction}; - -use super::ACCOUNT_NAMES_DICT; - -pub fn get_transaction_matchers( -) -> Vec<Box<dyn Fn(&Transaction, &[Account]) -> bool>> { - vec![ - Box::new(|t, a| matches_bank_account_initial_transaction(t, a)), - Box::new(|t, a| matches_cash_account_initial_transaction(t, a)), - Box::new(|t, a| matches_income_transaction(t, a, "08")), - Box::new(|t, a| matches_income_transaction(t, a, "09")), - Box::new(|t, a| matches_income_transaction(t, a, "10")), - Box::new(|t, a| matches_income_transaction(t, a, "11")), - Box::new(|t, a| matches_food_transaction(t, a, "08")), - Box::new(|t, a| matches_food_transaction(t, a, "09")), - Box::new(|t, a| matches_food_transaction(t, a, "10")), - Box::new(|t, a| matches_food_transaction(t, a, "11")), - ] -} - -pub fn matches_bank_account_initial_transaction( - t: &Transaction, - accounts: &[Account], -) -> bool { - let bank_account_id = accounts - .iter() - .find(|a| a.name == ACCOUNT_NAMES_DICT.bank_account) - .expect("failed to find bank account") - .id - .clone(); - - match t { - Transaction { - account_id, - date, - id: _id, - description, - payee, - quantity: 1200_00, - } => *account_id == bank_account_id - && *date == "2024-08-01".parse().unwrap() - && description == "" - && payee == "Starting Balance", - _ => false, - } -} - -pub fn matches_cash_account_initial_transaction( - t: &Transaction, - accounts: &[Account], -) -> bool { - let bank_account_id = accounts - .iter() - .find(|a| a.name == ACCOUNT_NAMES_DICT.cash_account) - .expect("failed to find cash account") - .id - .clone(); - - match t { - Transaction { - account_id, - date, - id: _id, - description, - payee, - quantity: 45_10, - } => *account_id == bank_account_id - && *date == "2024-08-01".parse().unwrap() - && description == "" - && payee == "Starting Balance", - _ => false, - } -} - -pub fn matches_income_transaction( - t: &Transaction, - accounts: &[Account], - month: &str, -) -> bool { - let bank_account_id = accounts - .iter() - .find(|a| a.name == ACCOUNT_NAMES_DICT.bank_account) - .expect("failed to find bank account") - .id - .clone(); - - match t { - Transaction { - account_id, - date, - description, - id: _id, - payee, - quantity: 846_46, - } => - *account_id == bank_account_id - && *date == format!("2024-{}-21", month).parse().unwrap() - && description == "Salary" - && payee == "Employer Ltd", - _ => false, - } -} - -pub fn matches_food_transaction( - t: &Transaction, - accounts: &[Account], - month: &str, -) -> bool { - let bank_account_id = accounts - .iter() - .find(|a| a.name == ACCOUNT_NAMES_DICT.bank_account) - .expect("failed to find bank account") - .id - .clone(); - - match t { - Transaction { - account_id, - date, - description, - id: _id, - payee, - quantity: -200_00, - } => *account_id == bank_account_id - && *date == format!("2024-{}-08", month).parse().unwrap() - && description == "" - && payee == "Tesco", - _ => false, - } -} diff --git a/rust/actualbudget_to_schist_transformer/tests/resources/actualbudget_test_db.sqlite b/rust/actualbudget_to_schist_transformer/tests/resources/actualbudget_test_db.sqlite deleted file mode 120000 index f8d3f5d..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/resources/actualbudget_test_db.sqlite +++ /dev/null @@ -1 +0,0 @@ -../../../actualbudget_queries/tests/resources/actualbudget_test_db.sqlite
\ No newline at end of file diff --git a/rust/actualbudget_to_schist_transformer/tests/run.rs b/rust/actualbudget_to_schist_transformer/tests/run.rs deleted file mode 100644 index e882dc5..0000000 --- a/rust/actualbudget_to_schist_transformer/tests/run.rs +++ /dev/null @@ -1,90 +0,0 @@ -pub mod common; - -use actualbudget_to_schist_transformer::run::run; -use common::{assert_budget_drip_matches, get_account_matchers, get_account_transfer_matchers, get_category_matchers, get_category_transfer_matchers, get_num_expected_budget_drips, 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, &accounts)), - "no match found for account_transfer {:?}", - account_transfer, - ); - } - - assert_eq!(get_num_expected_budget_drips(), budget_drips.len()); - for budget_drip in budget_drips { - assert_budget_drip_matches(&budget_drip, &categories); - } - - let category_matchers = get_category_matchers(); - assert_eq!(category_matchers.len(), categories.len()); - for category in categories.clone() { - 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, &categories)), - "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.clone() { - assert!( - transaction_matchers.iter().any(|m| m(&transaction, &accounts)), - "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, - &transactions, - &categories, - &accounts, - )), - "no match found for transaction_categorisation {:?}", - transaction_categorisation, - ); - } -} |
