diff options
| author | Joe Carstairs <me@joeac.net> | 2024-12-05 23:16:26 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-12-05 23:16:26 +0000 |
| commit | 8bd11324b467fadd49258548268c85cdaf127097 (patch) | |
| tree | 7ddb5c3ec67cdb797e130c23526067282e8188fd /rust | |
| parent | 2d1f57c8398e5291cb6d67281a2aa1d408667390 (diff) | |
Tests transforming AB categories
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs | 32 | ||||
| -rw-r--r-- | rust/actualbudget_to_schist_transformer/tests/common/category_names.rs | 10 |
2 files changed, 40 insertions, 2 deletions
diff --git a/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs index 8a76259..6660add 100644 --- a/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs +++ b/rust/actualbudget_to_schist_transformer/tests/common/category_matchers.rs @@ -1,6 +1,34 @@ -use schist_models::category::Category; +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>> { - todo!() + 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 index b51718c..601f294 100644 --- a/rust/actualbudget_to_schist_transformer/tests/common/category_names.rs +++ b/rust/actualbudget_to_schist_transformer/tests/common/category_names.rs @@ -6,6 +6,16 @@ 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, |
