summaryrefslogtreecommitdiff
path: root/actualbudget_queries/tests/common/transaction_matchers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'actualbudget_queries/tests/common/transaction_matchers.rs')
-rw-r--r--actualbudget_queries/tests/common/transaction_matchers.rs315
1 files changed, 0 insertions, 315 deletions
diff --git a/actualbudget_queries/tests/common/transaction_matchers.rs b/actualbudget_queries/tests/common/transaction_matchers.rs
deleted file mode 100644
index 2620da5..0000000
--- a/actualbudget_queries/tests/common/transaction_matchers.rs
+++ /dev/null
@@ -1,315 +0,0 @@
-use std::collections::HashMap;
-
-use actualbudget_models::{ActualbudgetAccount, ActualbudgetCategory, ActualbudgetTransaction};
-
-use super::{account_names::ACCOUNT_NAMES_DICT, category_names::CATEGORY_NAMES_DICT};
-
-pub fn get_transaction_matchers() -> Vec<Box<dyn Fn(&ActualbudgetTransaction, &HashMap<String, ActualbudgetAccount>, &HashMap<String, ActualbudgetCategory>) -> bool>> {
- vec![
- Box::new(|t, a, c| matches_bank_account_initial_transaction(t, a, c)),
- Box::new(|t, a, c| matches_cash_account_initial_transaction(t, a, c)),
- Box::new(|t, a, c| matches_income_transaction(t, a, c, "08")),
- Box::new(|t, a, c| matches_income_transaction(t, a, c, "09")),
- Box::new(|t, a, c| matches_income_transaction(t, a, c, "10")),
- Box::new(|t, a, c| matches_income_transaction(t, a, c, "11")),
- Box::new(|t, a, c| matches_food_transaction(t, a, c, "08")),
- Box::new(|t, a, c| matches_food_transaction(t, a, c, "09")),
- Box::new(|t, a, c| matches_food_transaction(t, a, c, "10")),
- Box::new(|t, a, c| matches_food_transaction(t, a, c, "11")),
- Box::new(|t, a, c| matches_category_transfer_parent_transaction(t, a, c)),
- Box::new(|t, a, c| matches_category_transfer_child_out_transaction(t, a, c)),
- Box::new(|t, a, c| matches_category_transfer_child_in_transaction(t, a, c)),
- Box::new(|t, a, c| matches_account_transfer_out_transaction(t, a, c)),
- Box::new(|t, a, c| matches_account_transfer_in_transaction(t, a, c)),
- ]
-}
-
-fn matches_bank_account_initial_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let bank_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.bank_account)
- .expect("failed to find bank account")
- .id
- .clone();
-
- let starting_balances_category_id = categories
- .get(CATEGORY_NAMES_DICT.starting_balances)
- .expect("failed to find starting balances category")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: false,
- parent_id: None,
- account_id,
- category_id: Some(category_id),
- amount: 1200_00,
- date,
- ..
- } => *account_id == bank_account_id
- && *category_id == starting_balances_category_id
- && date.to_iso().get(0..10) == Some("2024-08-01"),
- _ => false,
- }
-}
-
-fn matches_cash_account_initial_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let bank_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.cash_account)
- .expect("failed to find cash account")
- .id
- .clone();
-
- let starting_balances_category_id = categories
- .get(CATEGORY_NAMES_DICT.starting_balances)
- .expect("failed to find starting balances category")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: false,
- parent_id: None,
- account_id,
- category_id: Some(category_id),
- amount: 45_10,
- date,
- ..
- } => *account_id == bank_account_id
- && *category_id == starting_balances_category_id
- && date.to_iso().get(0..10) == Some("2024-08-01"),
- _ => false,
- }
-}
-
-fn matches_income_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- categories: &HashMap<String, ActualbudgetCategory>,
- month: &str,
-) -> bool {
- let bank_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.bank_account)
- .expect("failed to find bank account")
- .id
- .clone();
-
- let income_category_id = categories
- .get(CATEGORY_NAMES_DICT.income)
- .expect("failed to find income category")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: false,
- parent_id: None,
- account_id,
- category_id,
- amount: 846_46,
- date,
- notes: Some(notes),
- ..
- } =>
- *account_id == bank_account_id
- && *category_id == Some(income_category_id)
- && date.to_iso().get(0..10) == Some(format!("2024-{}-21", month).as_str())
- && *notes == String::from("Salary"),
- _ => false,
- }
-}
-
-fn matches_food_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- categories: &HashMap<String, ActualbudgetCategory>,
- month: &str,
-) -> bool {
- let bank_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.bank_account)
- .expect("failed to find bank account")
- .id
- .clone();
-
- let income_category_id = categories
- .get(CATEGORY_NAMES_DICT.food)
- .expect("failed to find food category")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: false,
- parent_id: None,
- account_id,
- category_id,
- amount: -200_00,
- date,
- ..
- } => *account_id == bank_account_id
- && *category_id == Some(income_category_id)
- && date.to_iso().get(0..10) == Some(format!("2024-{}-08", month).as_str()),
- _ => false,
- }
-}
-
-fn matches_category_transfer_parent_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- _categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let category_transfers_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.transfers_account)
- .expect("failed to find transfers account")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: true,
- is_child: false,
- parent_id: None,
- account_id,
- category_id: None,
- amount: 0,
- date,
- ..
- } => *account_id == category_transfers_account_id
- && date.to_iso().get(0..10) == Some("2024-10-23"),
- _ => false,
- }
-}
-
-fn matches_category_transfer_child_out_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let category_transfers_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.transfers_account)
- .expect("failed to find transfers account")
- .id
- .clone();
-
- let savings_category_id = categories
- .get(CATEGORY_NAMES_DICT.savings)
- .expect("failed to find savings category")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: true,
- parent_id: Some(_),
- account_id,
- category_id: Some(category_id),
- amount: -120_00,
- date,
- ..
- } => *account_id == category_transfers_account_id
- && *category_id == savings_category_id
- && date.to_iso().get(0..10) == Some("2024-10-23"),
- _ => false,
- }
-}
-
-fn matches_category_transfer_child_in_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let category_transfers_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.transfers_account)
- .expect("failed to find transfers account")
- .id
- .clone();
-
- let savings_category_id = categories
- .get(CATEGORY_NAMES_DICT.general)
- .expect("failed to find general category")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: true,
- parent_id: Some(_),
- account_id,
- category_id: Some(category_id),
- amount: 120_00,
- date,
- ..
- } => *account_id == category_transfers_account_id
- && *category_id == savings_category_id
- && date.to_iso().get(0..10) == Some("2024-10-23"),
- _ => false,
- }
-}
-
-fn matches_account_transfer_out_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- _categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let bank_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.bank_account)
- .expect("failed to find bank account")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: false,
- parent_id: None,
- account_id,
- category_id: None,
- amount: -80_00,
- date,
- ..
- } => *account_id == bank_account_id
- && date.to_iso().get(0..10) == Some("2024-09-10"),
- _ => false,
- }
-}
-
-fn matches_account_transfer_in_transaction(
- t: &ActualbudgetTransaction,
- accounts: &HashMap<String, ActualbudgetAccount>,
- _categories: &HashMap<String, ActualbudgetCategory>,
-) -> bool {
- let cash_account_id = accounts
- .get(ACCOUNT_NAMES_DICT.cash_account)
- .expect("failed to find cash account")
- .id
- .clone();
-
- match t {
- ActualbudgetTransaction {
- is_parent: false,
- is_child: false,
- parent_id: None,
- account_id,
- category_id: None,
- amount: 80_00,
- date,
- ..
- } => *account_id == cash_account_id
- && date.to_iso().get(0..10) == Some("2024-09-10"),
- _ => false,
- }
-}