From 8a9119e6922bf845d9369a3473b2b8644f4e3ea0 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Fri, 10 Oct 2025 08:56:06 +0200 Subject: [PATCH] test: add Item struct to be used in test scenarios --- 01.workspace/heave/src/str/catalog.rs | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index 635b77e..449623c 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -194,6 +194,46 @@ impl Catalog { #[cfg(test)] mod tests { + use super::*; + #[derive(Default, PartialEq, Clone)] + struct Item { + pub id: String, + pub name: String, + pub price: u64, + pub in_stock: bool, + } + impl Item { + pub fn new() -> Self { + Self { + id: short_uuid::short!().to_string(), + ..Self::default() + } + } + } + impl EAV for Item { + fn class() -> &'static str { + "item" + } + } + impl From for Entity { + fn from(value: Item) -> Entity { + Entity::new::() + .with_id(&value.id) + .with_attribute("name", value.name) + .with_attribute("price", value.price) + .with_attribute("in_stock", value.in_stock) + } + } + impl From for Item { + fn from(entity: Entity) -> Self { + Self { + id: entity.id.clone(), + name: entity.unwrap("name"), + price: entity.unwrap("price"), + in_stock: entity.unwrap("in_stock"), + } + } + } // ## 'new()' #[test] fn new_should_create_catalog_with_path_and_empty_items() {