feat: define customization ID check DB port

This commit is contained in:
Aravinth Manivannan 2024-07-16 11:17:11 +05:30
parent 85dabf644c
commit 4c2cec1e7f
Signed by: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -0,0 +1,57 @@
// 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 CustomizationIDExistsDBPort: Send + Sync {
async fn customization_id_exists(&self, c: &Uuid) -> InventoryDBResult<bool>;
}
pub type CustomizationIDExistsDBPortObj = std::sync::Arc<dyn CustomizationIDExistsDBPort>;
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_customization_id_exists_db_port_false(
times: Option<usize>,
) -> CustomizationIDExistsDBPortObj {
let mut m = MockCustomizationIDExistsDBPort::new();
if let Some(times) = times {
m.expect_customization_id_exists()
.times(times)
.returning(|_| Ok(false));
} else {
m.expect_customization_id_exists().returning(|_| Ok(false));
}
Arc::new(m)
}
pub fn mock_customization_id_exists_db_port_true(
times: Option<usize>,
) -> CustomizationIDExistsDBPortObj {
let mut m = MockCustomizationIDExistsDBPort::new();
if let Some(times) = times {
m.expect_customization_id_exists()
.times(times)
.returning(|_| Ok(true));
} else {
m.expect_customization_id_exists().returning(|_| Ok(true));
}
Arc::new(m)
}
}