diff --git a/src/inventory/application/port/output/db/product_name_exists_for_category.rs b/src/inventory/application/port/output/db/product_name_exists_for_category.rs new file mode 100644 index 0000000..222faf7 --- /dev/null +++ b/src/inventory/application/port/output/db/product_name_exists_for_category.rs @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use mockall::predicate::*; +use mockall::*; + +use crate::inventory::domain::product_aggregate::Product; + +use super::errors::*; +#[cfg(test)] +#[allow(unused_imports)] +pub use tests::*; + +#[automock] +#[async_trait::async_trait] +pub trait ProductNameExistsForCategoryDBPort: Send + Sync { + async fn product_name_exists_for_category(&self, c: &Product) -> InventoryDBResult; +} + +pub type ProductNameExistsForCategoryDBPortObj = + std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_product_name_exists_for_category_db_port_false( + times: Option, + ) -> ProductNameExistsForCategoryDBPortObj { + let mut m = MockProductNameExistsForCategoryDBPort::new(); + if let Some(times) = times { + m.expect_product_name_exists_for_category() + .times(times) + .returning(|_| Ok(false)); + } else { + m.expect_product_name_exists_for_category() + .returning(|_| Ok(false)); + } + + Arc::new(m) + } + + pub fn mock_product_name_exists_for_category_db_port_true( + times: Option, + ) -> ProductNameExistsForCategoryDBPortObj { + let mut m = MockProductNameExistsForCategoryDBPort::new(); + if let Some(times) = times { + m.expect_product_name_exists_for_category() + .times(times) + .returning(|_| Ok(true)); + } else { + m.expect_product_name_exists_for_category() + .returning(|_| Ok(true)); + } + + Arc::new(m) + } +}