feat: check for Customization constraint violation #43
2 changed files with 7 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use mockall::predicate::*;
|
use mockall::predicate::*;
|
||||||
use mockall::*;
|
use mockall::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::inventory::domain::product_aggregate::Customization;
|
use crate::inventory::domain::product_aggregate::Customization;
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ pub trait CustomizationNameExistsForProductDBPort: Send + Sync {
|
||||||
async fn customization_name_exists_for_product(
|
async fn customization_name_exists_for_product(
|
||||||
&self,
|
&self,
|
||||||
c: &Customization,
|
c: &Customization,
|
||||||
|
product_id: &Uuid,
|
||||||
) -> InventoryDBResult<bool>;
|
) -> InventoryDBResult<bool>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,10 +39,10 @@ pub mod tests {
|
||||||
if let Some(times) = times {
|
if let Some(times) = times {
|
||||||
m.expect_customization_name_exists_for_product()
|
m.expect_customization_name_exists_for_product()
|
||||||
.times(times)
|
.times(times)
|
||||||
.returning(|_| Ok(false));
|
.returning(|_, _| Ok(false));
|
||||||
} else {
|
} else {
|
||||||
m.expect_customization_name_exists_for_product()
|
m.expect_customization_name_exists_for_product()
|
||||||
.returning(|_| Ok(false));
|
.returning(|_, _| Ok(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(m)
|
Arc::new(m)
|
||||||
|
@ -53,10 +55,10 @@ pub mod tests {
|
||||||
if let Some(times) = times {
|
if let Some(times) = times {
|
||||||
m.expect_customization_name_exists_for_product()
|
m.expect_customization_name_exists_for_product()
|
||||||
.times(times)
|
.times(times)
|
||||||
.returning(|_| Ok(true));
|
.returning(|_, _| Ok(true));
|
||||||
} else {
|
} else {
|
||||||
m.expect_customization_name_exists_for_product()
|
m.expect_customization_name_exists_for_product()
|
||||||
.returning(|_| Ok(true));
|
.returning(|_, _| Ok(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(m)
|
Arc::new(m)
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl AddProductUseCase for AddProductService {
|
||||||
|
|
||||||
if self
|
if self
|
||||||
.db_customization_name_exists_for_product
|
.db_customization_name_exists_for_product
|
||||||
.customization_name_exists_for_product(&customization)
|
.customization_name_exists_for_product(&customization, &product_id)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
return Err(InventoryError::DuplicateCustomizationName);
|
return Err(InventoryError::DuplicateCustomizationName);
|
||||||
|
|
Loading…
Reference in a new issue