Test create product variant
This commit is contained in:
parent
3cf6cfb2e5
commit
59034ea1e0
@ -993,6 +993,7 @@ pub mod v2 {
|
||||
RecordId, StockId, UniqueName,
|
||||
};
|
||||
|
||||
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
||||
#[cfg_attr(feature = "db", derive(sqlx::Type))]
|
||||
#[cfg_attr(feature = "db", sqlx(transparent))]
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)]
|
||||
@ -1023,7 +1024,7 @@ pub mod v2 {
|
||||
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DetailedProductVariant {
|
||||
pub id: ProductVariantId,
|
||||
pub name: ProductName,
|
||||
pub name: ProductVariantName,
|
||||
pub short_description: ProductShortDesc,
|
||||
pub long_description: ProductLongDesc,
|
||||
pub price: Price,
|
||||
@ -1058,7 +1059,7 @@ pub mod v2 {
|
||||
pub struct ProductVariant {
|
||||
pub id: ProductVariantId,
|
||||
pub product_id: ProductId,
|
||||
pub name: ProductName,
|
||||
pub name: ProductVariantName,
|
||||
pub short_description: ProductShortDesc,
|
||||
pub long_description: ProductLongDesc,
|
||||
pub price: Price,
|
||||
|
@ -15,7 +15,7 @@ pub async fn create_product(
|
||||
) -> create_product::Output {
|
||||
let mut t = begin_t!(db, Error::InternalServerError);
|
||||
|
||||
match inner_create_product(input, &mut t, Some(_config)).await {
|
||||
match inner_create_product(input, &mut t).await {
|
||||
Ok(res) => {
|
||||
if let Err(e) = t.commit().await {
|
||||
tracing::error!("{}", e);
|
||||
@ -36,7 +36,6 @@ pub async fn create_product(
|
||||
async fn inner_create_product(
|
||||
input: create_product::Input,
|
||||
t: &mut PgT<'_>,
|
||||
_config: Option<SharedAppConfig>,
|
||||
) -> create_product::Output {
|
||||
use create_product::*;
|
||||
|
||||
@ -92,7 +91,7 @@ async fn inner_create_product(
|
||||
deliver_days_flag: product.deliver_days_flag,
|
||||
variants: vec![DetailedProductVariant {
|
||||
id: variant.id,
|
||||
name: variant.name,
|
||||
name: ProductVariantName::new(variant.name.as_str()),
|
||||
short_description: variant.short_description,
|
||||
long_description: variant.long_description,
|
||||
price: variant.price,
|
||||
@ -193,7 +192,6 @@ mod tests {
|
||||
},
|
||||
},
|
||||
t,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
@ -221,7 +219,6 @@ mod tests {
|
||||
},
|
||||
},
|
||||
&mut t,
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -72,3 +72,61 @@ pub async fn delete_product_variant(
|
||||
) -> delete_product_variant::Output {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use channels::stocks::create_product_variant;
|
||||
use config::UpdateConfig;
|
||||
use db_utils::PgT;
|
||||
use model::v2::*;
|
||||
|
||||
use crate::actions::product_variant::inner_create_product_variant;
|
||||
use crate::db::Database;
|
||||
|
||||
struct NoOpts;
|
||||
impl UpdateConfig for NoOpts {}
|
||||
|
||||
async fn test_product(t: &mut PgT<'_>) -> Product {
|
||||
crate::db::CreateProduct {
|
||||
name: ProductName::new(format!("{}", uuid::Uuid::new_v4())),
|
||||
category: None,
|
||||
deliver_days_flag: Days(vec![]),
|
||||
}
|
||||
.run(t)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_product_variant() {
|
||||
testx::db_t_ref!(t);
|
||||
|
||||
let name = ProductVariantName::new(format!("{}", uuid::Uuid::new_v4()));
|
||||
let short_description = ProductShortDesc::new(format!("{}", uuid::Uuid::new_v4()));
|
||||
let long_description = ProductLongDesc::new(format!("{}", uuid::Uuid::new_v4()));
|
||||
let price = Price::from_u32(234234);
|
||||
|
||||
let product = test_product(&mut t).await;
|
||||
|
||||
let res = inner_create_product_variant(
|
||||
create_product_variant::Input {
|
||||
product_id: product.id,
|
||||
name: name.clone(),
|
||||
short_description: short_description.clone(),
|
||||
long_description: long_description.clone(),
|
||||
price,
|
||||
},
|
||||
&mut t,
|
||||
)
|
||||
.await;
|
||||
|
||||
testx::db_rollback!(t);
|
||||
|
||||
let variant = res.unwrap().product_variant;
|
||||
|
||||
assert_eq!(variant.name, name);
|
||||
assert_eq!(variant.short_description, short_description);
|
||||
assert_eq!(variant.long_description, long_description);
|
||||
assert_eq!(variant.price, price);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user