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
|
mod account_activity;
mod bmo;
mod cibc;
mod hm_bank;
mod investment;
mod pdf_td_loc;
mod simplii;
mod td;
mod wise;
use crate::model::Transaction;
pub fn parse_transactions(bank: &str, file: &str) -> anyhow::Result<Vec<Transaction>> {
match bank.to_lowercase().as_str() {
"account_activity" => account_activity::parse(file),
"cibc" => cibc::parse(file),
"bmo" => bmo::parse(file),
"hm_bank" => hm_bank::parse(file),
"td" => td::parse(file),
"simplii" => simplii::parse(file),
"wise" => wise::parse(file),
"investment" => investment::parse(file),
"pdf_td_loc" => pdf_td_loc::parse(file),
_ => Err(anyhow::anyhow!("Unsupported bank: {}", bank)),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_unsupported_bank() {
let result = parse_transactions("unsupported_bank", "fake_file.csv");
assert!(result.is_err());
assert!(
result
.unwrap_err()
.to_string()
.contains("Unsupported bank: unsupported_bank")
);
}
#[test]
fn test_bank_name_case_insensitive() {
// These should not error out due to case
let result1 = parse_transactions("CIBC", "nonexistent.csv");
let result2 = parse_transactions("bMo", "nonexistent.csv");
let result3 = parse_transactions("TD", "nonexistent.csv");
let result4 = parse_transactions("SIMPLII", "nonexistent.csv");
// They should error due to file not found, not unsupported bank
assert!(result1.is_err());
assert!(result2.is_err());
assert!(result3.is_err());
assert!(result4.is_err());
// But the error should not be "Unsupported bank"
assert!(
!result1
.unwrap_err()
.to_string()
.contains("Unsupported bank")
);
assert!(
!result2
.unwrap_err()
.to_string()
.contains("Unsupported bank")
);
assert!(
!result3
.unwrap_err()
.to_string()
.contains("Unsupported bank")
);
assert!(
!result4
.unwrap_err()
.to_string()
.contains("Unsupported bank")
);
}
}
|