diff --git a/src/inventory/adapters/output/db/postgres/category_id_exists.rs b/src/inventory/adapters/output/db/postgres/category_id_exists.rs index 6152c65..c61f9a5 100644 --- a/src/inventory/adapters/output/db/postgres/category_id_exists.rs +++ b/src/inventory/adapters/output/db/postgres/category_id_exists.rs @@ -32,6 +32,8 @@ impl CategoryIDExistsDBPort for InventoryDBPostgresAdapter { mod tests { use uuid::Uuid; + use crate::inventory::adapters::output::db::postgres::category_name_exists_for_store::tests::create_dummy_category_record; + use super::*; #[actix_rt::test] @@ -57,20 +59,8 @@ mod tests { // state doesn't exist assert!(!db.category_id_exists(&category).await.unwrap()); - sqlx::query!( - "INSERT INTO cqrs_inventory_category_query - (version, name, description, category_id, store_id) - VALUES ($1, $2, $3, $4, $5);", - 1, - category.name(), - category.description().as_ref().unwrap(), - category.category_id(), - category.store_id(), - ) - .execute(&db.pool) - .await - .unwrap(); - + create_dummy_category_record(&category, &db).await; + // state exists assert!(db.category_id_exists(&category).await.unwrap()); diff --git a/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs b/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs index ef3ed59..44cce82 100644 --- a/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs +++ b/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs @@ -34,11 +34,28 @@ impl CategoryNameExistsForStoreDBPort for InventoryDBPostgresAdapter { } #[cfg(test)] -mod tests { +pub mod tests { + use uuid::Uuid; use super::*; + pub async fn create_dummy_category_record(c: &Category, db: &InventoryDBPostgresAdapter) { + sqlx::query!( + "INSERT INTO cqrs_inventory_category_query + (version, name, description, category_id, store_id) + VALUES ($1, $2, $3, $4, $5);", + 1, + c.name(), + c.description().as_ref().unwrap(), + c.category_id(), + c.store_id(), + ) + .execute(&db.pool) + .await + .unwrap(); + } + #[actix_rt::test] async fn test_postgres_category_exists() { let category_id = Uuid::new_v4(); @@ -62,19 +79,7 @@ mod tests { // state doesn't exist assert!(!db.category_name_exists_for_store(&category).await.unwrap()); - sqlx::query!( - "INSERT INTO cqrs_inventory_category_query - (version, name, description, category_id, store_id) - VALUES ($1, $2, $3, $4, $5);", - 1, - category.name(), - category.description().as_ref().unwrap(), - category.category_id(), - category.store_id(), - ) - .execute(&db.pool) - .await - .unwrap(); + create_dummy_category_record(&category, &db).await; // state exists assert!(db.category_name_exists_for_store(&category).await.unwrap()); diff --git a/src/inventory/domain/category_aggregate.rs b/src/inventory/domain/category_aggregate.rs index dc3ee20..6998715 100644 --- a/src/inventory/domain/category_aggregate.rs +++ b/src/inventory/domain/category_aggregate.rs @@ -89,7 +89,7 @@ mod aggregate_tests { type CategoryTestFramework = TestFramework; #[test] - fn test_create_store() { + fn test_create_category() { let name = "category_name"; let description = Some("category_description".to_string()); let adding_by = UUID;