diff --git a/src/identity/application/port/output/db/errors.rs b/src/identity/application/port/output/db/errors.rs index 93df497..4b4eeb7 100644 --- a/src/identity/application/port/output/db/errors.rs +++ b/src/identity/application/port/output/db/errors.rs @@ -18,4 +18,7 @@ pub enum OutDBPortError { PhoneNumberNotFound, EmpLoginOTPNotFound, EmpVerificationOTPNotFound, + DuplicateStoreName, + DuplicateStoreID, + StoreIDNotFound, } diff --git a/src/identity/application/port/output/db/mod.rs b/src/identity/application/port/output/db/mod.rs index b6f884d..ad3bc00 100644 --- a/src/identity/application/port/output/db/mod.rs +++ b/src/identity/application/port/output/db/mod.rs @@ -19,6 +19,7 @@ pub mod get_verification_secret; pub mod invite_id_exists; pub mod phone_exists; pub mod store_id_exists; +pub mod store_name_exists; pub mod user_id_exists; //pub mod verification_otp_exists; pub mod verification_secret_exists; diff --git a/src/identity/application/port/output/db/store_name_exists.rs b/src/identity/application/port/output/db/store_name_exists.rs new file mode 100644 index 0000000..bf0d9d9 --- /dev/null +++ b/src/identity/application/port/output/db/store_name_exists.rs @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use mockall::predicate::*; +use mockall::*; + +use crate::identity::domain::store_aggregate::Store; + +use super::errors::*; +#[cfg(test)] +#[allow(unused_imports)] +pub use tests::*; + +#[automock] +#[async_trait::async_trait] +pub trait StoreNameExistsDBPort: Send + Sync { + async fn store_name_exists(&self, s: &Store) -> OutDBPortResult; +} + +pub type StoreNameExistsDBPortObj = std::sync::Arc; + +#[cfg(test)] +pub mod tests { + use super::*; + + use std::sync::Arc; + + pub fn mock_store_name_exists_db_port_false(times: Option) -> StoreNameExistsDBPortObj { + let mut m = MockStoreNameExistsDBPort::new(); + if let Some(times) = times { + m.expect_store_name_exists() + .times(times) + .returning(|_| Ok(false)); + } else { + m.expect_store_name_exists().returning(|_| Ok(false)); + } + + Arc::new(m) + } + + pub fn mock_store_name_exists_db_port_true(times: Option) -> StoreNameExistsDBPortObj { + let mut m = MockStoreNameExistsDBPort::new(); + if let Some(times) = times { + m.expect_store_name_exists() + .times(times) + .returning(|_| Ok(true)); + } else { + m.expect_store_name_exists().returning(|_| Ok(true)); + } + + Arc::new(m) + } +}