feat: define product ID exists DB port
This commit is contained in:
parent
6158779995
commit
f6f3834ba1
2 changed files with 55 additions and 0 deletions
|
@ -5,5 +5,7 @@
|
||||||
pub mod category_id_exists;
|
pub mod category_id_exists;
|
||||||
pub mod category_name_exists_for_store;
|
pub mod category_name_exists_for_store;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
pub mod product_id_exists;
|
||||||
|
pub mod product_name_exists_for_category;
|
||||||
pub mod store_id_exists;
|
pub mod store_id_exists;
|
||||||
pub mod store_name_exists;
|
pub mod store_name_exists;
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use mockall::predicate::*;
|
||||||
|
use mockall::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use super::errors::*;
|
||||||
|
#[cfg(test)]
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
pub use tests::*;
|
||||||
|
|
||||||
|
#[automock]
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait ProductIDExistsDBPort: Send + Sync {
|
||||||
|
async fn product_id_exists(&self, c: &Uuid) -> InventoryDBResult<bool>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type ProductIDExistsDBPortObj = std::sync::Arc<dyn ProductIDExistsDBPort>;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub fn mock_product_id_exists_db_port_false(times: Option<usize>) -> ProductIDExistsDBPortObj {
|
||||||
|
let mut m = MockProductIDExistsDBPort::new();
|
||||||
|
if let Some(times) = times {
|
||||||
|
m.expect_product_id_exists()
|
||||||
|
.times(times)
|
||||||
|
.returning(|_| Ok(false));
|
||||||
|
} else {
|
||||||
|
m.expect_product_id_exists().returning(|_| Ok(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
Arc::new(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mock_product_id_exists_db_port_true(times: Option<usize>) -> ProductIDExistsDBPortObj {
|
||||||
|
let mut m = MockProductIDExistsDBPort::new();
|
||||||
|
if let Some(times) = times {
|
||||||
|
m.expect_product_id_exists()
|
||||||
|
.times(times)
|
||||||
|
.returning(|_| Ok(true));
|
||||||
|
} else {
|
||||||
|
m.expect_product_id_exists().returning(|_| Ok(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
Arc::new(m)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue