summaryrefslogtreecommitdiff
path: root/rust/actualbudget_to_schist_transformer/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'rust/actualbudget_to_schist_transformer/tests/common')
-rw-r--r--rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs130
1 files changed, 127 insertions, 3 deletions
diff --git a/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs b/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs
index 3f126fd..d183b3a 100644
--- a/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs
+++ b/rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs
@@ -1,6 +1,130 @@
-use schist_models::transaction::Transaction;
+use schist_models::{account::Account, transaction::Transaction};
+
+use super::ACCOUNT_NAMES_DICT;
pub fn get_transaction_matchers(
-) -> Vec<Box<dyn Fn(&Transaction) -> bool>> {
- todo!()
+) -> 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")),
+ ]
+}
+
+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,
+ }
+}
+
+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,
+ }
+}
+
+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,
+ }
+}
+
+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,
+ }
}