From fb8bfa301b7ac4e42d43d89fece4607b0287e185 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Tue, 14 Oct 2025 11:52:03 +0200 Subject: [PATCH] test: add tests to catalog.delete function --- 01.workspace/heave/src/str/catalog.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index b5e4ba1..3ae5628 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -572,13 +572,35 @@ mod tests { #[test] fn delete_should_mark_entity_as_to_delete() { // Should mark an existing entity's state as 'ToDelete'. - todo!(); + let mut catalog = Catalog::new("dummy.db"); + let item = Item { + id: "item-123".to_string(), + name: "Test Item".to_string(), + price: 100, + in_stock: true, + }; + let item_id = item.id.clone(); + catalog.insert(item); + catalog.delete(&item_id); + let entity = catalog.items.get(&item_id).unwrap(); + assert_eq!(entity.state, EntityState::ToDelete); } #[test] fn delete_should_have_no_effect_for_nonexistent_id() { // Should have no effect if the entity ID does not exist. - todo!(); + let mut catalog = Catalog::new("dummy.db"); + let item = Item { + id: "item-123".to_string(), + name: "Test Item".to_string(), + price: 100, + in_stock: true, + }; + catalog.insert(item); + let original_items = catalog.items.clone(); + // Attempt to delete a non-existent entity, which should not panic or change anything. + catalog.delete("nonexistent-id"); + assert_eq!(catalog.items, original_items); } // ## 'persist()'