summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/actualbudget_to_schist_transformer/tests/common/transaction_matchers.rs130
-rw-r--r--rust/actualbudget_to_schist_transformer/tests/run.rs2
2 files changed, 128 insertions, 4 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,
+ }
}
diff --git a/rust/actualbudget_to_schist_transformer/tests/run.rs b/rust/actualbudget_to_schist_transformer/tests/run.rs
index bf2cf39..7cfe150 100644
--- a/rust/actualbudget_to_schist_transformer/tests/run.rs
+++ b/rust/actualbudget_to_schist_transformer/tests/run.rs
@@ -67,7 +67,7 @@ fn given_test_database_when_run_then_exports_expected_schist_state() {
assert_eq!(transaction_matchers.len(), transactions.len());
for transaction in transactions {
assert!(
- transaction_matchers.iter().any(|m| m(&transaction)),
+ transaction_matchers.iter().any(|m| m(&transaction, &accounts)),
"no match found for transaction {:?}",
transaction,
);