test: add tests to catalog.delete function
This commit is contained in:
@@ -572,13 +572,35 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn delete_should_mark_entity_as_to_delete() {
|
fn delete_should_mark_entity_as_to_delete() {
|
||||||
// Should mark an existing entity's state as 'ToDelete'.
|
// 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]
|
#[test]
|
||||||
fn delete_should_have_no_effect_for_nonexistent_id() {
|
fn delete_should_have_no_effect_for_nonexistent_id() {
|
||||||
// Should have no effect if the entity ID does not exist.
|
// 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()'
|
// ## 'persist()'
|
||||||
|
|||||||
Reference in New Issue
Block a user