summaryrefslogtreecommitdiff
path: root/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs')
-rw-r--r--actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs130
1 files changed, 130 insertions, 0 deletions
diff --git a/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs b/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs
new file mode 100644
index 0000000..c3763c1
--- /dev/null
+++ b/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs
@@ -0,0 +1,130 @@
+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,
+ }
+}