File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ class TotalOrderValue
66 Pricing ::PriceItemAdded ,
77 Pricing ::PriceItemRemoved ,
88 Pricing ::PercentageDiscountSet ,
9- Pricing ::PercentageDiscountChanged
9+ Pricing ::PercentageDiscountChanged ,
10+ Pricing ::PercentageDiscountRemoved
1011 )
1112
1213 private
@@ -30,6 +31,8 @@ def apply(event)
3031 state . with ( discount_amount : event . data . fetch ( :amount ) )
3132 when Pricing ::PercentageDiscountChanged
3233 state . with ( discount_amount : event . data . fetch ( :amount ) )
34+ when Pricing ::PercentageDiscountRemoved
35+ state . with ( discount_amount : 0 )
3336 else
3437 state
3538 end
Original file line number Diff line number Diff line change @@ -155,6 +155,36 @@ def test_changed_discount
155155 end
156156 end
157157
158+ def test_removed_discount
159+ process = TotalOrderValue . new ( event_store , command_bus )
160+ product_id = SecureRandom . uuid
161+ event_1 = price_item_added ( product_id )
162+ event_2 = Pricing ::PercentageDiscountSet . new ( data : {
163+ order_id : order_id ,
164+ type : "test_discount" ,
165+ amount : 10
166+ } )
167+ event_3 = Pricing ::PercentageDiscountRemoved . new ( data : {
168+ order_id : order_id ,
169+ type : "test_discount"
170+ } )
171+ event_store . append ( event_1 )
172+ event_store . append ( event_2 )
173+ event_store . append ( event_3 )
174+ process . call ( event_1 )
175+ process . call ( event_2 )
176+ assert_events_contain (
177+ "Processes::TotalOrderValue$#{ event_3 . data [ :order_id ] } " ,
178+ Processes ::TotalOrderValueUpdated . new (
179+ data : {
180+ total_value : 100 ,
181+ order_id : order_id
182+ }
183+ ) ) do
184+ process . call ( event_3 )
185+ end
186+ end
187+
158188
159189
160190 private
You can’t perform that action at this time.
0 commit comments