chore: move Item outside of catalog test mod

This commit is contained in:
2025-10-22 06:40:08 +02:00
parent d4ecd1a6cc
commit dedfe7a5d2
4 changed files with 61 additions and 50 deletions

View File

@@ -193,6 +193,9 @@ pub use crate::str::filter::O as Filter;
pub(crate) use crate::str::value::Value; pub(crate) use crate::str::value::Value;
pub use crate::trt::eav::T as EAV; pub use crate::trt::eav::T as EAV;
#[cfg(test)]
pub(crate) use crate::str::item::O as Item;
mod sqlite { mod sqlite {
pub use crate::str::sqlite_failed_to::FailedTo; pub use crate::str::sqlite_failed_to::FailedTo;
pub mod build { pub mod build {

View File

@@ -14,56 +14,6 @@ pub struct O {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[derive(Debug, Default, PartialEq, Clone)]
struct Item {
pub id: String,
pub name: String,
pub price: u64,
pub discount: f64,
pub sell_trend: i64,
pub in_stock: bool,
pub subclass: Option<String>,
}
impl EAV for Item {
fn class() -> &'static str {
"item"
}
}
impl From<Item> for Entity {
fn from(value: Item) -> Entity {
let mut entity = Entity::new::<Item>()
.with_id(&value.id)
.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);
if let Some(subclass) = value.subclass {
entity = entity.with_subclass(&subclass);
}
entity
}
}
impl From<Entity> for Item {
fn from(entity: Entity) -> Self {
Self {
id: entity.id.clone(),
name: entity.unwrap("name").expect("name is always present"),
price: entity.unwrap("price").expect("price is always present"),
discount: entity
.unwrap("discount")
.expect("discount is always present"),
sell_trend: entity
.unwrap("sell_trend")
.expect("sell_trend is always present"),
in_stock: entity
.unwrap("in_stock")
.expect("in_stock is always present"),
subclass: entity.subclass,
}
}
}
// ## 'new()' // ## 'new()'
#[test] #[test]
fn new_should_create_catalog_with_path_and_empty_items() { fn new_should_create_catalog_with_path_and_empty_items() {

View File

@@ -0,0 +1,57 @@
#[cfg(test)]
use crate::*;
#[cfg(test)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct O {
pub id: String,
pub name: String,
pub price: u64,
pub discount: f64,
pub sell_trend: i64,
pub in_stock: bool,
pub subclass: Option<String>,
}
#[cfg(test)]
impl EAV for Item {
fn class() -> &'static str {
"item"
}
}
#[cfg(test)]
impl From<Item> for Entity {
fn from(value: Item) -> Entity {
let mut entity = Entity::new::<Item>()
.with_id(&value.id)
.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);
if let Some(subclass) = value.subclass {
entity = entity.with_subclass(&subclass);
}
entity
}
}
#[cfg(test)]
impl From<Entity> for Item {
fn from(entity: Entity) -> Self {
Self {
id: entity.id.clone(),
name: entity.unwrap("name").expect("name is always present"),
price: entity.unwrap("price").expect("price is always present"),
discount: entity
.unwrap("discount")
.expect("discount is always present"),
sell_trend: entity
.unwrap("sell_trend")
.expect("sell_trend is always present"),
in_stock: entity
.unwrap("in_stock")
.expect("in_stock is always present"),
subclass: entity.subclass,
}
}
}

View File

@@ -6,5 +6,6 @@ pub mod entity;
pub mod entity_state; pub mod entity_state;
pub mod failed_to; pub mod failed_to;
pub mod filter; pub mod filter;
pub mod item;
pub mod sqlite_failed_to; pub mod sqlite_failed_to;
pub mod value; pub mod value;