From f6f3834ba1136f234824cb0b61c3162a24e41a5b Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Mon, 15 Jul 2024 17:48:26 +0530 Subject: [PATCH] feat: define product ID exists DB port --- .../application/port/output/db/mod.rs | 2 + .../port/output/db/product_id_exists.rs | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/inventory/application/port/output/db/product_id_exists.rs diff --git a/src/inventory/application/port/output/db/mod.rs b/src/inventory/application/port/output/db/mod.rs index d5741ec..599269b 100644 --- a/src/inventory/application/port/output/db/mod.rs +++ b/src/inventory/application/port/output/db/mod.rs @@ -5,5 +5,7 @@ pub mod category_id_exists; pub mod category_name_exists_for_store; pub mod errors; +pub mod product_id_exists; +pub mod product_name_exists_for_category; pub mod store_id_exists; pub mod store_name_exists; diff --git a/src/inventory/application/port/output/db/product_id_exists.rs b/src/inventory/application/port/output/db/product_id_exists.rs new file mode 100644 index 0000000..ba3675f --- /dev/null +++ b/src/inventory/application/port/output/db/product_id_exists.rs @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use mockall::predicate::*; +use mockall::*; +use uuid::Uuid; + +use super::errors::*; +#[cfg(test)] +#[allow(unused_imports)] +pub use tests::*; + +#[automock] +#[async_trait::async_trait] +pub trait ProductIDExistsDBPort: Send + Sync { + async fn product_id_exists(&self, c: &Uuid) -> InventoryDBResult; +} + +pub type ProductIDExistsDBPortObj = std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_product_id_exists_db_port_false(times: Option) -> ProductIDExistsDBPortObj { + let mut m = MockProductIDExistsDBPort::new(); + if let Some(times) = times { + m.expect_product_id_exists() + .times(times) + .returning(|_| Ok(false)); + } else { + m.expect_product_id_exists().returning(|_| Ok(false)); + } + + Arc::new(m) + } + + pub fn mock_product_id_exists_db_port_true(times: Option) -> ProductIDExistsDBPortObj { + let mut m = MockProductIDExistsDBPort::new(); + if let Some(times) = times { + m.expect_product_id_exists() + .times(times) + .returning(|_| Ok(true)); + } else { + m.expect_product_id_exists().returning(|_| Ok(true)); + } + + Arc::new(m) + } +}