From 8bd11324b467fadd49258548268c85cdaf127097 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 5 Dec 2024 23:16:26 +0000 Subject: Tests transforming AB categories --- .../tests/common/category_matchers.rs | 32 ++++++++++++++++++++-- .../tests/common/category_names.rs | 10 +++++++ 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'rust') 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 bool>> { - todo!() + CATEGORY_NAMES + .iter() + .map(|category_name| -> Box 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, -- cgit v1.2.3