chore: clippy lints
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2024-07-16 11:50:49 +05:30
parent d707051e72
commit cb5bb703e1
Signed by: realaravinth
GPG key ID: F8F50389936984FF
38 changed files with 187 additions and 261 deletions

View file

@ -42,7 +42,7 @@ mod tests {
let msg = CreateSecretMsgBuilder::default()
.secret("secret".into())
.user_id(UUID.clone())
.user_id(UUID)
.build()
.unwrap();

View file

@ -49,7 +49,7 @@ mod tests {
.unwrap(),
);
let msg = VerifySecretExistsMsgBuilder::default()
.user_id(user_id.clone())
.user_id(user_id)
.secret(secret.into())
.build()
.unwrap();
@ -59,7 +59,7 @@ mod tests {
let create_msg = CreateSecretMsgBuilder::default()
.secret(secret.into())
.user_id(user_id.clone())
.user_id(user_id)
.build()
.unwrap();
db.create_verification_secret(create_msg).await.unwrap();

View file

@ -60,7 +60,7 @@ mod tests {
let create_msg = CreateSecretMsgBuilder::default()
.secret(secret.into())
.user_id(user_id.clone())
.user_id(user_id)
.build()
.unwrap();

View file

@ -45,7 +45,7 @@ impl View<User> for UserView {
self.deleted = false;
self.first_name = val.first_name().into();
self.last_name = val.last_name().into();
self.user_id = val.user_id().clone();
self.user_id = *val.user_id();
}
UserEvent::UserDeleted => self.deleted = true,
UserEvent::Loggedin(_) => (),

View file

@ -56,7 +56,7 @@ mod tests {
.unwrap(),
);
let msg = VerifySecretExistsMsgBuilder::default()
.user_id(user_id.clone())
.user_id(user_id)
.secret(secret.into())
.build()
.unwrap();
@ -66,7 +66,7 @@ mod tests {
let create_msg = CreateSecretMsgBuilder::default()
.secret(secret.into())
.user_id(user_id.clone())
.user_id(user_id)
.build()
.unwrap();
db.create_verification_secret(create_msg).await.unwrap();

View file

@ -29,7 +29,7 @@ mod tests {
fn test_cmd() {
let user_id = UUID;
let secret = "asdfasdf";
let cmd = MarkUserVerifiedCommand::new(user_id.clone(), secret.into()).unwrap();
let cmd = MarkUserVerifiedCommand::new(user_id, secret.into()).unwrap();
assert_eq!(cmd.user_id(), &user_id);
assert_eq!(cmd.secret(), secret);
}

View file

@ -22,7 +22,7 @@ impl MarkUserVerifiedUseCase for MarkUserVerifiedService {
cmd: command::MarkUserVerifiedCommand,
) -> IdentityResult<()> {
let msg = VerifySecretExistsMsgBuilder::default()
.user_id(cmd.user_id().clone())
.user_id(*cmd.user_id())
.secret(cmd.secret().into())
.build()
.unwrap();
@ -54,7 +54,7 @@ mod tests {
async fn test_service() {
let user_id = UUID;
let secret = "password";
let cmd = command::MarkUserVerifiedCommand::new(user_id.clone(), secret.into()).unwrap();
let cmd = command::MarkUserVerifiedCommand::new(user_id, secret.into()).unwrap();
// happy case
{

View file

@ -60,7 +60,7 @@ impl RegisterUserUseCase for RegisterUserService {
.create_verification_secret(
CreateSecretMsgBuilder::default()
.secret(secret.clone())
.user_id(user_id.clone())
.user_id(user_id)
.build()
.unwrap(),
)
@ -103,7 +103,7 @@ mod tests {
let cmd = command::UnvalidatedRegisterUserCommandBuilder::default()
.first_name(username.into())
.last_name(username.into())
.email(email.into())
.email(email)
.password(password.into())
.confirm_password(password.into())
.build()
@ -151,7 +151,7 @@ mod tests {
let cmd = command::UnvalidatedRegisterUserCommandBuilder::default()
.first_name(username.into())
.last_name(username.into())
.email(email.into())
.email(email)
.password(password.into())
.confirm_password(password.into())
.build()

View file

@ -41,7 +41,7 @@ mod tests {
fn test_cmd() {
let config = argon2_creds::Config::default();
ResendVerificationEmailCommand::new(
UUID.clone(),
UUID,
"john".into(),
"realaravinth@example.com".into(),
&config,
@ -49,13 +49,7 @@ mod tests {
.unwrap();
assert_eq!(
ResendVerificationEmailCommand::new(
UUID.clone(),
"john".into(),
"john".into(),
&config
)
.err(),
ResendVerificationEmailCommand::new(UUID, "john".into(), "john".into(), &config).err(),
Some(IdentityCommandError::BadEmail)
);
}

View file

@ -57,11 +57,11 @@ mod tests {
#[actix_rt::test]
async fn test_service() {
let user_id = UUID;
let email = format!("john@example.com");
let email = "john@example.com".to_string();
let secret = "asdfasdf";
let config = argon2_creds::Config::default();
let cmd = command::ResendVerificationEmailCommand::new(
UUID.clone(),
UUID,
"john".into(),
email.clone(),
&config,
@ -88,11 +88,11 @@ mod tests {
#[actix_rt::test]
async fn test_service_email_exists() {
let user_id = UUID;
let email = format!("john@example.com");
let email = "john@example.com".to_string();
let secret = "asdfasdf";
let config = argon2_creds::Config::default();
let cmd = command::ResendVerificationEmailCommand::new(
UUID.clone(),
UUID,
"john".into(),
email.clone(),
&config,

View file

@ -44,7 +44,7 @@ mod tests {
.email_verified(false)
.is_admin(true)
.deleted(false)
.user_id(UUID.clone())
.user_id(UUID)
.build()
.unwrap(),
)
@ -61,7 +61,7 @@ mod tests {
.is_admin(false)
.email_verified(false)
.deleted(false)
.user_id(UUID.clone())
.user_id(UUID)
.build()
.unwrap(),
)

View file

@ -38,7 +38,7 @@ mod tests {
.email_verified(false)
.is_admin(true)
.deleted(false)
.user_id(UUID.clone())
.user_id(UUID)
.build()
.unwrap();

View file

@ -49,12 +49,12 @@ mod tests {
let password = "adsfasdfasd";
let first_name = "john";
let user_id = UUID;
let new_email = format!("newemail@example.com");
let new_email = "newemail@example.com".to_string();
let hashed_password = config.password(password).unwrap();
assert_eq!(
UpdateEmailCommand::new(
new_email.clone(),
user_id.clone(),
user_id,
first_name.into(),
password.into(),
&hashed_password,
@ -69,7 +69,7 @@ mod tests {
assert_eq!(
UpdateEmailCommand::new(
user_id.to_string(),
user_id.clone(),
user_id,
first_name.into(),
password.into(),
&hashed_password,
@ -83,7 +83,7 @@ mod tests {
assert_eq!(
UpdateEmailCommand::new(
new_email.to_string(),
user_id.clone(),
user_id,
first_name.into(),
first_name.into(),
&hashed_password,

View file

@ -44,7 +44,7 @@ impl UpdateEmailUseCase for UpdateEmailService {
.create_verification_secret(
CreateSecretMsgBuilder::default()
.secret(secret.clone())
.user_id(cmd.user_id().clone())
.user_id(*cmd.user_id())
.build()
.unwrap(),
)
@ -71,14 +71,14 @@ mod tests {
#[actix_rt::test]
async fn test_service() {
let user_id = UUID;
let new_email = format!("john@example.com");
let new_email = "john@example.com".to_string();
let password = "password";
let config = argon2_creds::Config::default();
let hashed_password = config.password(password).unwrap();
let cmd = command::UpdateEmailCommand::new(
new_email.clone(),
user_id.clone(),
user_id,
"john".into(),
password.into(),
&hashed_password,

View file

@ -55,7 +55,7 @@ mod tests {
)
.unwrap()
.hashed_new_passowrd,
new_password.into(),
new_password,
)
.unwrap();

View file

@ -33,7 +33,7 @@ mod tests {
username.into(),
password.into(),
new_password.clone(),
new_password.into(),
new_password,
&hashed_password,
&config,
)

View file

@ -142,12 +142,12 @@ impl Aggregate for User {
UserEvent::UserRegistered(e) => {
self.first_name = e.first_name().into();
self.last_name = e.last_name().into();
self.user_id = e.user_id().clone();
self.user_id = *e.user_id();
self.email = e.email().into();
self.hashed_password = e.hashed_password().into();
self.is_admin = e.is_admin().clone();
self.email_verified = e.email_verified().clone();
self.is_verified = e.is_verified().clone();
self.is_admin = *e.is_admin();
self.email_verified = *e.email_verified();
self.is_verified = *e.is_verified();
self.deleted = false;
}
UserEvent::UserDeleted => {

View file

@ -32,15 +32,12 @@ pub struct CategoryView {
// design the events to carry the balance information instead.
impl View<Category> for CategoryView {
fn update(&mut self, event: &EventEnvelope<Category>) {
match &event.payload {
InventoryEvent::CategoryAdded(val) => {
self.name = val.name().into();
self.description = val.description().clone();
self.category_id = val.category_id().clone();
self.store_id = val.store_id().clone();
self.deleted = false;
}
_ => (),
if let InventoryEvent::CategoryAdded(val) = &event.payload {
self.name = val.name().into();
self.description = val.description().clone();
self.category_id = *val.category_id();
self.store_id = *val.store_id();
self.deleted = false;
}
}
}
@ -187,7 +184,7 @@ impl Query<Category> for SimpleLoggingQuery {
impl Query<Category> for InventoryDBPostgresAdapter {
async fn dispatch(&self, category_id: &str, events: &[EventEnvelope<Category>]) {
let res = self
.load_with_context(&category_id)
.load_with_context(category_id)
.await
.unwrap_or_else(|_| {
Some((

View file

@ -63,10 +63,10 @@ pub mod tests {
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.image(cmd.image().as_ref().map(|s| s.to_string()))
.sku_able(cmd.sku_able().clone())
.category_id(cmd.category_id().clone())
.sku_able(*cmd.sku_able())
.category_id(*cmd.category_id())
.quantity(cmd.quantity().clone())
.product_id(UUID.clone())
.product_id(UUID)
.customizations(customizations)
.price(cmd.price().clone())
.build()

View file

@ -60,10 +60,10 @@ mod tests {
.name(product_name.into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.image(cmd.image().as_ref().map(|s| s.to_string()))
.sku_able(cmd.sku_able().clone())
.category_id(cmd.category_id().clone())
.sku_able(*cmd.sku_able())
.category_id(*cmd.category_id())
.customizations(Vec::default())
.product_id(UUID.clone())
.product_id(UUID)
.price(cmd.price().clone())
.quantity(cmd.quantity().clone())
.build()

View file

@ -10,8 +10,8 @@ use cqrs_es::{EventEnvelope, Query, View};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::errors::*;
use super::InventoryDBPostgresAdapter;
use super::{errors::*, product_id_exists};
use crate::inventory::domain::events::InventoryEvent;
use crate::inventory::domain::product_aggregate::{
Currency, Customization, CustomizationBuilder, PriceBuilder, Product, ProductBuilder,
@ -122,27 +122,24 @@ impl From<ProductView> for Product {
// design the events to carry the balance information instead.
impl View<Product> for ProductView {
fn update(&mut self, event: &EventEnvelope<Product>) {
match &event.payload {
InventoryEvent::ProductAdded(val) => {
self.name = val.name().into();
self.description = val.description().clone();
self.image = val.image().clone();
self.product_id = val.product_id().clone();
self.category_id = val.category_id().clone();
if let InventoryEvent::ProductAdded(val) = &event.payload {
self.name = val.name().into();
self.description = val.description().clone();
self.image = val.image().clone();
self.product_id = *val.product_id();
self.category_id = *val.category_id();
self.sku_able = val.sku_able().clone();
self.sku_able = *val.sku_able();
self.price_minor = val.price().minor().clone() as i32;
self.price_major = val.price().major().clone() as i32;
self.price_currency = val.price().currency().to_string();
self.price_minor = *val.price().minor() as i32;
self.price_major = *val.price().major() as i32;
self.price_currency = val.price().currency().to_string();
self.quantity_number = val.quantity().number().clone() as i32;
self.quantity_unit = val.quantity().unit().to_string();
self.quantity_number = *val.quantity().number() as i32;
self.quantity_unit = val.quantity().unit().to_string();
self.deleted = false;
self.customizations = val.customizations().clone();
}
_ => (),
self.deleted = false;
self.customizations = val.customizations().clone();
}
}
}
@ -234,7 +231,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
.await
.map_err(PostgresAggregateError::from)?;
let customizations = res.get_customizations(&self).await?;
let customizations = res.get_customizations(self).await?;
Ok(Some(res.to_product_view(customizations)))
}
@ -273,7 +270,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
.await
.map_err(PostgresAggregateError::from)?;
let customizations = res.get_customizations(&self).await?;
let customizations = res.get_customizations(self).await?;
struct Context {
version: i64,
@ -436,7 +433,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
impl Query<Product> for InventoryDBPostgresAdapter {
async fn dispatch(&self, product_id: &str, events: &[EventEnvelope<Product>]) {
let res = self
.load_with_context(&product_id)
.load_with_context(product_id)
.await
.unwrap_or_else(|_| {
Some((

View file

@ -66,7 +66,7 @@ pub mod tests {
let store = StoreBuilder::default()
.name("store_name".into())
.owner(UUID.clone())
.owner(UUID)
.address(Some("store_address".into()))
.store_id(store_id)
.build()

View file

@ -52,7 +52,7 @@ mod tests {
let store = StoreBuilder::default()
.name("store_name".into())
.owner(UUID.clone())
.owner(UUID)
.address(Some("store_address".into()))
.store_id(store_id)
.build()

View file

@ -32,15 +32,12 @@ pub struct StoreView {
// design the events to carry the balance information instead.
impl View<Store> for StoreView {
fn update(&mut self, event: &EventEnvelope<Store>) {
match &event.payload {
InventoryEvent::StoreAdded(val) => {
self.name = val.name().into();
self.address = val.address().clone();
self.store_id = val.store_id().clone();
self.owner = val.owner().clone();
self.deleted = false;
}
_ => (),
if let InventoryEvent::StoreAdded(val) = &event.payload {
self.name = val.name().into();
self.address = val.address().clone();
self.store_id = *val.store_id();
self.owner = *val.owner();
self.deleted = false;
}
}
}
@ -187,7 +184,7 @@ impl Query<Store> for SimpleLoggingQuery {
impl Query<Store> for InventoryDBPostgresAdapter {
async fn dispatch(&self, store_id: &str, events: &[EventEnvelope<Store>]) {
let res = self
.load_with_context(&store_id)
.load_with_context(store_id)
.await
.unwrap_or_else(|_| Some((StoreView::default(), ViewContext::new(store_id.into(), 0))));
let (mut view, view_context): (StoreView, ViewContext) = res.unwrap();
@ -254,7 +251,7 @@ mod tests {
))
.add_category(mock_add_category_service(
IS_NEVER_CALLED,
AddCategoryCommand::new("foo".into(), None, UUID.clone(), UUID.clone()).unwrap(),
AddCategoryCommand::new("foo".into(), None, UUID, UUID).unwrap(),
))
.add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
.build()
@ -273,7 +270,7 @@ mod tests {
);
let rand = crate::utils::random_string::GenerateRandomString {};
let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID.clone()).unwrap();
let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID).unwrap();
cqrs.execute("", InventoryCommand::AddStore(cmd.clone()))
.await
.unwrap();

View file

@ -41,7 +41,7 @@ impl AddCategoryUseCase for AddCategoryService {
let mut category = CategoryBuilder::default()
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.store_id(cmd.store_id().clone())
.store_id(*cmd.store_id())
.category_id(category_id)
.build()
.unwrap();
@ -64,7 +64,7 @@ impl AddCategoryUseCase for AddCategoryService {
category = CategoryBuilder::default()
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.store_id(cmd.store_id().clone())
.store_id(*cmd.store_id())
.category_id(category_id)
.build()
.unwrap();
@ -78,9 +78,9 @@ impl AddCategoryUseCase for AddCategoryService {
Ok(CategoryAddedEventBuilder::default()
.name(category.name().into())
.description(category.description().as_ref().map(|s| s.to_string()))
.added_by_user(cmd.adding_by().clone())
.store_id(category.store_id().clone())
.category_id(category.category_id().clone())
.added_by_user(*cmd.adding_by())
.store_id(*category.store_id())
.category_id(*category.category_id())
.build()
.unwrap())
}
@ -104,9 +104,9 @@ pub mod tests {
let res = CategoryAddedEventBuilder::default()
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.added_by_user(cmd.adding_by().clone())
.store_id(cmd.store_id().clone())
.category_id(UUID.clone())
.added_by_user(*cmd.adding_by())
.store_id(*cmd.store_id())
.category_id(UUID)
.build()
.unwrap();
@ -129,13 +129,8 @@ pub mod tests {
let store_id = Uuid::new_v4();
// description = None
let cmd = AddCategoryCommand::new(
name.into(),
Some(description.into()),
store_id.clone(),
user_id.clone(),
)
.unwrap();
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
.unwrap();
let s = AddCategoryServiceBuilder::default()
.db_category_name_exists_for_store(mock_category_name_exists_for_store_db_port_false(
@ -162,13 +157,8 @@ pub mod tests {
let store_id = Uuid::new_v4();
// description = None
let cmd = AddCategoryCommand::new(
name.into(),
Some(description.into()),
store_id.clone(),
user_id.clone(),
)
.unwrap();
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
.unwrap();
let s = AddCategoryServiceBuilder::default()
.db_category_name_exists_for_store(mock_category_name_exists_for_store_db_port_true(

View file

@ -11,9 +11,7 @@ use mockall::*;
use super::errors::*;
use crate::inventory::{
application::port::output::db::{
customization_id_exists::{self, *},
customization_name_exists_for_product::*,
product_id_exists::*,
customization_id_exists::*, customization_name_exists_for_product::*, product_id_exists::*,
product_name_exists_for_category::*,
},
domain::{
@ -97,9 +95,9 @@ impl AddProductUseCase for AddProductService {
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.image(cmd.image().clone())
.sku_able(cmd.sku_able().clone())
.sku_able(*cmd.sku_able())
.price(cmd.price().clone())
.category_id(cmd.category_id().clone())
.category_id(*cmd.category_id())
.quantity(cmd.quantity().clone())
.customizations(customizations)
.product_id(product_id)
@ -115,14 +113,14 @@ impl AddProductUseCase for AddProductService {
}
Ok(ProductAddedEventBuilder::default()
.added_by_user(cmd.adding_by().clone())
.added_by_user(*cmd.adding_by())
.name(product.name().into())
.description(product.description().as_ref().map(|s| s.to_string()))
.image(product.image().clone())
.sku_able(product.sku_able().clone())
.sku_able(*product.sku_able())
.price(product.price().clone())
.category_id(product.category_id().clone())
.product_id(product.product_id().clone())
.category_id(*product.category_id())
.product_id(*product.product_id())
.customizations(product.customizations().clone())
.quantity(product.quantity().clone())
.build()
@ -134,8 +132,6 @@ impl AddProductUseCase for AddProductService {
pub mod tests {
use super::*;
use uuid::Uuid;
use crate::inventory::domain::add_product_command::tests::get_command;
use crate::utils::uuid::tests::UUID;
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
@ -162,13 +158,13 @@ pub mod tests {
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.image(cmd.image().as_ref().map(|s| s.to_string()))
.sku_able(cmd.sku_able().clone())
.category_id(cmd.category_id().clone())
.product_id(UUID.clone())
.sku_able(*cmd.sku_able())
.category_id(*cmd.category_id())
.product_id(UUID)
.price(cmd.price().clone())
.quantity(cmd.quantity().clone())
.customizations(customizations)
.added_by_user(cmd.adding_by().clone())
.added_by_user(*cmd.adding_by())
.build()
.unwrap();

View file

@ -10,9 +10,7 @@ use mockall::*;
use super::errors::*;
use crate::inventory::{
application::port::output::db::{
errors::InventoryDBError, store_id_exists::*, store_name_exists::*,
},
application::port::output::db::{store_id_exists::*, store_name_exists::*},
domain::{
add_store_command::AddStoreCommand,
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
@ -43,8 +41,8 @@ impl AddStoreUseCase for AddStoreService {
let mut store = StoreBuilder::default()
.name(cmd.name().into())
.address(cmd.address().as_ref().map(|s| s.to_string()))
.owner(cmd.owner().clone())
.store_id(store_id.clone())
.owner(*cmd.owner())
.store_id(store_id)
.build()
.unwrap();
@ -58,8 +56,8 @@ impl AddStoreUseCase for AddStoreService {
store = StoreBuilder::default()
.name(cmd.name().into())
.address(cmd.address().as_ref().map(|s| s.to_string()))
.owner(cmd.owner().clone())
.store_id(store_id.clone())
.owner(*cmd.owner())
.store_id(store_id)
.build()
.unwrap();
continue;
@ -71,8 +69,8 @@ impl AddStoreUseCase for AddStoreService {
Ok(StoreAddedEventBuilder::default()
.name(store.name().into())
.address(store.address().as_ref().map(|s| s.to_string()))
.owner(cmd.owner().clone())
.store_id(store_id.clone())
.owner(*cmd.owner())
.store_id(store_id)
.build()
.unwrap())
}
@ -94,8 +92,8 @@ pub mod tests {
let res = StoreAddedEventBuilder::default()
.name(cmd.name().into())
.address(cmd.address().as_ref().map(|s| s.to_string()))
.owner(cmd.owner().clone())
.store_id(UUID.clone())
.owner(*cmd.owner())
.store_id(UUID)
.build()
.unwrap();
@ -117,7 +115,7 @@ pub mod tests {
let owner = UUID;
// address = None
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner.clone()).unwrap();
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
let s = AddStoreServiceBuilder::default()
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
@ -140,7 +138,7 @@ pub mod tests {
let owner = UUID;
// address = None
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner.clone()).unwrap();
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
let s = AddStoreServiceBuilder::default()
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_NEVER_CALLED))

View file

@ -66,21 +66,16 @@ mod tests {
let store_id = Uuid::new_v4();
// description = None
let cmd = AddCategoryCommand::new(name.into(), None, store_id.clone(), adding_by.clone())
.unwrap();
let cmd = AddCategoryCommand::new(name.into(), None, store_id, adding_by).unwrap();
assert_eq!(cmd.name(), name);
assert_eq!(cmd.description(), &None);
assert_eq!(cmd.adding_by(), &adding_by);
assert_eq!(cmd.store_id(), &store_id);
// description = Some
let cmd = AddCategoryCommand::new(
name.into(),
Some(description.into()),
store_id.clone(),
adding_by.clone(),
)
.unwrap();
let cmd =
AddCategoryCommand::new(name.into(), Some(description.into()), store_id, adding_by)
.unwrap();
assert_eq!(cmd.name(), name);
assert_eq!(cmd.description(), &Some(description.to_owned()));
assert_eq!(cmd.adding_by(), &adding_by);
@ -88,12 +83,7 @@ mod tests {
// AddCategoryCommandError::NameIsEmpty
assert_eq!(
AddCategoryCommand::new(
"".into(),
Some(description.into()),
store_id.clone(),
adding_by.clone(),
),
AddCategoryCommand::new("".into(), Some(description.into()), store_id, adding_by,),
Err(AddCategoryCommandError::NameIsEmpty)
)
}

View file

@ -181,8 +181,8 @@ pub mod tests {
.name(name.into())
.description(description.clone())
.image(image.clone())
.category_id(category_id.clone())
.adding_by(adding_by.clone())
.category_id(category_id)
.adding_by(adding_by)
.quantity(quantity)
.sku_able(sku_able)
.price(price.clone())
@ -218,8 +218,8 @@ pub mod tests {
.name(name.into())
.description(None)
.image(None)
.category_id(category_id.clone())
.adding_by(adding_by.clone())
.category_id(category_id)
.adding_by(adding_by)
.quantity(quantity.clone())
.sku_able(sku_able)
.price(price.clone())
@ -265,9 +265,9 @@ pub mod tests {
.name(name.into())
.description(description.clone())
.image(image.clone())
.category_id(category_id.clone())
.category_id(category_id)
.quantity(quantity.clone())
.adding_by(adding_by.clone())
.adding_by(adding_by)
.sku_able(sku_able)
.price(price.clone())
.customizations(customizations.clone())
@ -312,8 +312,8 @@ pub mod tests {
.name("".into())
.description(description.clone())
.image(image.clone())
.category_id(category_id.clone())
.adding_by(adding_by.clone())
.category_id(category_id)
.adding_by(adding_by)
.quantity(quantity)
.sku_able(sku_able)
.customizations(customizations)
@ -365,8 +365,8 @@ pub mod tests {
.name(name.into())
.description(description.clone())
.image(image.clone())
.category_id(category_id.clone())
.adding_by(adding_by.clone())
.category_id(category_id)
.adding_by(adding_by)
.quantity(quantity)
.sku_able(sku_able)
.customizations(customizations)

View file

@ -59,23 +59,23 @@ mod tests {
fn test_cmd() {
let name = "foo";
let address = "bar";
let owner = UUID.clone();
let owner = UUID;
// address = None
let cmd = AddStoreCommand::new(name.into(), None, owner.clone()).unwrap();
let cmd = AddStoreCommand::new(name.into(), None, owner).unwrap();
assert_eq!(cmd.name(), name);
assert_eq!(cmd.address(), &None);
assert_eq!(cmd.owner(), &owner);
// address = Some
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner.clone()).unwrap();
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
assert_eq!(cmd.name(), name);
assert_eq!(cmd.address(), &Some(address.to_owned()));
assert_eq!(cmd.owner(), &owner);
// AddStoreCommandError::NameIsEmpty
assert_eq!(
AddStoreCommand::new("".into(), Some(address.into()), owner.clone()),
AddStoreCommand::new("".into(), Some(address.into()), owner),
Err(AddStoreCommandError::NameIsEmpty)
)
}

View file

@ -55,17 +55,14 @@ impl Aggregate for Category {
}
fn apply(&mut self, event: Self::Event) {
match event {
InventoryEvent::CategoryAdded(e) => {
*self = CategoryBuilder::default()
.name(e.name().into())
.category_id(e.category_id().clone())
.description(e.description().clone())
.store_id(e.store_id().clone())
.build()
.unwrap();
}
_ => (),
if let InventoryEvent::CategoryAdded(e) = event {
*self = CategoryBuilder::default()
.name(e.name().into())
.category_id(*e.category_id())
.description(e.description().clone())
.store_id(*e.store_id())
.build()
.unwrap();
}
}
}
@ -96,22 +93,17 @@ mod aggregate_tests {
let description = Some("category_description".to_string());
let adding_by = UUID;
let store_id = Uuid::new_v4();
let category_id = UUID.clone();
let category_id = UUID;
let cmd = AddCategoryCommand::new(
name.into(),
description.clone(),
store_id.clone(),
adding_by.clone(),
)
.unwrap();
let cmd =
AddCategoryCommand::new(name.into(), description.clone(), store_id, adding_by).unwrap();
let expected = CategoryAddedEventBuilder::default()
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.added_by_user(cmd.adding_by().clone())
.store_id(cmd.store_id().clone())
.category_id(category_id.clone())
.added_by_user(*cmd.adding_by())
.store_id(*cmd.store_id())
.category_id(category_id)
.build()
.unwrap();
let expected = InventoryEvent::CategoryAdded(expected);

View file

@ -53,13 +53,13 @@ pub mod tests {
.name(cmd.name().into())
.description(cmd.description().as_ref().map(|s| s.to_string()))
.image(cmd.image().as_ref().map(|s| s.to_string()))
.sku_able(cmd.sku_able().clone())
.category_id(cmd.category_id().clone())
.product_id(UUID.clone())
.sku_able(*cmd.sku_able())
.category_id(*cmd.category_id())
.product_id(UUID)
.price(cmd.price().clone())
.customizations(customizations)
.quantity(cmd.quantity().clone())
.added_by_user(cmd.adding_by().clone())
.added_by_user(*cmd.adding_by())
.build()
.unwrap()
}

View file

@ -5,10 +5,10 @@
use std::str::FromStr;
use async_trait::async_trait;
use config::builder;
use cqrs_es::Aggregate;
use derive_builder::Builder;
use derive_getters::Getters;
use derive_more::Display;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
@ -16,12 +16,17 @@ use super::{commands::InventoryCommand, events::InventoryEvent};
use crate::inventory::application::services::errors::*;
use crate::inventory::application::services::InventoryServicesInterface;
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Clone, Display, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum QuantityUnit {
#[display(fmt = "{}", KILO_GRAM)]
Kilogram,
#[display(fmt = "{}", GRAM)]
Gram,
#[display(fmt = "{}", DISCRETE_NUMBER)]
DiscreteNumber, // example: 1 sofa, 2 bed, etc.
#[display(fmt = "{}", MILLI_LITER)]
MilliLiter,
#[display(fmt = "{}", LITER)]
Liter,
}
@ -37,19 +42,6 @@ const DISCRETE_NUMBER: &str = "discrete_number";
const MILLI_LITER: &str = "ml";
const LITER: &str = "l";
impl ToString for QuantityUnit {
fn to_string(&self) -> String {
match self {
Self::Kilogram => KILO_GRAM,
Self::Gram => GRAM,
Self::DiscreteNumber => DISCRETE_NUMBER,
Self::MilliLiter => MILLI_LITER,
Self::Liter => LITER,
}
.into()
}
}
impl FromStr for QuantityUnit {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -72,22 +64,14 @@ pub struct Quantity {
unit: QuantityUnit,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Clone, Display, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum Currency {
#[display(fmt = "{}", INR)]
INR,
}
const INR: &str = "INR";
impl ToString for Currency {
fn to_string(&self) -> String {
match self {
Self::INR => INR,
}
.into()
}
}
impl FromStr for Currency {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -172,23 +156,20 @@ impl Aggregate for Product {
}
fn apply(&mut self, event: Self::Event) {
match event {
InventoryEvent::ProductAdded(e) => {
*self = ProductBuilder::default()
.name(e.name().into())
.description(e.description().clone())
.image(e.image().clone())
.price(e.price().clone())
.category_id(e.category_id().clone())
.sku_able(e.sku_able().clone())
.product_id(e.product_id().clone())
.quantity(e.quantity().clone())
.customizations(e.customizations().clone())
.deleted(false)
.build()
.unwrap();
}
_ => (),
if let InventoryEvent::ProductAdded(e) = event {
*self = ProductBuilder::default()
.name(e.name().into())
.description(e.description().clone())
.image(e.image().clone())
.price(e.price().clone())
.category_id(*e.category_id())
.sku_able(*e.sku_able())
.product_id(*e.product_id())
.quantity(e.quantity().clone())
.customizations(e.customizations().clone())
.deleted(false)
.build()
.unwrap();
}
}
}

View file

@ -55,15 +55,12 @@ impl Aggregate for Store {
}
fn apply(&mut self, event: Self::Event) {
match event {
InventoryEvent::StoreAdded(e) => {
self.name = e.name().into();
self.address = e.address().as_ref().map(|s| s.to_string());
self.owner = e.owner().clone();
self.store_id = e.store_id().clone();
self.deleted = false;
}
_ => (),
if let InventoryEvent::StoreAdded(e) = event {
self.name = e.name().into();
self.address = e.address().as_ref().map(|s| s.to_string());
self.owner = *e.owner();
self.store_id = *e.store_id();
self.deleted = false;
}
}
}
@ -99,13 +96,13 @@ mod tests {
let expected = StoreAddedEventBuilder::default()
.name(name.into())
.address(address.clone())
.store_id(store_id.clone())
.owner(owner.into())
.store_id(store_id)
.owner(owner)
.build()
.unwrap();
let expected = InventoryEvent::StoreAdded(expected);
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner.clone()).unwrap();
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner).unwrap();
let mut services = MockInventoryServicesInterface::new();
services

View file

@ -75,8 +75,6 @@ mod tests {
"postgres://test_db_env_override",
database.url
);
assert!(true);
})
.join()
.unwrap();

View file

@ -65,7 +65,6 @@ mod tests {
"asdfasdflkjhasdlkfhalksdf",
server.cookie_secret
);
assert!(true);
})
.join()
.unwrap();

View file

@ -10,18 +10,18 @@ pub fn parse_aggregate_id<T: Default>(
non_id: &str,
) -> Result<Option<(T, ViewContext)>, PersistenceError> {
match Uuid::parse_str(aggregate_id) {
Ok(_) => return Ok(None),
Ok(_) => Ok(None),
Err(e) => {
if aggregate_id == non_id {
// if store_id is unbearable, then store isn't created yet. Use cleaner, robust method
// later.
return Ok(Some((
Ok(Some((
T::default(),
ViewContext::new(aggregate_id.into(), 0),
)));
)))
} else {
return Err(PersistenceError::UnknownError(Box::new(e)));
Err(PersistenceError::UnknownError(Box::new(e)))
}
}
};
}
}

View file

@ -50,9 +50,9 @@ pub mod tests {
let mut m = MockGetUUID::new();
if let Some(times) = times {
m.expect_get_uuid().times(times).return_const(UUID.clone());
m.expect_get_uuid().times(times).return_const(UUID);
} else {
m.expect_get_uuid().return_const(UUID.clone());
m.expect_get_uuid().return_const(UUID);
}
Arc::new(m)