feat: check for Customization constraint violation #43

Merged
realaravinth merged 7 commits from customize-products into master 2024-07-16 11:42:37 +05:30
Showing only changes of commit 4c2cec1e7f - Show all commits

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