From 73cc31d44f96eb8f6d6e73d175845769a2a68b67 Mon Sep 17 00:00:00 2001 From: SkyfallWasTaken Date: Sat, 20 Jul 2024 10:06:02 +0100 Subject: [PATCH] Add fulfillment description --- src/format.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/format.rs b/src/format.rs index 3f1d5dd..ff27cfa 100644 --- a/src/format.rs +++ b/src/format.rs @@ -16,6 +16,10 @@ pub fn format_item_diff(old: &ShopItem, new: &ShopItem) -> Option { result.push(format!("*Name:* {}", new.full_name)); } + if old.price != new.price { + result.push(format!("*Price:* {} → {}", old.price, new.price)); + } + if old.description != new.description { result.push(format!( "*Description:* {} → {}", @@ -24,8 +28,12 @@ pub fn format_item_diff(old: &ShopItem, new: &ShopItem) -> Option { )); } - if old.price != new.price { - result.push(format!("*Price:* {} → {}", old.price, new.price)); + if old.fulfillment_description != new.fulfillment_description { + result.push(format!( + "*Fulfillment info:* {} → {}", + old.description.as_ref().unwrap_or(&"_not set_".into()), + new.description.as_ref().unwrap_or(&"_not set_".into()) + )); } if old.stock != new.stock { @@ -226,6 +234,31 @@ mod diff_tests { ); } + #[test] + fn test_fulfillment_info() { + let old = ShopItem { + full_name: "Test".into(), + fulfillment_description: Some("Lorem ipsum".into()), + ..Default::default() + }; + + let new = ShopItem { + full_name: "Test".into(), + fulfillment_description: Some("Dolor sit amet".into()), + ..Default::default() + }; + + assert_eq!( + format_item_diff(&old, &new), + Some( + indoc! {" + *Name:* Test + *Fulfillment info:* Lorem ipsum → Dolor sit amet"} + .into() + ) + ); + } + #[test] fn equal_items_no_diff() { let item = ShopItem {