test: add properties to Item struct to improve test code coverage for Entity
This commit is contained in:
@@ -5,12 +5,15 @@ use crate::*;
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct O {
|
||||
pub id: String,
|
||||
pub first_seen: u64,
|
||||
pub name: String,
|
||||
pub price: u64,
|
||||
pub discount: f64,
|
||||
pub sell_trend: i64,
|
||||
pub in_stock: bool,
|
||||
pub subclass: Option<String>,
|
||||
pub category: Option<String>,
|
||||
pub tag: String,
|
||||
}
|
||||
#[cfg(test)]
|
||||
impl EAV for Item {
|
||||
@@ -23,12 +26,15 @@ impl From<Item> for Entity {
|
||||
fn from(value: Item) -> Entity {
|
||||
let mut entity = Entity::new::<Item>()
|
||||
.with_id(&value.id)
|
||||
.with_ref_date(value.first_seen)
|
||||
.with_subclass("subitem")
|
||||
.with_attribute("name", value.name)
|
||||
.with_attribute("price", value.price)
|
||||
.with_attribute("discount", value.discount)
|
||||
.with_attribute("sell_trend", value.sell_trend)
|
||||
.with_attribute("in_stock", value.in_stock);
|
||||
.with_attribute("in_stock", value.in_stock)
|
||||
.with_opt_attribute("vategory", value.category)
|
||||
.with_attribute("tag", value.tag);
|
||||
if let Some(subclass) = value.subclass {
|
||||
entity = entity.with_subclass(&subclass);
|
||||
}
|
||||
@@ -39,7 +45,8 @@ impl From<Item> for Entity {
|
||||
impl From<Entity> for Item {
|
||||
fn from(entity: Entity) -> Self {
|
||||
Self {
|
||||
id: entity.id.clone(),
|
||||
id: entity.id(),
|
||||
first_seen: entity.ref_date.expect("ref date is always present"),
|
||||
name: entity.unwrap("name").expect("name is always present"),
|
||||
price: entity.unwrap("price").expect("price is always present"),
|
||||
discount: entity
|
||||
@@ -51,7 +58,13 @@ impl From<Entity> for Item {
|
||||
in_stock: entity
|
||||
.unwrap("in_stock")
|
||||
.expect("in_stock is always present"),
|
||||
subclass: entity.subclass,
|
||||
subclass: entity.subclass(),
|
||||
category: entity
|
||||
.unwrap_opt("category")
|
||||
.expect("category is always optinally present"),
|
||||
tag: entity
|
||||
.unwrap_or("tag", "-".to_string())
|
||||
.expect("tag is always present"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user