feat: define store_name_exists port for identity

This commit is contained in:
Aravinth Manivannan 2025-01-09 01:16:17 +05:30
parent 176e9ff6f6
commit e52530f0e3
Signed by: realaravinth
GPG key ID: F8F50389936984FF
3 changed files with 58 additions and 0 deletions

View file

@ -18,4 +18,7 @@ pub enum OutDBPortError {
PhoneNumberNotFound,
EmpLoginOTPNotFound,
EmpVerificationOTPNotFound,
DuplicateStoreName,
DuplicateStoreID,
StoreIDNotFound,
}

View file

@ -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;

View file

@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// 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<bool>;
}
pub type StoreNameExistsDBPortObj = std::sync::Arc<dyn StoreNameExistsDBPort>;
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_store_name_exists_db_port_false(times: Option<usize>) -> 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<usize>) -> 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)
}
}