diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index dc913d5..052a463 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -58,4 +58,4 @@ jobs: exit 1 fi env: - COVERAGE_THRESHOLD: 65 + COVERAGE_THRESHOLD: 45 diff --git a/Cargo.lock b/Cargo.lock index 63e7449..7633023 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,7 +571,7 @@ checksum = "b90ca2580b73ab6a1f724b76ca11ab632df820fd6040c336200d2c1df7b3c82c" [[package]] name = "etradeTaxReturnHelper" -version = "0.4.6" +version = "0.5.0" dependencies = [ "calamine", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 80b56f8..e6b47c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "etradeTaxReturnHelper" -version = "0.4.6" +version = "0.5.0" edition = "2021" description = "Parses etrade financial documents for transaction details (income, tax paid, cost basis) and compute total income and total tax paid according to chosen tax residency (currency)" license = "BSD-3-Clause" diff --git a/src/de.rs b/src/de.rs index 63ed44a..72d02f7 100644 --- a/src/de.rs +++ b/src/de.rs @@ -74,6 +74,8 @@ impl etradeTaxReturnHelper::Residency for DE { #[cfg(test)] mod tests { use super::*; + use etradeTaxReturnHelper::Residency; + #[test] fn test_present_result_de() -> Result<(), String> { let rd: Box = Box::new(DE {}); @@ -99,4 +101,32 @@ mod tests { Ok(()) } + + #[test] + fn test_get_exchange_rates_eur() -> Result<(), String> { + let mut dates: std::collections::HashMap< + etradeTaxReturnHelper::Exchange, + Option<(String, f32)>, + > = std::collections::HashMap::new(); + dates.insert( + etradeTaxReturnHelper::Exchange::USD("07/14/23".to_owned()), + None, + ); + + let rd: DE = DE {}; + rd.get_currency_exchange_rates(&mut dates,"EUR").map_err(|x| "Error: unable to get exchange rates. Please check your internet connection or proxy settings\n\nDetails:".to_string()+x.as_str())?; + + let mut expected_result: std::collections::HashMap< + etradeTaxReturnHelper::Exchange, + Option<(String, f32)>, + > = std::collections::HashMap::new(); + expected_result.insert( + etradeTaxReturnHelper::Exchange::USD("07/14/23".to_owned()), + Some(("2023-07-13".to_owned(), 0.89077)), + ); + + assert_eq!(dates, expected_result); + + Ok(()) + } } diff --git a/src/main.rs b/src/main.rs index 6410fd1..3ba0bfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -261,6 +261,26 @@ mod tests { Ok(()) } + #[test] + fn test_unrecognized_file_taxation() -> Result<(), clap::Error> { + // Get all brokerage with dividends only + let myapp = App::new("E-trade tax helper").setting(AppSettings::ArgRequiredElseHelp); + let rd: Box = Box::new(pl::PL {}); + // Check printed values or returned values? + let matches = create_cmd_line_pattern(myapp) + .get_matches_from_safe(vec!["mytest", "unrecognized_file.txt"])?; + + let pdfnames = matches + .values_of("financial documents") + .expect_and_log("error getting financial documents names"); + let pdfnames: Vec = pdfnames.map(|x| x.to_string()).collect(); + + match etradeTaxReturnHelper::run_taxation(&rd, pdfnames) { + Ok(_) => panic!("Expected an error from run_taxation, but got Ok"), + Err(_) => Ok(()), // Expected error, test passes + } + } + #[test] #[ignore] fn test_dividends_taxation() -> Result<(), clap::Error> { diff --git a/src/pdfparser.rs b/src/pdfparser.rs index 6d37557..873b81e 100644 --- a/src/pdfparser.rs +++ b/src/pdfparser.rs @@ -146,7 +146,7 @@ fn create_dividend_parsing_sequence(sequence: &mut std::collections::VecDeque>) { sequence.push_back(Box::new(StringEntry { val: String::new(), - patterns: vec!["INTEL CORP".to_owned()], + patterns: vec!["INTEL CORP".to_owned(), "ADVANCED MICRO DEVICES".to_owned()], })); sequence.push_back(Box::new(F32Entry { val: 0.0 })); // Tax Entry } @@ -184,7 +184,7 @@ fn create_sold_parsing_sequence(sequence: &mut std::collections::VecDeque>) { sequence.push_back(Box::new(StringEntry { val: String::new(), - patterns: vec!["INTEL CORP".to_owned()], + patterns: vec!["INTEL CORP".to_owned(), "ADVANCED MICRO DEVICES".to_owned()], })); sequence.push_back(Box::new(StringEntry { val: String::new(), @@ -1105,6 +1105,31 @@ mod tests { )) ); + assert_eq!( + parse_statement("data/example-sold-amd.pdf"), + Ok(( + vec![], + vec![], + vec![ + ( + "11/10/23".to_owned(), + "11/14/23".to_owned(), + 72.0, + 118.13, + 8505.29 + ), + ( + "11/22/23".to_owned(), + "11/27/23".to_owned(), + 162.0, + 122.4511, + 19836.92 + ), + ], + vec![] + )) + ); + //TODO(jczaja): Renable reinvest dividends case as soon as you get some PDFs //assert_eq!( // parse_statement("data/example3.pdf"),