feat: inventory: customization view tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
ac6da029a5
commit
5245cf02e0
3 changed files with 147 additions and 8 deletions
|
@ -187,12 +187,10 @@ impl ViewRepository<CustomizationView, Customization> for InventoryDBPostgresAda
|
|||
SET
|
||||
version = $1,
|
||||
name = $2,
|
||||
customization_id = $3,
|
||||
product_id = $4,
|
||||
deleted = $5;",
|
||||
product_id = $3,
|
||||
deleted = $4;",
|
||||
version,
|
||||
view.name,
|
||||
view.customization_id,
|
||||
view.product_id,
|
||||
view.deleted,
|
||||
)
|
||||
|
@ -225,3 +223,145 @@ impl Query<Customization> for InventoryDBPostgresAdapter {
|
|||
self.update_view(view, view_context).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use postgres_es::PostgresCqrs;
|
||||
|
||||
use crate::{
|
||||
db::migrate::*,
|
||||
inventory::{
|
||||
adapters::output::db::postgres::product_id_exists::tests::create_dummy_product_record,
|
||||
application::services::{
|
||||
add_customization_service::*, update_customization_service::*,
|
||||
MockInventoryServicesInterface,
|
||||
},
|
||||
domain::{
|
||||
add_customization_command::*,
|
||||
commands::InventoryCommand,
|
||||
product_aggregate::Product,
|
||||
update_customization_command::{tests::get_update_customization_command, *},
|
||||
},
|
||||
},
|
||||
tests::bdd::*,
|
||||
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn pg_query_inventory_customization_view() {
|
||||
let settings = crate::settings::tests::get_settings().await;
|
||||
//let settings = crate::settings::Settings::new().unwrap();
|
||||
settings.create_db().await;
|
||||
|
||||
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||
db.migrate().await;
|
||||
let db = InventoryDBPostgresAdapter::new(db.pool.clone());
|
||||
let product = Product::default();
|
||||
create_dummy_product_record(&product, &db).await;
|
||||
|
||||
// let simple_query = super::store_view::SimpleLoggingQuery {};
|
||||
|
||||
let queries: Vec<Box<dyn Query<Customization>>> = vec![Box::new(db.clone())];
|
||||
|
||||
let mut mock_services = MockInventoryServicesInterface::new();
|
||||
|
||||
let db2 = db.clone();
|
||||
mock_services
|
||||
.expect_add_customization()
|
||||
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||
.returning(move || {
|
||||
Arc::new(
|
||||
AddCustomizationServiceBuilder::default()
|
||||
.db_product_id_exists(Arc::new(db2.clone()))
|
||||
.db_customization_id_exists(Arc::new(db2.clone()))
|
||||
.db_customization_name_exists_for_product(Arc::new(db2.clone()))
|
||||
.build()
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let db2 = Arc::new(db.clone());
|
||||
mock_services
|
||||
.expect_update_customization()
|
||||
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||
.returning(move || {
|
||||
Arc::new(
|
||||
UpdateCustomizationServiceBuilder::default()
|
||||
.db_product_id_exists(db2.clone())
|
||||
.db_customization_name_exists_for_product(db2.clone())
|
||||
.db_customization_id_exists(db2.clone())
|
||||
.build()
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let (cqrs, custmoization_query): (
|
||||
Arc<PostgresCqrs<Customization>>,
|
||||
Arc<dyn ViewRepository<CustomizationView, Customization>>,
|
||||
) = (
|
||||
Arc::new(postgres_es::postgres_cqrs(
|
||||
db.pool.clone(),
|
||||
queries,
|
||||
Arc::new(mock_services),
|
||||
)),
|
||||
Arc::new(db.clone()),
|
||||
);
|
||||
|
||||
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||
|
||||
let cmd = AddCustomizationCommandBuilder::default()
|
||||
.name(rand.get_random(10))
|
||||
.product_id(product.product_id().clone())
|
||||
.customization_id(UUID.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
cqrs.execute(
|
||||
&cmd.customization_id().to_string(),
|
||||
InventoryCommand::AddCustomization(cmd.clone()),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let customization = custmoization_query
|
||||
.load(&(*cmd.customization_id()).to_string())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let customization: Customization = customization.into();
|
||||
assert_eq!(customization.name(), cmd.name());
|
||||
assert_eq!(customization.customization_id(), cmd.customization_id());
|
||||
assert_eq!(customization.product_id(), cmd.product_id());
|
||||
assert!(!customization.deleted());
|
||||
|
||||
let update_customization_command = UnvalidatedUpdateCustomizationCommandBuilder::default()
|
||||
.name(rand.get_random(10))
|
||||
.old_customization(customization.clone())
|
||||
.adding_by(UUID.clone())
|
||||
.build()
|
||||
.unwrap()
|
||||
.validate()
|
||||
.unwrap();
|
||||
cqrs.execute(
|
||||
&cmd.customization_id().to_string(),
|
||||
InventoryCommand::UpdateCustomization(update_customization_command.clone()),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let c = custmoization_query
|
||||
.load(&(*cmd.customization_id()).to_string())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let c: Customization = c.into();
|
||||
assert_eq!(c.name(), update_customization_command.name());
|
||||
assert_eq!(
|
||||
update_customization_command.old_customization(),
|
||||
&customization
|
||||
);
|
||||
assert!(!c.deleted());
|
||||
settings.drop_db().await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@ pub mod tests {
|
|||
);",
|
||||
1,
|
||||
p.name(),
|
||||
p.description().as_ref().unwrap(),
|
||||
p.image().as_ref().unwrap(),
|
||||
p.description().as_ref().map(|s| s.as_str()),
|
||||
p.image().as_ref().map(|s| s.as_str()),
|
||||
p.product_id(),
|
||||
p.category_id(),
|
||||
p.price().major().clone() as i32,
|
||||
|
|
|
@ -225,7 +225,6 @@ impl Query<Store> for InventoryDBPostgresAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue