fix: ignore deleted categories while checking for category names
This commit is contained in:
parent
cdb055fb42
commit
92219cd4f3
3 changed files with 17 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_inventory_category_query\n WHERE\n name = $1\n AND\n store_id = $2\n );",
|
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_inventory_category_query\n WHERE\n name = $1\n AND\n store_id = $2\n AND\n deleted = false\n );",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
@ -19,5 +19,5 @@
|
||||||
null
|
null
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "5944442c15d28d47654afae92815ccefea89cc9aee705e0e1e54a3bf884bb194"
|
"hash": "7acab15a75b02104059e95c24ade45836ccb6745ff2096f1d4f733b702142ca0"
|
||||||
}
|
}
|
|
@ -19,6 +19,8 @@ impl CategoryNameExistsForStoreDBPort for InventoryDBPostgresAdapter {
|
||||||
name = $1
|
name = $1
|
||||||
AND
|
AND
|
||||||
store_id = $2
|
store_id = $2
|
||||||
|
AND
|
||||||
|
deleted = false
|
||||||
);",
|
);",
|
||||||
s.name(),
|
s.name(),
|
||||||
s.store_id(),
|
s.store_id(),
|
||||||
|
@ -85,6 +87,18 @@ pub mod tests {
|
||||||
// state exists
|
// state exists
|
||||||
assert!(db.category_name_exists_for_store(&category).await.unwrap());
|
assert!(db.category_name_exists_for_store(&category).await.unwrap());
|
||||||
|
|
||||||
|
|
||||||
|
// Set category.deleted = true; now db.category_name_exists_for_store must return false
|
||||||
|
sqlx::query!(
|
||||||
|
"UPDATE cqrs_inventory_category_query SET deleted = true WHERE category_id = $1;",
|
||||||
|
category.category_id(),
|
||||||
|
)
|
||||||
|
.execute(&db.pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert!(!db.category_name_exists_for_store(&category).await.unwrap());
|
||||||
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
settings.drop_db().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ mod tests {
|
||||||
// state exists
|
// state exists
|
||||||
assert!(db.store_name_exists(&store).await.unwrap());
|
assert!(db.store_name_exists(&store).await.unwrap());
|
||||||
|
|
||||||
// Set store.deleted = true; now db.store_id_exists must return false
|
// Set store.deleted = true; now db.store_name_exists must return false
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE cqrs_inventory_store_query SET deleted = true WHERE store_id = $1;",
|
"UPDATE cqrs_inventory_store_query SET deleted = true WHERE store_id = $1;",
|
||||||
store.store_id()
|
store.store_id()
|
||||||
|
|
Loading…
Reference in a new issue