Skip to content

Commit

Permalink
Adjust tests to rely on Pricing events
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejkrzywda committed Sep 27, 2024
1 parent 120070d commit 9df0c40
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion rails_application/test/client_orders/discount_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def test_add_another_item
data: {
order_id: order_id,
product_id: another_product_id,
quantity_before: 0
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 7 additions & 13 deletions rails_application/test/orders/broadcast_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
)
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
)
)
Expand Down Expand Up @@ -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
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion rails_application/test/orders/discount_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions rails_application/test/orders/order_expired_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
)
Expand Down
3 changes: 1 addition & 2 deletions rails_application/test/orders/order_placed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9df0c40

Please sign in to comment.