From cfcacefe9a180a7604cbd9ff33e930ed865365c1 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Mon, 10 Nov 2025 16:55:32 +0100 Subject: [PATCH] test: add properties to Item struct to improve test code coverage for Entity --- 01.workspace/heave/src/str/item.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/01.workspace/heave/src/str/item.rs b/01.workspace/heave/src/str/item.rs index 7a77601..93e22f7 100644 --- a/01.workspace/heave/src/str/item.rs +++ b/01.workspace/heave/src/str/item.rs @@ -5,12 +5,15 @@ use crate::*; #[derive(Debug, Default, PartialEq, Clone)] pub struct O { pub id: String, + pub first_seen: u64, pub name: String, pub price: u64, pub discount: f64, pub sell_trend: i64, pub in_stock: bool, pub subclass: Option, + pub category: Option, + pub tag: String, } #[cfg(test)] impl EAV for Item { @@ -23,12 +26,15 @@ impl From for Entity { fn from(value: Item) -> Entity { let mut entity = Entity::new::() .with_id(&value.id) + .with_ref_date(value.first_seen) .with_subclass("subitem") .with_attribute("name", value.name) .with_attribute("price", value.price) .with_attribute("discount", value.discount) .with_attribute("sell_trend", value.sell_trend) - .with_attribute("in_stock", value.in_stock); + .with_attribute("in_stock", value.in_stock) + .with_opt_attribute("vategory", value.category) + .with_attribute("tag", value.tag); if let Some(subclass) = value.subclass { entity = entity.with_subclass(&subclass); } @@ -39,7 +45,8 @@ impl From for Entity { impl From for Item { fn from(entity: Entity) -> Self { Self { - id: entity.id.clone(), + id: entity.id(), + first_seen: entity.ref_date.expect("ref date is always present"), name: entity.unwrap("name").expect("name is always present"), price: entity.unwrap("price").expect("price is always present"), discount: entity @@ -51,7 +58,13 @@ impl From for Item { in_stock: entity .unwrap("in_stock") .expect("in_stock is always present"), - subclass: entity.subclass, + subclass: entity.subclass(), + category: entity + .unwrap_opt("category") + .expect("category is always optinally present"), + tag: entity + .unwrap_or("tag", "-".to_string()) + .expect("tag is always present"), } } }