chore: delete test scenarios used during initial implementation

This commit is contained in:
2025-10-16 16:07:46 +02:00
parent aa1ff02d6d
commit 79fc4272b6
3 changed files with 1 additions and 205 deletions

View File

@@ -1,68 +0,0 @@
#[cfg(test)]
mod tests {
use crate::*;
#[derive(Clone, Debug, PartialEq)]
struct Product {
id: String,
name: String,
model: Option<String>,
price: u64,
in_stock: bool,
}
impl EAV for Product {
fn class() -> &'static str {
"product"
}
}
impl From<Entity> for Product {
fn from(entity: Entity) -> Self {
Product {
id: entity.id.clone(),
name: entity.unwrap("name"),
model: entity.unwrap_opt("model"),
price: entity.unwrap_or("price", 0),
in_stock: entity.unwrap("in_stock"),
}
}
}
impl From<Product> for Entity {
fn from(value: Product) -> Self {
Entity::new::<Product>()
.with_id(&value.id)
.with_attribute("name", value.name)
.with_attribute("price", value.price)
.with_attribute("in_stock", value.in_stock)
.with_opt_attribute("model", value.model)
}
}
#[test]
/// # Example 1
///
/// - How to create a new empty catalog
/// - How to insert a new entity
/// - How to read the entity by id
fn scenario_001() {
// create a new named temp file
let tempfile = tempfile::NamedTempFile::new().unwrap();
let path = tempfile.path();
let path = path.to_str().unwrap();
// initialize a new empty catalog given an existing path
let mut catalog = Catalog::new(path);
// create a new object
let product = Product {
id: short_uuid::short!().to_string(),
name: String::from("PenguinX Laptop"),
model: None,
price: 135000,
in_stock: true,
};
// save some info for late comparison
let original_product = product.clone();
// insert the new object into catalog consuming it
catalog.upsert(product);
// read value from catalog using the original key
let read_product = catalog.get::<Product>(&original_product.id).unwrap();
// assert equality between original and read
assert_eq!(original_product, read_product);
}
}

View File

@@ -1,2 +1 @@
pub mod intended_use;
pub mod rusty_budger_use;

View File

@@ -1,135 +0,0 @@
#[cfg(test)]
mod tests {
use crate::*;
use category::*;
use operation::*;
use relation::*;
pub mod relation {
use super::*;
pub struct OperationToCategory {
pub id: String,
pub operation_id: String,
pub category_id: String,
}
impl EAV for OperationToCategory {
fn class() -> &'static str {
"operation_to_category"
}
}
impl From<OperationToCategory> for Entity {
fn from(value: OperationToCategory) -> Entity {
Entity::new::<OperationToCategory>()
.with_id(&value.id)
.with_attribute("operation_id", value.operation_id)
.with_attribute("category_id", value.category_id)
}
}
impl From<Entity> for OperationToCategory {
fn from(entity: Entity) -> Self {
OperationToCategory {
id: entity.id.clone(),
operation_id: entity.unwrap("operation_id"),
category_id: entity.unwrap("category_id"),
}
}
}
}
pub mod category {
use super::*;
pub struct Category {
pub id: String,
pub label: String,
}
impl EAV for Category {
fn class() -> &'static str {
"category"
}
}
impl From<Category> for Entity {
fn from(value: Category) -> Entity {
Entity::new::<Category>()
.with_id(&value.id)
.with_attribute("label", value.label)
}
}
impl From<Entity> for Category {
fn from(entity: Entity) -> Self {
Category {
id: entity.id.clone(),
label: entity.unwrap("label"),
}
}
}
}
pub mod operation {
use super::*;
pub struct Operation {
pub id: String,
pub date: u64,
pub amount: i64,
pub description: String,
}
impl EAV for Operation {
fn class() -> &'static str {
"operation"
}
}
impl From<Operation> for Entity {
fn from(value: Operation) -> Entity {
Entity::new::<Operation>()
.with_id(&value.id)
.with_attribute("date", value.date)
.with_attribute("amount", value.amount)
.with_attribute("description", value.description)
}
}
impl From<Entity> for Operation {
fn from(entity: Entity) -> Self {
Operation {
id: entity.id.clone(),
date: entity.unwrap("date"),
amount: entity.unwrap("amount"),
description: entity.unwrap("description"),
}
}
}
}
#[test]
pub fn check_001() {
let file = "./rustybudger.sqlite3";
// clean filesystem
if let Ok(true) = std::fs::exists(file) {
let _ = std::fs::remove_file(file);
}
let mut catalog = Catalog::new(file);
let operation_01 = Operation {
id: short_uuid::short!().to_string(),
date: 20250929,
amount: -10000,
description: "operation 1".to_string(),
};
let operation_02 = Operation {
id: short_uuid::short!().to_string(),
date: 20250930,
amount: -20000,
description: "operation 2".to_string(),
};
let category_01 = Category {
id: short_uuid::short!().to_string(),
label: "Need".to_string(),
};
let relation_01 = OperationToCategory {
id: short_uuid::short!().to_string(),
operation_id: operation_01.id.clone(),
category_id: category_01.id.clone(),
};
let operations = vec![operation_01, operation_02];
let categories = vec![category_01];
let relations = vec![relation_01];
catalog.insert_many(operations);
catalog.insert_many(categories);
catalog.insert_many(relations);
let result = catalog.persist();
assert!(result.is_ok());
}
}