feat: add product against categories #34

Merged
realaravinth merged 10 commits from add-product into master 2024-07-15 18:21:13 +05:30
Showing only changes of commit a3a947fd89 - Show all commits

View file

@ -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)
}
}