Test update product
This commit is contained in:
parent
1dc484b1c9
commit
3cf6cfb2e5
@ -111,7 +111,7 @@ pub async fn update_product(
|
|||||||
) -> update_product::Output {
|
) -> update_product::Output {
|
||||||
let mut t = begin_t!(db, Error::InternalServerError);
|
let mut t = begin_t!(db, Error::InternalServerError);
|
||||||
|
|
||||||
let res = inner_update_product(input, &mut t, Some(_config)).await;
|
let res = inner_update_product(input, &mut t).await;
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
@ -138,7 +138,6 @@ pub async fn update_product(
|
|||||||
async fn inner_update_product(
|
async fn inner_update_product(
|
||||||
input: update_product::Input,
|
input: update_product::Input,
|
||||||
t: &mut PgT<'_>,
|
t: &mut PgT<'_>,
|
||||||
_config: Option<SharedAppConfig>,
|
|
||||||
) -> update_product::Output {
|
) -> update_product::Output {
|
||||||
let dbm = crate::db::UpdateProduct {
|
let dbm = crate::db::UpdateProduct {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
@ -176,6 +175,31 @@ mod tests {
|
|||||||
|
|
||||||
impl UpdateConfig for NoOpts {}
|
impl UpdateConfig for NoOpts {}
|
||||||
|
|
||||||
|
async fn test_product_with_variant(t: &mut PgT<'_>) -> DetailedProduct {
|
||||||
|
inner_create_product(
|
||||||
|
create_product::Input {
|
||||||
|
product: create_product::ProductInput {
|
||||||
|
name: ProductName::new(format!("{}", uuid::Uuid::new_v4())),
|
||||||
|
variant_name: Some(ProductVariantName::new("variant")),
|
||||||
|
short_description: ProductShortDesc::new("desc"),
|
||||||
|
long_description: ProductLongDesc::new("long description"),
|
||||||
|
category: None,
|
||||||
|
price: Default::default(),
|
||||||
|
deliver_days_flag: Days(vec![]),
|
||||||
|
},
|
||||||
|
stock: create_product::StockInput {
|
||||||
|
quantity: Default::default(),
|
||||||
|
quantity_unit: QuantityUnit::Gram,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
t,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.product
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn create_product() {
|
async fn create_product() {
|
||||||
testx::db_t_ref!(t);
|
testx::db_t_ref!(t);
|
||||||
@ -205,4 +229,29 @@ mod tests {
|
|||||||
|
|
||||||
res.unwrap();
|
res.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn update_product() {
|
||||||
|
testx::db_t_ref!(t);
|
||||||
|
|
||||||
|
let product = test_product_with_variant(&mut t).await;
|
||||||
|
|
||||||
|
let new_name = ProductName::new(format!("{}", uuid::Uuid::new_v4()));
|
||||||
|
let res = inner_update_product(
|
||||||
|
update_product::Input {
|
||||||
|
id: product.id,
|
||||||
|
name: new_name.clone(),
|
||||||
|
category: None,
|
||||||
|
deliver_days_flag: Days(vec![]),
|
||||||
|
},
|
||||||
|
&mut t,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
testx::db_rollback!(t);
|
||||||
|
|
||||||
|
let new_product = res.unwrap().product;
|
||||||
|
assert_eq!(new_product.id, product.id);
|
||||||
|
assert_eq!(new_product.name, new_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user