Skip to content

Commit a686775

Browse files
Replaced commands with events in the Orders read model test
We still have integration tests to test the "contracts", so hopefully even if there's mismatch between events in real world and the tests, this will be caught. It "feels" simpler and better to test with events. But yeah, without discipline - it may catch us.
1 parent 2d3aea3 commit a686775

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

rails_application/test/orders/item_added_to_basket_test.rb

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ def test_add_new_item
88
event_store = Rails.configuration.event_store
99

1010
product_id = SecureRandom.uuid
11-
run_command(
12-
ProductCatalog::RegisterProduct.new(
13-
product_id: product_id,
11+
event_store.publish(
12+
ProductCatalog::ProductRegistered.new(
13+
data: { product_id: product_id }
1414
)
1515
)
16-
run_command(
17-
ProductCatalog::NameProduct.new(
18-
product_id: product_id,
19-
name: "test"
16+
event_store.publish(
17+
ProductCatalog::ProductNamed.new(
18+
data: { product_id: product_id, name: "test" }
2019
)
2120
)
22-
run_command(Pricing::SetPrice.new(product_id: product_id, price: 49))
21+
event_store.publish(
22+
Pricing::PriceSet.new(data: { product_id: product_id, price: 49 })
23+
)
2324

2425
order_id = SecureRandom.uuid
2526

@@ -55,18 +56,19 @@ def test_add_the_same_item_2nd_time
5556
event_store = Rails.configuration.event_store
5657

5758
product_id = SecureRandom.uuid
58-
run_command(
59-
ProductCatalog::RegisterProduct.new(
60-
product_id: product_id,
59+
event_store.publish(
60+
ProductCatalog::ProductRegistered.new(
61+
data: { product_id: product_id }
6162
)
6263
)
63-
run_command(
64-
ProductCatalog::NameProduct.new(
65-
product_id: product_id,
66-
name: "test"
64+
event_store.publish(
65+
ProductCatalog::ProductNamed.new(
66+
data: { product_id: product_id, name: "test" }
6767
)
6868
)
69-
run_command(Pricing::SetPrice.new(product_id: product_id, price: 49))
69+
event_store.publish(
70+
Pricing::PriceSet.new(data: { product_id: product_id, price: 49 })
71+
)
7072

7173
order_id = SecureRandom.uuid
7274
event_store.publish(
@@ -114,33 +116,33 @@ def test_add_another_item
114116
event_store = Rails.configuration.event_store
115117

116118
product_id = SecureRandom.uuid
117-
run_command(
118-
ProductCatalog::RegisterProduct.new(
119-
product_id: product_id,
119+
event_store.publish(
120+
ProductCatalog::ProductRegistered.new(
121+
data: { product_id: product_id }
120122
)
121123
)
122-
run_command(
123-
ProductCatalog::NameProduct.new(
124-
product_id: product_id,
125-
name: "test"
124+
event_store.publish(
125+
ProductCatalog::ProductNamed.new(
126+
data: { product_id: product_id, name: "test" }
126127
)
127128
)
128-
run_command(Pricing::SetPrice.new(product_id: product_id, price: 20))
129+
event_store.publish(
130+
Pricing::PriceSet.new(data: { product_id: product_id, price: 20 })
131+
)
129132

130133
another_product_id = SecureRandom.uuid
131-
run_command(
132-
ProductCatalog::RegisterProduct.new(
133-
product_id: another_product_id,
134+
event_store.publish(
135+
ProductCatalog::ProductRegistered.new(
136+
data: { product_id: another_product_id }
134137
)
135138
)
136-
run_command(
137-
ProductCatalog::NameProduct.new(
138-
product_id: another_product_id,
139-
name: "2nd one"
139+
event_store.publish(
140+
ProductCatalog::ProductNamed.new(
141+
data: { product_id: another_product_id, name: "2nd one" }
140142
)
141143
)
142-
run_command(
143-
Pricing::SetPrice.new(product_id: another_product_id, price: 20)
144+
event_store.publish(
145+
Pricing::PriceSet.new(data: { product_id: another_product_id, price: 20 })
144146
)
145147

146148
order_id = SecureRandom.uuid

0 commit comments

Comments
 (0)