Skip to content

Commit c4a2558

Browse files
committed
make Ordering test GREEN; temporarily make Ordering tests dependent on Pricing and Fulfillment
1 parent 5f383fc commit c4a2558

File tree

7 files changed

+104
-24
lines changed

7 files changed

+104
-24
lines changed

ecommerce/ordering/.mutant.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ matcher:
1111
- Ordering::Test*
1212
- Ordering::Configuration#call
1313
- Ordering::Configuration#initialize
14+
- Ordering::RefundableProducts#call
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
module Ordering
22
class RefundableProducts
33
def call(event_store, order_id)
4-
event_store
4+
accepted_event = event_store
55
.read.backward
66
.stream("Pricing::Offer$#{order_id}")
77
.of_type(Pricing::OfferAccepted)
88
.first
9-
&.data
10-
&.fetch(:order_lines) || []
9+
10+
placed_event = event_store
11+
.read
12+
.stream("Fulfillment::Order$#{order_id}")
13+
.first
14+
15+
accepted_event.data.fetch(:order_lines) if placed_event
1116
end
1217
end
1318
end

ecommerce/ordering/test/add_item_to_refund_test.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ def test_add_item_to_refund
1313
stream = "Ordering::Refund$#{aggregate_id}"
1414

1515
arrange(
16-
AddItemToBasket.new(order_id: order_id, product_id: product_1_id),
17-
AddItemToBasket.new(order_id: order_id, product_id: product_2_id),
18-
AddItemToBasket.new(order_id: order_id, product_id: product_2_id),
19-
AddItemToBasket.new(order_id: order_id, product_id: product_3_id),
16+
Pricing::SetPrice.new(product_id: product_1_id, price: 11),
17+
Pricing::SetPrice.new(product_id: product_2_id, price: 22),
18+
Pricing::SetPrice.new(product_id: product_3_id, price: 33),
19+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_1_id),
20+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_2_id),
21+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_2_id),
22+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_3_id),
23+
Pricing::AcceptOffer.new(order_id: order_id),
24+
Fulfillment::RegisterOrder.new(order_id: order_id),
2025
CreateDraftRefund.new(refund_id: aggregate_id, order_id: order_id),
2126
AddItemToRefund.new(
2227
refund_id: aggregate_id,
@@ -52,7 +57,10 @@ def test_add_item_raises_exceeds_order_quantity_error
5257
product_id = SecureRandom.uuid
5358

5459
arrange(
55-
AddItemToBasket.new(order_id: order_id, product_id: product_id),
60+
Pricing::SetPrice.new(product_id: product_id, price: 11),
61+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id),
62+
Pricing::AcceptOffer.new(order_id: order_id),
63+
Fulfillment::RegisterOrder.new(order_id: order_id),
5664
CreateDraftRefund.new(refund_id: aggregate_id, order_id: order_id),
5765
AddItemToRefund.new(
5866
refund_id: aggregate_id,

ecommerce/ordering/test/create_draft_refund_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ class CreateDraftRefundTest < Test
77
def test_draft_refund_created
88
order_id = SecureRandom.uuid
99
aggregate_id = SecureRandom.uuid
10+
product_id = SecureRandom.uuid
1011
stream = "Ordering::Refund$#{aggregate_id}"
1112

13+
arrange(
14+
Pricing::SetPrice.new(product_id: product_id, price: 11),
15+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id),
16+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id),
17+
Pricing::AcceptOffer.new(order_id: order_id),
18+
Fulfillment::RegisterOrder.new(order_id: order_id),
19+
)
20+
1221
expected_events = [
1322
DraftRefundCreated.new(
1423
data: {
1524
refund_id: aggregate_id,
1625
order_id: order_id,
17-
refundable_products: []
26+
refundable_products: [{ product_id:, quantity: 2 }]
1827
}
1928
)
2029
]

ecommerce/ordering/test/refundable_products_test.rb

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,67 @@ class RefundableProductsTest < Test
66

77
def test_product_quantity_available_to_refund
88
order_id = SecureRandom.uuid
9+
order_number = Fulfillment::FakeNumberGenerator::FAKE_NUMBER
910
product_1_id = SecureRandom.uuid
1011
product_2_id = SecureRandom.uuid
1112
product_3_id = SecureRandom.uuid
12-
stream_name = "Ordering::Order$#{order_id}"
13-
projection = RefundableProducts.call(order_id)
13+
stream_name = "Pricing::Offer$#{order_id}"
1414

1515
event_store = RubyEventStore::Client.new(repository: RubyEventStore::InMemoryRepository.new)
1616

