From 9df0c4070bb679d1dd17a69e3aac3f9f6e6569ce Mon Sep 17 00:00:00 2001 From: Andrzej Krzywda Date: Fri, 27 Sep 2024 13:13:13 +0200 Subject: [PATCH] Adjust tests to rely on Pricing events --- .../test/client_orders/discount_test.rb | 2 +- .../item_added_to_basket_test.rb | 1 - .../item_removed_from_basket_test.rb | 24 +++++++------------ .../update_order_total_value_test.rb | 2 +- .../test/orders/broadcast_test.rb | 20 ++++++---------- .../test/orders/discount_test.rb | 2 +- .../test/orders/order_expired_test.rb | 3 +-- .../test/orders/order_placed_test.rb | 3 +-- .../orders/update_order_total_value_test.rb | 2 +- 9 files changed, 22 insertions(+), 37 deletions(-) diff --git a/rails_application/test/client_orders/discount_test.rb b/rails_application/test/client_orders/discount_test.rb index 6127ed84d..29e3990c3 100644 --- a/rails_application/test/client_orders/discount_test.rb +++ b/rails_application/test/client_orders/discount_test.rb @@ -69,7 +69,7 @@ def change_percentage_discount(order_id) end def item_added_to_basket(order_id, product_id) - event_store.publish(Ordering::ItemAddedToBasket.new(data: { product_id: product_id, order_id: order_id, quantity_before: 0 })) + run_command(Pricing::AddPriceItem.new(product_id: product_id, order_id: order_id)) end def prepare_product(product_id) diff --git a/rails_application/test/client_orders/item_added_to_basket_test.rb b/rails_application/test/client_orders/item_added_to_basket_test.rb index 4d90e9acf..dbfce0672 100644 --- a/rails_application/test/client_orders/item_added_to_basket_test.rb +++ b/rails_application/test/client_orders/item_added_to_basket_test.rb @@ -152,7 +152,6 @@ def test_add_another_item data: { order_id: order_id, product_id: another_product_id, - quantity_before: 0 } ) ) diff --git a/rails_application/test/client_orders/item_removed_from_basket_test.rb b/rails_application/test/client_orders/item_removed_from_basket_test.rb index 2b932c37c..949d25edb 100644 --- a/rails_application/test/client_orders/item_removed_from_basket_test.rb +++ b/rails_application/test/client_orders/item_removed_from_basket_test.rb @@ -33,25 +33,23 @@ def test_remove_item_when_quantity_gt_1 ) order_id = SecureRandom.uuid event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 1 } ) ) event_store.publish( - Ordering::ItemRemovedFromBasket.new( + Pricing::PriceItemRemoved.new( data: { order_id: order_id, product_id: product_id @@ -82,16 +80,15 @@ def test_remove_item_when_quantity_eq_1 ) order_id = SecureRandom.uuid event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) event_store.publish( - Ordering::ItemRemovedFromBasket.new( + Pricing::PriceItemRemoved.new( data: { order_id: order_id, product_id: product_id @@ -140,34 +137,31 @@ def test_remove_item_when_there_is_another_item ) order_id = SecureRandom.uuid event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 1 } ) ) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: another_product_id, - quantity_before: 0 } ) ) event_store.publish( - Ordering::ItemRemovedFromBasket.new( + Pricing::PriceItemRemoved.new( data: { order_id: order_id, product_id: another_product_id diff --git a/rails_application/test/client_orders/update_order_total_value_test.rb b/rails_application/test/client_orders/update_order_total_value_test.rb index da0bc7b49..205b461e2 100644 --- a/rails_application/test/client_orders/update_order_total_value_test.rb +++ b/rails_application/test/client_orders/update_order_total_value_test.rb @@ -20,7 +20,7 @@ def test_order_created_has_draft_state private def item_added_to_basket(order_id, product_id) - event_store.publish(Ordering::ItemAddedToBasket.new(data: { product_id: product_id, order_id: order_id, quantity_before: 0 })) + event_store.publish(Pricing::PriceItemAdded.new(data: { product_id: product_id, order_id: order_id })) end def prepare_product(product_id) diff --git a/rails_application/test/orders/broadcast_test.rb b/rails_application/test/orders/broadcast_test.rb index 9c2bc0e98..6e0c2df37 100644 --- a/rails_application/test/orders/broadcast_test.rb +++ b/rails_application/test/orders/broadcast_test.rb @@ -40,11 +40,10 @@ def test_broadcast_add_item_to_basket in_memory_broadcast.result.clear event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) @@ -68,18 +67,17 @@ def test_broadcast_remove_item_from_basket order_id = SecureRandom.uuid event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) in_memory_broadcast.result.clear event_store.publish( - Ordering::ItemRemovedFromBasket.new( + Pricing::PriceItemRemoved.new( data: { order_id: order_id, product_id: product_id, @@ -108,20 +106,18 @@ def test_broadcast_update_order_value ) run_command(Pricing::SetPrice.new(product_id: product_id, price: 20)) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_1_id, product_id: product_id, - quantity_before: 0 } ) ) @@ -170,20 +166,18 @@ def test_broadcast_update_discount ) run_command(Pricing::SetPrice.new(product_id: product_id, price: 20)) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_1_id, product_id: product_id, - quantity_before: 0 } ) ) diff --git a/rails_application/test/orders/discount_test.rb b/rails_application/test/orders/discount_test.rb index 27482ee5f..bd9d9de72 100644 --- a/rails_application/test/orders/discount_test.rb +++ b/rails_application/test/orders/discount_test.rb @@ -86,7 +86,7 @@ def change_percentage_discount(order_id) end def item_added_to_basket(order_id, product_id) - event_store.publish(Ordering::ItemAddedToBasket.new(data: { product_id: product_id, order_id: order_id, quantity_before: 0 })) + run_command(Pricing::AddPriceItem.new(product_id: product_id, order_id: order_id )) end def prepare_product(product_id) diff --git a/rails_application/test/orders/order_expired_test.rb b/rails_application/test/orders/order_expired_test.rb index 59e5534bf..fef4ddf32 100644 --- a/rails_application/test/orders/order_expired_test.rb +++ b/rails_application/test/orders/order_expired_test.rb @@ -27,11 +27,10 @@ def test_expire_created_order order_id = SecureRandom.uuid order_number = Ordering::FakeNumberGenerator::FAKE_NUMBER event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) diff --git a/rails_application/test/orders/order_placed_test.rb b/rails_application/test/orders/order_placed_test.rb index 1a69cf23f..a378a7815 100644 --- a/rails_application/test/orders/order_placed_test.rb +++ b/rails_application/test/orders/order_placed_test.rb @@ -25,11 +25,10 @@ def test_create_when_not_exists order_number = Ordering::FakeNumberGenerator::FAKE_NUMBER event_store.publish( - Ordering::ItemAddedToBasket.new( + Pricing::PriceItemAdded.new( data: { order_id: order_id, product_id: product_id, - quantity_before: 0 } ) ) diff --git a/rails_application/test/orders/update_order_total_value_test.rb b/rails_application/test/orders/update_order_total_value_test.rb index 50f432b64..7426999e9 100644 --- a/rails_application/test/orders/update_order_total_value_test.rb +++ b/rails_application/test/orders/update_order_total_value_test.rb @@ -36,7 +36,7 @@ def test_newest_event_is_always_applied private def item_added_to_basket(order_id, product_id) - event_store.publish(Ordering::ItemAddedToBasket.new(data: { product_id: product_id, order_id: order_id, quantity_before: 0 })) + event_store.publish(Pricing::PriceItemAdded.new(data: { product_id: product_id, order_id: order_id })) end def prepare_product(product_id)