mirror of
https://github.com/SkyfallWasTaken/arcade-monitor.git
synced 2024-11-10 03:49:40 +00:00
Add more tests for diffing algo
This commit is contained in:
parent
01ea8485e8
commit
88107872e9
2 changed files with 116 additions and 1 deletions
115
src/diff.rs
115
src/diff.rs
|
@ -72,4 +72,119 @@ mod test {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn description_diff() {
|
||||
let old = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
description: Some("Lorem ipsum".into()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let new = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
description: Some("Dolor sit amet".into()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
diff_items(old, new),
|
||||
Some(
|
||||
indoc! {"
|
||||
*Item updated*
|
||||
*Name:* Test
|
||||
*Description:* Lorem ipsum → Dolor sit amet"}
|
||||
.into()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stock_diff_limited_update() {
|
||||
let old = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
stock: Some(10),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let new = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
stock: Some(9),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
diff_items(old, new),
|
||||
Some(
|
||||
indoc! {"
|
||||
*Item updated*
|
||||
*Name:* Test
|
||||
*Stock:* 10 → 9"}
|
||||
.into()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stock_diff_limited_to_unlimited() {
|
||||
let old = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
stock: Some(10),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let new = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
stock: None,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
diff_items(old, new),
|
||||
Some(
|
||||
indoc! {"
|
||||
*Item updated*
|
||||
*Name:* Test
|
||||
*Stock:* 10 → Unlimited"}
|
||||
.into()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stock_diff_unlimited_to_limited() {
|
||||
let old = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
stock: None,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let new = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
stock: Some(10),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
diff_items(old, new),
|
||||
Some(
|
||||
indoc! {"
|
||||
*Item updated*
|
||||
*Name:* Test
|
||||
*Stock:* Unlimited → 10"}
|
||||
.into()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equal_items_no_diff() {
|
||||
let item = ShopItem {
|
||||
full_name: "Test".into(),
|
||||
price: 1,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(diff_items(item.clone(), item), None);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use scraper::{Html, Selector};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use worker::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Default, Clone)]
|
||||
pub struct ShopItem {
|
||||
#[serde(rename = "Full Name")]
|
||||
pub full_name: String,
|
||||
|
|
Loading…
Reference in a new issue