feat: add product against categories #34
1 changed files with 61 additions and 0 deletions
|
@ -0,0 +1,61 @@
|
||||||
|
// 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::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<bool>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type ProductNameExistsForCategoryDBPortObj =
|
||||||
|
std::sync::Arc<dyn ProductNameExistsForCategoryDBPort>;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub fn mock_product_name_exists_for_category_db_port_false(
|
||||||
|
times: Option<usize>,
|
||||||
|
) -> 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<usize>,
|
||||||
|
) -> 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue