fix: use product ID from customization obj
This commit is contained in:
parent
7c416feacd
commit
feaab33d33
3 changed files with 9 additions and 11 deletions
|
@ -14,7 +14,6 @@ impl CustomizationNameExistsForProductDBPort for InventoryDBPostgresAdapter {
|
||||||
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> {
|
||||||
let res = sqlx::query!(
|
let res = sqlx::query!(
|
||||||
"SELECT EXISTS (
|
"SELECT EXISTS (
|
||||||
|
@ -28,7 +27,7 @@ impl CustomizationNameExistsForProductDBPort for InventoryDBPostgresAdapter {
|
||||||
deleted = false
|
deleted = false
|
||||||
);",
|
);",
|
||||||
c.name(),
|
c.name(),
|
||||||
product_id,
|
c.product_id()
|
||||||
)
|
)
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -71,7 +70,7 @@ mod tests {
|
||||||
|
|
||||||
// state doesn't exist
|
// state doesn't exist
|
||||||
assert!(!db
|
assert!(!db
|
||||||
.customization_name_exists_for_product(&customization, &product_id)
|
.customization_name_exists_for_product(&customization)
|
||||||
.await
|
.await
|
||||||
.unwrap());
|
.unwrap());
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ mod tests {
|
||||||
|
|
||||||
// state exists
|
// state exists
|
||||||
assert!(db
|
assert!(db
|
||||||
.customization_name_exists_for_product(&customization, &product_id)
|
.customization_name_exists_for_product(&customization)
|
||||||
.await
|
.await
|
||||||
.unwrap());
|
.unwrap());
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!db
|
assert!(!db
|
||||||
.customization_name_exists_for_product(&customization, &product_id)
|
.customization_name_exists_for_product(&customization)
|
||||||
.await
|
.await
|
||||||
.unwrap());
|
.unwrap());
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ 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>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,10 +38,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)
|
||||||
|
@ -55,10 +54,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)
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl AddCustomizationUseCase for AddCustomizationService {
|
||||||
|
|
||||||
if self
|
if self
|
||||||
.db_customization_name_exists_for_product
|
.db_customization_name_exists_for_product
|
||||||
.customization_name_exists_for_product(&customization, cmd.product_id())
|
.customization_name_exists_for_product(&customization)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
return Err(InventoryError::DuplicateCustomizationName);
|
return Err(InventoryError::DuplicateCustomizationName);
|
||||||
|
|
Loading…
Reference in a new issue