test: add test to catalog.load_by_filter function
This commit is contained in:
@@ -1523,6 +1523,55 @@ mod tests {
|
|||||||
|
|
||||||
std::fs::remove_file(path).unwrap();
|
std::fs::remove_file(path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn load_by_filter_should_load_matching_negative_sell_trend() {
|
||||||
|
let db_path = "target/test_dbs/lbf_matching_negative_sell_trend.db";
|
||||||
|
let path = std::path::Path::new(db_path);
|
||||||
|
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||||
|
if path.exists() {
|
||||||
|
std::fs::remove_file(path).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut catalog_setup = Catalog::new(db_path);
|
||||||
|
catalog_setup.init().unwrap();
|
||||||
|
let items = vec![
|
||||||
|
Item {
|
||||||
|
id: "item-1".to_string(),
|
||||||
|
name: "Item One".to_string(),
|
||||||
|
price: 100,
|
||||||
|
sell_trend: 10,
|
||||||
|
in_stock: true,
|
||||||
|
},
|
||||||
|
Item {
|
||||||
|
id: "item-2".to_string(),
|
||||||
|
name: "Item Two".to_string(),
|
||||||
|
price: 200,
|
||||||
|
sell_trend: -5,
|
||||||
|
in_stock: false,
|
||||||
|
},
|
||||||
|
Item {
|
||||||
|
id: "item-3".to_string(),
|
||||||
|
name: "Item Three".to_string(),
|
||||||
|
price: 300,
|
||||||
|
sell_trend: 10,
|
||||||
|
in_stock: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
catalog_setup.insert_many(items).unwrap();
|
||||||
|
catalog_setup.persist().unwrap();
|
||||||
|
|
||||||
|
let mut catalog = Catalog::new(db_path);
|
||||||
|
let filter = Filter::new().with_signed_int("sell_trend", Comparison::Equal, -5);
|
||||||
|
assert!(catalog.load_by_filter(&filter).is_ok());
|
||||||
|
|
||||||
|
assert_eq!(catalog.items.len(), 1);
|
||||||
|
assert!(catalog.items.contains_key("item-2"));
|
||||||
|
assert!(!catalog.items.contains_key("item-1"));
|
||||||
|
assert!(!catalog.items.contains_key("item-3"));
|
||||||
|
|
||||||
|
std::fs::remove_file(path).unwrap();
|
||||||
|
}
|
||||||
// ## Integration Tests
|
// ## Integration Tests
|
||||||
#[test]
|
#[test]
|
||||||
fn integration_test_init_insert_persist_load_get() {
|
fn integration_test_init_insert_persist_load_get() {
|
||||||
|
|||||||
Reference in New Issue
Block a user