feat: define customization duplicate name check DB port

This commit is contained in:
Aravinth Manivannan 2024-07-16 11:17:25 +05:30
parent 4c2cec1e7f
commit 5937d7a0fd
Signed by: realaravinth
GPG key ID: F8F50389936984FF
2 changed files with 66 additions and 0 deletions

View file

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

View file

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