extern crate find_latest_nav; mod common; use common::db_connection; use find_latest_nav::nav::{ retrieve_csv_data_from, Record, find_latest_for }; //use csv::StringRecord; #[test] fn test_retrieve_csv_data_from() { let conn = db_connection(); let sample_data = get_csv_contents_sample(); let result = retrieve_csv_data_from(sample_data, &conn); assert_eq!(result, Ok(())); } // test data fn get_csv_contents_sample() -> String { " Scheme Code;ISIN Div Payout/ ISIN Growth;ISIN Div Reinvestment;Scheme Name;Net Asset Value;Date 119551;INF209KA12Z1;INF209KA13Z9;Aditya Birla Sun Life Banking & PSU Debt Fund - Direct Plan-Dividend;148.892;30-Jul-2019 119552;INF209K01YM2;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Direct Plan-Monthly Dividend;109.3933;30-Jul-2019 119553;INF209K01YO8;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Direct Plan-Quarterly Dividend;107.3603;30-Jul-2019 108272;INF209K01LX6;INF209KA11Z3;Aditya Birla Sun Life Banking & PSU Debt Fund - Regular Plan-Dividend;156.1891;30-Jul-2019 108273;INF209K01LV0;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Regular Plan-Growth;247.8975;30-Jul-2019 110282;INF209K01LU2;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Regular Plan-Monthly Dividend;107.6318;30-Jul-2019 108274;INF209K01LN7;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Regular Plan-Quarterly Dividend;105.739;30-Jul-2019 103176;INF209K01LT4;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Retail Plan-Growth;372.1243;30-Jul-2019 110490;INF209K01LR8;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Retail Plan-Monthly Dividend;107.4933;30-Jul-2019 106157;INF209K01LS6;-;Aditya Birla Sun Life Banking & PSU Debt Fund - Retail Plan-Quarterly Dividend;108.4294;30-Jul-2019 119550;INF209K01YN0;-;Aditya Birla Sun Life Banking & PSU Debt Fund- Direct Plan-Growth;252.2005;30-Jul-2019 ".to_string() } fn sample_record() -> Vec { vec![ String::from("119551"), // scheme_code String::new(), // isin growth String::new(), // isin div reinvestment String::from("Test scheme"), // scheme name String::from("123.456"), // net-asset-value String::from("10-Sep-2019"), // date String::new(), // remarks String::new() // created on ] } #[test] fn test_convert() { let nav_record = Record::convert( sample_record() ); let expected = sample_record()[0].parse::().unwrap(); let actual = nav_record.scheme_code(); assert_eq!(actual, &expected); } #[test] fn test_row_exist() { let conn = db_connection(); let nav_record = Record::convert( sample_record() ); let result = nav_record.row_exist(&conn); assert_eq!(result, true); } #[test] fn test_find_latest_nav_for_scheme() { let conn = db_connection(); let scheme_codes = vec![119550]; let isin_codes = vec![]; let result = find_latest_for(scheme_codes, isin_codes, &conn); let expected_nav = String::from("252.2005"); let actual_nav = result[0].net_asset_value(); assert_eq!(actual_nav, &expected_nav); } #[test] fn test_find_latest_nav_for_isin() { let conn = db_connection(); let scheme_codes = vec![]; let isin_codes = vec!["INF209K01YM2"]; let result = find_latest_for(scheme_codes, isin_codes, &conn); let expected_nav = String::from("109.3933"); let actual_nav = result[0].net_asset_value(); assert_eq!(actual_nav, &expected_nav); } #[test] fn test_find_latest_nav_for_both_scheme_and_isin() { let conn = db_connection(); let scheme_codes = vec![119550]; let isin_codes = vec!["INF209K01YN0"]; let result = find_latest_for(scheme_codes, isin_codes, &conn); let expected_count = 1; let actual_count = result.len(); assert_eq!(actual_count, expected_count); }