diff --git a/crates/model/src/api.rs b/crates/model/src/api.rs index 2199fa7..ad49658 100644 --- a/crates/model/src/api.rs +++ b/crates/model/src/api.rs @@ -102,7 +102,6 @@ impl From for AccountAddress { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug)] #[serde(transparent)] pub struct Orders(pub Vec); @@ -163,7 +162,6 @@ impl From<(crate::Order, Vec)> for Order { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug)] pub struct Order { pub id: crate::OrderId, @@ -174,7 +172,6 @@ pub struct Order { pub address_id: OrderAddressId, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug)] pub struct ShoppingCartItem { pub id: ShoppingCartItemId, @@ -204,7 +201,6 @@ impl From for ShoppingCartItem { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug)] pub struct ShoppingCart { pub id: ShoppingCartId, @@ -256,7 +252,6 @@ impl From<(crate::ShoppingCart, Vec)> for ShoppingCart } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug, Hash)] pub struct Photo { pub id: crate::PhotoId, @@ -265,7 +260,6 @@ pub struct Photo { pub unique_name: crate::UniqueName, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub struct Category { @@ -284,7 +278,6 @@ impl From<&crate::Category> for Category { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug, Hash)] pub struct Product { pub id: crate::ProductId, @@ -374,7 +367,6 @@ impl<'path> } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Serialize, Deserialize, Debug, Deref)] #[serde(transparent)] pub struct Products(pub Vec); diff --git a/crates/model/src/dummy.rs b/crates/model/src/dummy.rs deleted file mode 100644 index 3740e9d..0000000 --- a/crates/model/src/dummy.rs +++ /dev/null @@ -1,127 +0,0 @@ -use fake::faker::internet::en::{FreeEmail, Password as FakePass, Username}; -use fake::faker::phone_number::en::PhoneNumber; -use fake::Fake; - -use crate::*; - -impl fake::Dummy for Login { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - Self(Username().fake()) - } -} - -impl fake::Dummy for Email { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - Self(FreeEmail().fake()) - } -} - -impl fake::Dummy for Phone { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - Self(PhoneNumber().fake()) - } -} - -impl fake::Dummy for ProductShortDesc { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::lorem::en::Words; - let words: Vec = Words(5..20).fake(); - Self(words.join(" ")) - } -} - -impl fake::Dummy for ProductLongDesc { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::lorem::en::Paragraphs; - let words: Vec = (3..5) - .into_iter() - .map(|_| { - let words: Vec = Paragraphs(4..8).fake(); - words.join(" ") - }) - .collect(); - Self(words.join("\n")) - } -} - -impl fake::Dummy for Password { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - let pass: String = FakePass(6..20).fake(); - Self(pass) - } -} - -impl fake::Dummy for PassHash { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - let pass: Password = fake::Faker.fake(); - Self( - pass.encrypt( - &password_hash::SaltString::new("a7sydd98asd98ahsda9shdahd98ahsd9aysd9aysd9y") - .unwrap(), - ) - .unwrap(), - ) - } -} - -impl fake::Dummy for ProductName { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::lorem::en::Words; - let name: Vec = Words(5..8).fake(); - Self(name.join(" ")) - } -} - -impl fake::Dummy for Price { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - let price = rand::random::() as i32 * 100i32 + rand::random::() as i32; - - let price: i32 = price as i32; - Self(NonNegative(price)) - } -} - -impl fake::Dummy for NonNegative { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - let price = rand::random::() as i32 * 100i32 + rand::random::() as i32; - - let price: i32 = price as i32; - Self(price) - } -} - -impl fake::Dummy for crate::Name { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::name::raw::*; - use fake::locales::*; - Self(Name(EN).fake()) - } -} -impl fake::Dummy for crate::Street { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::address::raw::*; - use fake::locales::*; - Self(StreetName(EN).fake()) - } -} -impl fake::Dummy for crate::City { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::address::raw::*; - use fake::locales::*; - Self(CityName(EN).fake()) - } -} -impl fake::Dummy for crate::Country { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::address::raw::*; - use fake::locales::*; - Self(CountryName(EN).fake()) - } -} -impl fake::Dummy for crate::Zip { - fn dummy_with_rng(_config: &T, _rng: &mut R) -> Self { - use fake::faker::address::raw::*; - use fake::locales::*; - Self(ZipCode(EN).fake()) - } -} diff --git a/crates/model/src/lib.rs b/crates/model/src/lib.rs index f3e14a4..91c9086 100644 --- a/crates/model/src/lib.rs +++ b/crates/model/src/lib.rs @@ -2,8 +2,6 @@ pub mod api; -#[cfg(feature = "dummy")] -mod dummy; pub mod encrypt; use std::fmt::{Display, Formatter}; @@ -124,7 +122,6 @@ pub const CATEGORIES: [Category; 9] = [ }, ]; -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(rename_all = "snake_case"))] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Display, Deserialize, Serialize)] @@ -144,7 +141,6 @@ pub enum OrderStatus { Refunded, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(rename_all = "snake_case"))] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Display, Deserialize, Serialize)] @@ -171,7 +167,6 @@ impl Role { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Display, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] @@ -206,7 +201,6 @@ impl QuantityUnit { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(rename_all = "snake_case"))] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Display, Deserialize, Serialize)] @@ -222,7 +216,6 @@ impl Default for PaymentMethod { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(rename_all = "snake_case"))] #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Display, Deserialize, Serialize)] @@ -232,7 +225,6 @@ pub enum ShoppingCartState { Closed, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(rename_all = "snake_case"))] #[derive(Copy, Clone, Debug, Hash, Display, Deserialize, Serialize, PartialEq, Eq)] @@ -261,7 +253,6 @@ impl Audience { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(rename_all = "snake_case"))] #[derive(Copy, Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)] @@ -394,7 +385,6 @@ impl Offset { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, Copy, Clone, Hash, Deref, From)] @@ -632,7 +622,6 @@ impl<'de> serde::Deserialize<'de> for NonNegative { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive( Debug, Copy, Clone, Hash, PartialOrd, PartialEq, Eq, Serialize, Deserialize, Display, From, )] @@ -704,7 +693,6 @@ impl TryFrom for Day { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[derive(Hash, Debug, PartialOrd, PartialEq, Eq, Serialize, Deserialize)] #[serde(transparent)] pub struct Days(pub Vec); @@ -801,7 +789,6 @@ impl Password { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Serialize, Deserialize, Debug, Clone, Deref, From, Display)] @@ -832,7 +819,6 @@ impl PartialEq for Password { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive( @@ -841,7 +827,6 @@ impl PartialEq for Password { #[serde(transparent)] pub struct AccountId(RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct FullAccount { @@ -854,7 +839,6 @@ pub struct FullAccount { pub state: AccountState, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Serialize, Deserialize, Debug)] pub struct Account { @@ -889,7 +873,6 @@ impl From for Account { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Deref, From)] @@ -964,7 +947,6 @@ impl ProductLongDesc { } } -#[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)] @@ -1013,7 +995,6 @@ pub mod v2 { } } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Deref, From)] @@ -1023,7 +1004,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, @@ -1042,7 +1023,6 @@ pub mod v2 { pub variants: Vec, } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct Product { @@ -1052,19 +1032,17 @@ pub mod v2 { pub deliver_days_flag: Days, } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] 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, } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Stock { @@ -1074,7 +1052,6 @@ pub mod v2 { pub quantity_unit: QuantityUnit, } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct Photo { @@ -1084,7 +1061,6 @@ pub mod v2 { pub unique_name: UniqueName, } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct ProductLinkedPhoto { @@ -1095,7 +1071,6 @@ pub mod v2 { pub product_variant_id: ProductVariantId, } - #[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ProductPhoto { @@ -1105,7 +1080,6 @@ pub mod v2 { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct Product { @@ -1118,14 +1092,12 @@ pub struct Product { pub deliver_days_flag: Days, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)] #[serde(transparent)] pub struct StockId(pub RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Stock { @@ -1135,21 +1107,18 @@ pub struct Stock { pub quantity_unit: QuantityUnit, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Display, Deref)] #[serde(transparent)] pub struct OrderAddressId(RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Display, Deref)] #[serde(transparent)] pub struct OrderId(RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Display, Deref)] @@ -1166,7 +1135,6 @@ impl ExtOrderId { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Order { @@ -1185,7 +1153,6 @@ pub struct Order { pub address_id: OrderAddressId, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Serialize, Deserialize)] pub struct PublicOrder { @@ -1218,13 +1185,11 @@ impl From for PublicOrder { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Deref)] pub struct OrderItemId(pub RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct OrderItem { @@ -1235,14 +1200,12 @@ pub struct OrderItem { pub quantity_unit: QuantityUnit, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Debug, Deref, Display)] #[serde(transparent)] pub struct ShoppingCartId(pub RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ShoppingCart { @@ -1253,7 +1216,6 @@ pub struct ShoppingCart { pub checkout_notes: Option, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(PartialEq, Eq, Copy, Clone, Debug, Serialize, Deserialize, Deref, Display)] @@ -1276,14 +1238,12 @@ impl ShoppingCartItem { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, Deref, Display, Debug)] #[serde(transparent)] pub struct TokenId(RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Token { @@ -1315,7 +1275,6 @@ impl Token { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)] @@ -1333,7 +1292,6 @@ impl From for AccessTokenString { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)] @@ -1351,7 +1309,6 @@ impl RefreshTokenString { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)] @@ -1363,7 +1320,6 @@ impl LocalPath { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)] @@ -1375,7 +1331,6 @@ impl UniqueName { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)] @@ -1387,7 +1342,6 @@ impl FileName { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive( @@ -1406,13 +1360,11 @@ impl FileName { )] pub struct PhotoId(RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Deref, Display, From)] pub struct ProductPhotoId(RecordId); -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct Photo { @@ -1422,7 +1374,6 @@ pub struct Photo { pub unique_name: UniqueName, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct ProductLinkedPhoto { @@ -1433,7 +1384,6 @@ pub struct ProductLinkedPhoto { pub product_id: ProductId, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct ProductPhoto { @@ -1442,7 +1392,6 @@ pub struct ProductPhoto { pub photo_id: PhotoId, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "snake_case")] @@ -1453,7 +1402,6 @@ pub enum ShippingMethod { Manual, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::Type))] #[cfg_attr(feature = "db", sqlx(transparent))] #[derive( @@ -1603,7 +1551,6 @@ impl Zip { } } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] pub struct AccountAddress { @@ -1619,7 +1566,6 @@ pub struct AccountAddress { pub is_default: bool, } -#[cfg_attr(feature = "dummy", derive(fake::Dummy))] #[cfg_attr(feature = "db", derive(sqlx::FromRow))] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct OrderAddress { diff --git a/crates/stock_manager/src/actions/product.rs b/crates/stock_manager/src/actions/product.rs index c1bda09..c4faeb1 100644 --- a/crates/stock_manager/src/actions/product.rs +++ b/crates/stock_manager/src/actions/product.rs @@ -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, ) -> 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, @@ -111,7 +110,7 @@ pub async fn update_product( ) -> update_product::Output { 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 { Ok(res) => { @@ -138,7 +137,6 @@ pub async fn update_product( async fn inner_update_product( input: update_product::Input, t: &mut PgT<'_>, - _config: Option, ) -> update_product::Output { let dbm = crate::db::UpdateProduct { id: input.id, @@ -208,6 +206,30 @@ mod tests { 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, + ) + .await + .unwrap() + .product + } + #[tokio::test] async fn create_product() { testx::db_t_ref!(t); @@ -229,7 +251,6 @@ mod tests { }, }, &mut t, - None, ) .await; @@ -237,4 +258,29 @@ mod tests { 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); + } } diff --git a/crates/stock_manager/src/actions/product_variant.rs b/crates/stock_manager/src/actions/product_variant.rs index 7476a20..4654384 100644 --- a/crates/stock_manager/src/actions/product_variant.rs +++ b/crates/stock_manager/src/actions/product_variant.rs @@ -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); + } +}