Merge pull request 'feat: test AddCUstomization with cqrs infra' (#49) from add-customization-test into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Reviewed-on: #49
This commit is contained in:
Aravinth Manivannan 2024-07-16 19:45:59 +05:30
commit 4243c0346f
3 changed files with 68 additions and 94 deletions

View file

@ -100,6 +100,7 @@ impl AddCustomizationUseCase for AddCustomizationService {
pub mod tests { pub mod tests {
use super::*; use super::*;
use customization_added_event::tests::get_customization_added_event_from_cmd;
use uuid::Uuid; use uuid::Uuid;
use crate::inventory::domain::add_customization_command::tests::get_command; use crate::inventory::domain::add_customization_command::tests::get_command;
@ -112,19 +113,7 @@ pub mod tests {
) -> AddCustomizationServiceObj { ) -> AddCustomizationServiceObj {
let mut m = MockAddCustomizationUseCase::new(); let mut m = MockAddCustomizationUseCase::new();
let customization = CustomizationBuilder::default() let res = get_customization_added_event_from_cmd(&cmd);
.name(cmd.name().into())
.deleted(false)
.customization_id(UUID.clone())
.build()
.unwrap();
let res = CustomizationAddedEventBuilder::default()
.customization(customization)
.product_id(cmd.product_id().clone())
.build()
.unwrap();
if let Some(times) = times { if let Some(times) = times {
m.expect_add_customization() m.expect_add_customization()
.times(times) .times(times)

View file

@ -16,3 +16,29 @@ pub struct CustomizationAddedEvent {
customization: Customization, customization: Customization,
product_id: Uuid, product_id: Uuid,
} }
#[cfg(test)]
pub mod tests {
use crate::inventory::domain::add_customization_command::AddCustomizationCommand;
use super::*;
use crate::utils::uuid::tests::UUID;
pub fn get_customization_added_event_from_cmd(
cmd: &AddCustomizationCommand,
) -> CustomizationAddedEvent {
let customization = CustomizationBuilder::default()
.name(cmd.name().into())
.deleted(false)
.customization_id(UUID.clone())
.build()
.unwrap();
CustomizationAddedEventBuilder::default()
.customization(customization)
.product_id(cmd.product_id().clone())
.build()
.unwrap()
}
}

View file

@ -64,84 +64,43 @@ impl Aggregate for Customization {
} }
} }
//#[cfg(test)] #[cfg(test)]
//mod aggregate_tests { mod aggregate_tests {
// use std::sync::Arc; use std::sync::Arc;
//
// use cqrs_es::test::TestFramework; use cqrs_es::test::TestFramework;
//
// use super::*; use super::*;
// use crate::inventory::{ use crate::inventory::{
// application::services::{add_product_service::tests::*, *}, application::services::{add_customization_service::tests::*, *},
// domain::{ domain::{
// add_product_command::tests::get_command, commands::InventoryCommand, add_customization_command, commands::InventoryCommand,
// events::InventoryEvent, product_added_event::tests::get_event_from_command, customization_added_event::tests::get_customization_added_event_from_cmd,
// }, events::InventoryEvent,
// }; },
// use crate::tests::bdd::*; };
// use crate::tests::bdd::*;
// type ProductTestFramework = TestFramework<Product>;
// type CustomizationTestFramework = TestFramework<Customization>;
// #[test]
// fn test_create_product() { #[test]
// let cmd = get_command(); fn test_create_customization() {
// let expected = get_event_from_command(&cmd); let cmd = add_customization_command::tests::get_command();
// let expected = InventoryEvent::ProductAdded(expected); let expected = get_customization_added_event_from_cmd(&cmd);
// let expected = InventoryEvent::CustomizationAdded(expected);
// let mut services = MockInventoryServicesInterface::new();
// services let mut services = MockInventoryServicesInterface::new();
// .expect_add_product() services
// .times(IS_CALLED_ONLY_ONCE.unwrap()) .expect_add_customization()
// .return_const(mock_add_product_service(IS_CALLED_ONLY_ONCE, cmd.clone())); .times(IS_CALLED_ONLY_ONCE.unwrap())
// .return_const(mock_add_customization_service(
// ProductTestFramework::with(Arc::new(services)) IS_CALLED_ONLY_ONCE,
// .given_no_previous_events() cmd.clone(),
// .when(InventoryCommand::AddProduct(cmd)) ));
// .then_expect_events(vec![expected]);
// } CustomizationTestFramework::with(Arc::new(services))
// .given_no_previous_events()
// fn test_helper<T>(t: T, str_value: &str) -> bool .when(InventoryCommand::AddCustomization(cmd))
// where .then_expect_events(vec![expected]);
// T: ToString + FromStr + std::fmt::Debug + PartialEq, }
// <T as FromStr>::Err: std::fmt::Debug, }
// {
// println!("Testing type: {:?} against value {str_value}", t);
// assert_eq!(t.to_string(), str_value.to_string());
//
// assert_eq!(T::from_str(str_value).unwrap(), t);
//
// assert_eq!(T::from_str(t.to_string().as_str()).unwrap(), t,);
//
// true
// }
//
// #[test]
// fn currency_to_string_from_str() {
// assert!(test_helper(Currency::INR, INR));
// }
//
// #[test]
// fn quantity_unit_kilogram() {
// assert!(test_helper(QuantityUnit::Kilogram, KILO_GRAM));
// }
//
// #[test]
// fn quantity_unit_gram() {
// assert!(test_helper(QuantityUnit::Gram, GRAM));
// }
//
// #[test]
// fn quantity_unit_discrete_number() {
// assert!(test_helper(QuantityUnit::DiscreteNumber, DISCRETE_NUMBER));
// }
//
// #[test]
// fn quantity_unit_milli_liter() {
// assert!(test_helper(QuantityUnit::MilliLiter, MILLI_LITER));
// }
//
// #[test]
// fn quantity_unit_liter() {
// assert!(test_helper(QuantityUnit::Liter, LITER));
// }
//}