17-
event_store.publish(ItemAddedToBasket.new(data: { order_id: order_id, product_id: product_3_id }), stream_name: stream_name)
18-
event_store.publish(ItemAddedToBasket.new(data: { order_id: order_id, product_id: product_1_id }), stream_name: stream_name)
19-
event_store.publish(ItemAddedToBasket.new(data: { order_id: order_id, product_id: product_2_id }), stream_name: stream_name)
20-
event_store.publish(ItemAddedToBasket.new(data: { order_id: order_id, product_id: product_2_id }), stream_name: stream_name)
21-
event_store.publish(ItemRemovedFromBasket.new(data: { order_id: order_id, product_id: product_2_id }), stream_name: stream_name)
22-
event_store.publish(ItemRemovedFromBasket.new(data: { order_id: order_id, product_id: product_3_id }), stream_name: stream_name)
17+
event_store.publish(
18+
[
19+
Pricing::OfferAccepted.new(
20+
data: {
21+
order_id: order_id,
22+
order_lines: [
23+
{ product_id: product_3_id, quantity: 1 },
24+
{ product_id: product_1_id, quantity: 1 },
25+
{ product_id: product_2_id, quantity: 2 },
26+
]
27+
}),
28+
Pricing::OfferAccepted.new(
29+
data: {
30+
order_id: order_id,
31+
order_lines: [
32+
{ product_id: product_1_id, quantity: 1 },
33+
{ product_id: product_2_id, quantity: 1 }
34+
]
35+
}
36+
),
37+
],
38+
stream_name: stream_name
39+
)
40+
event_store.publish(
41+
[Fulfillment::OrderRegistered.new(data: { order_id:, order_number: })],
42+
stream_name: "Fulfillment::Order$#{order_id}"
43+
)
2344

24-
refundable_products = projection.run(event_store)
45+
refundable_products = RefundableProducts.new.call(event_store, order_id)
2546

26-
assert_equal([{ product_id: product_1_id, quantity: 1}, {product_id: product_2_id, quantity: 1 }], refundable_products)
47+
assert_equal([{ product_id: product_1_id, quantity: 1 }, { product_id: product_2_id, quantity: 1 }], refundable_products)
48+
end
49+
50+
def test_order_have_to_be_placed
51+
order_id = SecureRandom.uuid
52+
stream_name = "Pricing::Offer$#{order_id}"
53+
54+
event_store = RubyEventStore::Client.new(repository: RubyEventStore::InMemoryRepository.new)
55+
56+
event_store.publish(
57+
[
58+
Pricing::OfferAccepted.new(
59+
data: {
60+
order_id: order_id,
61+
order_lines: [
62+
{ product_id: SecureRandom.uuid, quantity: 1 },
63+
{ product_id: SecureRandom.uuid, quantity: 1 },
64+
]
65+
}),
66+
],
67+
stream_name: stream_name)
68+
69+
assert_nil(RefundableProducts.new.call(event_store, order_id))
2770
end
2871
end
2972
end

ecommerce/ordering/test/remove_item_from_refund_test.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ def test_removing_items_from_refund
1313
stream = "Ordering::Refund$#{aggregate_id}"
1414

1515
arrange(
16-
AddItemToBasket.new(order_id: order_id, product_id: product_1_id),
17-
AddItemToBasket.new(order_id: order_id, product_id: product_2_id),
18-
AddItemToBasket.new(order_id: order_id, product_id: product_2_id),
19-
AddItemToBasket.new(order_id: order_id, product_id: product_3_id),
16+
Pricing::SetPrice.new(product_id: product_1_id, price: 11),
17+
Pricing::SetPrice.new(product_id: product_2_id, price: 22),
18+
Pricing::SetPrice.new(product_id: product_3_id, price: 33),
19+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_1_id),
20+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_2_id),
21+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_2_id),
22+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_3_id),
23+
Pricing::AcceptOffer.new(order_id: order_id),
24+
Fulfillment::RegisterOrder.new(order_id: order_id),
2025
CreateDraftRefund.new(
2126
refund_id: aggregate_id,
2227
order_id: order_id
@@ -55,7 +60,10 @@ def test_cant_remove_item_with_0_quantity
5560
product_id = SecureRandom.uuid
5661

5762
arrange(
58-
AddItemToBasket.new(order_id: order_id, product_id: product_id),
63+
Pricing::SetPrice.new(product_id: product_id, price: 11),
64+
Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id),
65+
Pricing::AcceptOffer.new(order_id: order_id),
66+
Fulfillment::RegisterOrder.new(order_id: order_id),
5967
CreateDraftRefund.new(
6068
refund_id: aggregate_id,
6169
order_id: order_id

ecommerce/ordering/test/test_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33

44
require_relative "../lib/ordering"
55

6+
require_relative "../../pricing/lib/pricing"
7+
require_relative "../../fulfillment/lib/fulfillment"
8+
69
module Ordering
710
class Test < Infra::InMemoryTest
811
def before_setup
12+
generator = -> { Fulfillment::FakeNumberGenerator.new }
913
super
1014
Configuration.new.call(event_store, command_bus)
15+
Pricing::Configuration.new.call(event_store, command_bus)
16+
Fulfillment::Configuration.new(generator).call(event_store, command_bus)
1117
end
1218
end
1319
end

0 commit comments

Comments
 (0)