diff --git a/src/inventory/application/port/output/db/customization_name_exists_for_product.rs b/src/inventory/application/port/output/db/customization_name_exists_for_product.rs new file mode 100644 index 0000000..0550b3c --- /dev/null +++ b/src/inventory/application/port/output/db/customization_name_exists_for_product.rs @@ -0,0 +1,64 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use mockall::predicate::*; +use mockall::*; + +use crate::inventory::domain::product_aggregate::Customization; + +use super::errors::*; +#[cfg(test)] +#[allow(unused_imports)] +pub use tests::*; + +#[automock] +#[async_trait::async_trait] +pub trait CustomizationNameExistsForProductDBPort: Send + Sync { + async fn customization_name_exists_for_product( + &self, + c: &Customization, + ) -> InventoryDBResult; +} + +pub type CustomizationNameExistsForProductDBPortObj = + std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_customization_name_exists_for_product_db_port_false( + times: Option, + ) -> CustomizationNameExistsForProductDBPortObj { + let mut m = MockCustomizationNameExistsForProductDBPort::new(); + if let Some(times) = times { + m.expect_customization_name_exists_for_product() + .times(times) + .returning(|_| Ok(false)); + } else { + m.expect_customization_name_exists_for_product() + .returning(|_| Ok(false)); + } + + Arc::new(m) + } + + pub fn mock_customization_name_exists_for_product_db_port_true( + times: Option, + ) -> CustomizationNameExistsForProductDBPortObj { + let mut m = MockCustomizationNameExistsForProductDBPort::new(); + if let Some(times) = times { + m.expect_customization_name_exists_for_product() + .times(times) + .returning(|_| Ok(true)); + } else { + m.expect_customization_name_exists_for_product() + .returning(|_| Ok(true)); + } + + Arc::new(m) + } +} diff --git a/src/inventory/application/port/output/db/mod.rs b/src/inventory/application/port/output/db/mod.rs index 599269b..3833d54 100644 --- a/src/inventory/application/port/output/db/mod.rs +++ b/src/inventory/application/port/output/db/mod.rs @@ -4,6 +4,8 @@ pub mod category_id_exists; pub mod category_name_exists_for_store; +pub mod customization_id_exists; +pub mod customization_name_exists_for_product; pub mod errors; pub mod product_id_exists; pub mod product_name_exists_for_category;