Skip to content

Commit

Permalink
Rely on Pricing/Offering events instead of Ordering
Browse files Browse the repository at this point in the history
We want to remove items tracking from Ordering eventually.
  • Loading branch information
andrzejkrzywda committed Sep 27, 2024
1 parent d46feee commit 120070d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def call(event_store)
event_store.subscribe(OrderHandlers::CancelOrder, to: [Fulfillment::OrderCancelled])
event_store.subscribe(OrderHandlers::SubmitOrder, to: [Ordering::OrderPlaced])
event_store.subscribe(OrderHandlers::ConfirmOrder, to: [Fulfillment::OrderConfirmed])
event_store.subscribe(AddItemToOrder, to: [Ordering::ItemAddedToBasket])
event_store.subscribe(RemoveItemFromOrder, to: [Ordering::ItemRemovedFromBasket])
event_store.subscribe(AddItemToOrder, to: [Pricing::PriceItemAdded])
event_store.subscribe(RemoveItemFromOrder, to: [Pricing::PriceItemRemoved])

event_store.subscribe(CreateCustomer.new, to: [Crm::CustomerRegistered])
event_store.subscribe(OrderHandlers::AssignCustomerToOrder, to: [Crm::CustomerAssignedToOrder])
Expand Down
4 changes: 2 additions & 2 deletions rails_application/app/read_models/orders/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def call(event_store)

Rails.configuration.broadcaster = Orders::Broadcaster.new

event_store.subscribe(AddItemToOrder.new, to: [Ordering::ItemAddedToBasket])
event_store.subscribe(RemoveItemFromOrder.new, to: [Ordering::ItemRemovedFromBasket])
event_store.subscribe(AddItemToOrder.new, to: [Pricing::PriceItemAdded])
event_store.subscribe(RemoveItemFromOrder.new, to: [Pricing::PriceItemRemoved])
event_store.subscribe(UpdateDiscount.new, to: [Pricing::PercentageDiscountSet, Pricing::PercentageDiscountChanged])
event_store.subscribe(ResetDiscount.new, to: [Pricing::PercentageDiscountReset])
event_store.subscribe(UpdateOrderTotalValue.new, to: [Pricing::OrderTotalValueCalculated])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ def test_add_new_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
}
)
)
Expand Down Expand Up @@ -73,21 +72,19 @@ def test_add_the_same_item_2nd_time

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
}
)
)
Expand Down Expand Up @@ -142,17 +139,16 @@ def test_add_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: another_product_id,
Expand Down
2 changes: 1 addition & 1 deletion rails_application/test/integration/orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def assert_res_browser_order_history
.map { |data| data.fetch("attributes").fetch("event_type") }

assert(event_names.include?("Fulfillment::OrderConfirmed"))
assert(event_names.include?("Ordering::ItemAddedToBasket"))
assert(event_names.include?("Pricing::PriceItemAdded"))
assert(event_names.include?("Pricing::OrderTotalValueCalculated"))
assert(event_names.include?("Ordering::OrderPlaced"))
end
Expand Down
15 changes: 5 additions & 10 deletions rails_application/test/orders/item_added_to_basket_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ def test_add_new_item

order_id = SecureRandom.uuid

item_added_to_basket = Ordering::ItemAddedToBasket.new(
item_added_to_basket = Pricing::PriceItemAdded.new(
data: {
order_id: order_id,
product_id: product_id,
quantity_before: 0
}
)
event_store.publish(item_added_to_basket)
Expand Down Expand Up @@ -73,21 +72,19 @@ def test_add_the_same_item_2nd_time

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
}
)
)
Expand Down Expand Up @@ -142,21 +139,19 @@ def test_add_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: another_product_id,
quantity_before: 0
}
)
)
Expand Down
24 changes: 9 additions & 15 deletions rails_application/test/orders/item_removed_from_basket_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,22 @@ 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
}
)
)
item_removed_from_basket = Ordering::ItemRemovedFromBasket.new(
item_removed_from_basket = Pricing::PriceItemRemoved.new(
data: {
order_id: order_id,
product_id: product_id
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 120070d

Please sign in to comment.