1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
pub mod common;
use actualbudget_to_schist_transformer::run::run;
use common::{assert_budget_drip_matches, get_account_matchers, get_account_transfer_matchers, get_category_matchers, get_category_transfer_matchers, get_num_expected_budget_drips, get_transaction_categorisation_matchers, get_transaction_matchers, TestContext, TEST_IN_DB_URL, TEST_OUT_DB_URL};
use diesel::{Connection, SqliteConnection};
use schist_queries::{account_transfers::get_all_account_transfers, accounts::get_all_accounts, budget_drips::get_all_budget_drips, categories::get_all_categories, category_transfers::get_all_category_transfers, transaction_categorisations::get_all_transaction_categorisations, transactions::get_all_transactions};
#[test]
fn given_test_database_when_run_then_exports_expected_schist_state() {
let _context = TestContext::new();
run(TEST_IN_DB_URL, TEST_OUT_DB_URL).unwrap();
let connection = &mut SqliteConnection::establish(TEST_OUT_DB_URL).unwrap();
let accounts = get_all_accounts(connection).unwrap();
let account_transfers = get_all_account_transfers(connection).unwrap();
let budget_drips = get_all_budget_drips(connection).unwrap();
let categories = get_all_categories(connection).unwrap();
let category_transfers = get_all_category_transfers(connection).unwrap();
let transactions = get_all_transactions(connection).unwrap();
let transaction_categorisations = get_all_transaction_categorisations(connection).unwrap();
let account_matchers = get_account_matchers();
assert_eq!(account_matchers.len(), accounts.len());
for account in &accounts {
assert!(
account_matchers.iter().any(|m| m(&account)),
"no match found for account {:?}",
account,
);
}
let account_transfer_matchers = get_account_transfer_matchers();
assert_eq!(account_transfer_matchers.len(), account_transfers.len());
for account_transfer in account_transfers {
assert!(
account_transfer_matchers.iter().any(|m| m(&account_transfer, &accounts)),
"no match found for account_transfer {:?}",
account_transfer,
);
}
assert_eq!(get_num_expected_budget_drips(), budget_drips.len());
for budget_drip in budget_drips {
assert_budget_drip_matches(&budget_drip, &categories);
}
let category_matchers = get_category_matchers();
assert_eq!(category_matchers.len(), categories.len());
for category in categories.clone() {
assert!(
category_matchers.iter().any(|m| m(&category)),
"no match found for category {:?}",
category,
);
}
let category_transfer_matchers = get_category_transfer_matchers();
assert_eq!(category_transfer_matchers.len(), category_transfers.len());
for category_transfer in category_transfers {
assert!(
category_transfer_matchers.iter().any(|m| m(&category_transfer, &categories)),
"no match found for category_transfer {:?}",
category_transfer,
);
}
let transaction_matchers = get_transaction_matchers();
assert_eq!(transaction_matchers.len(), transactions.len());
for transaction in transactions.clone() {
assert!(
transaction_matchers.iter().any(|m| m(&transaction, &accounts)),
"no match found for transaction {:?}",
transaction,
);
}
let transaction_categorisation_matchers = get_transaction_categorisation_matchers();
assert_eq!(transaction_categorisation_matchers.len(), transaction_categorisations.len());
for transaction_categorisation in transaction_categorisations {
assert!(
transaction_categorisation_matchers.iter().any(|m| m(
&transaction_categorisation,
&transactions,
&categories,
&accounts,
)),
"no match found for transaction_categorisation {:?}",
transaction_categorisation,
);
}
}
|