Skip to content

Commit ef1d613

Browse files
Removed PriceItemValueCalculated and CalculateSubAmounts
1 parent 6a9f2fd commit ef1d613

File tree

10 files changed

+0
-255
lines changed

10 files changed

+0
-255
lines changed

ecommerce/pricing/lib/pricing.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require_relative "pricing/price_change"
99
require_relative "pricing/time_promotion"
1010
require_relative "pricing/promotions_calendar"
11-
require_relative "pricing/calculate_order_sub_amounts_value"
1211
require_relative "pricing/apply_time_promotion"
1312

1413
module Pricing
@@ -49,10 +48,6 @@ def call(event_store, command_bus)
4948
SetFuturePrice,
5049
SetFuturePriceHandler.new(event_store)
5150
)
52-
command_bus.register(
53-
CalculateSubAmounts,
54-
OnCalculateSubAmounts.new(event_store).public_method(:calculate_sub_amounts)
55-
)
5651
command_bus.register(
5752
SetPercentageDiscount,
5853
SetPercentageDiscountHandler.new(event_store)
@@ -114,15 +109,6 @@ def call(event_store, command_bus)
114109
ProductMadeFreeForOrder,
115110
FreeProductRemovedFromOrder
116111
])
117-
event_store.subscribe(CalculateOrderTotalSubAmountsValue, to: [
118-
PriceItemAdded,
119-
PriceItemRemoved,
120-
PercentageDiscountSet,
121-
PercentageDiscountRemoved,
122-
PercentageDiscountChanged,
123-
ProductMadeFreeForOrder,
124-
FreeProductRemovedFromOrder
125-
])
126112
end
127113
end
128114
end

ecommerce/pricing/lib/pricing/calculate_order_sub_amounts_value.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

ecommerce/pricing/lib/pricing/commands.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ class RemovePriceItem < Infra::Command
1414
alias aggregate_id order_id
1515
end
1616

17-
class CalculateSubAmounts < Infra::Command
18-
attribute :order_id, Infra::Types::UUID
19-
alias aggregate_id order_id
20-
end
2117

2218
class SetPrice < Infra::Command
2319
attribute :product_id, Infra::Types::UUID

ecommerce/pricing/lib/pricing/events.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ class TimePromotionCreated < Infra::Event
1919
end
2020

2121

22-
class PriceItemValueCalculated < Infra::Event
23-
attribute :order_id, Infra::Types::UUID
24-
attribute :product_id, Infra::Types::UUID
25-
attribute :quantity, Infra::Types::Quantity
26-
attribute :discounted_amount, Infra::Types::Value
27-
attribute :amount, Infra::Types::Value
28-
end
2922

3023
class PercentageDiscountSet < Infra::Event
3124
attribute :order_id, Infra::Types::UUID

ecommerce/pricing/lib/pricing/offer.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,6 @@ def remove_free_product(order_id, product_id)
8888
)
8989
end
9090

91-
92-
def calculate_sub_amounts
93-
sub_amounts_total = @list.sub_amounts_total
94-
95-
sub_amounts_total.each_pair do |product_id, h|
96-
apply(
97-
PriceItemValueCalculated.new(
98-
data: {
99-
order_id: @id,
100-
product_id: product_id,
101-
quantity: h.fetch(:quantity),
102-
amount: h.fetch(:base_amount),
103-
discounted_amount: h.fetch(:amount),
104-
}
105-
)
106-
)
107-
end
108-
end
109-
11091
def use_coupon(coupon_id, discount)
11192
apply CouponUsed.new(
11293
data: {
@@ -152,8 +133,6 @@ def expire
152133
@list.remove_item(event.data.fetch(:product_id), event.data.fetch(:price))
153134
end
154135

155-
on PriceItemValueCalculated do |event|
156-
end
157136

158137

159138
on PercentageDiscountSet do |event|

ecommerce/pricing/lib/pricing/services.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,6 @@ def call(command)
137137
end
138138
end
139139

140-
class OnCalculateSubAmounts
141-
include Infra::Retry
142-
143-
def initialize(event_store)
144-
@repository = Infra::AggregateRootRepository.new(event_store)
145-
end
146-
147-
def calculate_sub_amounts(command)
148-
with_retry do
149-
@repository.with_aggregate(Offer, command.aggregate_id) do |order|
150-
order.calculate_sub_amounts
151-
end
152-
end
153-
end
154-
end
155140

156141
class OnCouponRegister
157142
def initialize(event_store)

ecommerce/pricing/test/pricing_test.rb

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,6 @@ def test_configuration
1313
end
1414

1515

16-
def test_calculates_sub_amounts
17-
product_1_id = SecureRandom.uuid
18-
product_2_id = SecureRandom.uuid
19-
set_price(product_1_id, 20)
20-
set_price(product_2_id, 30)
21-
order_id = SecureRandom.uuid
22-
stream = stream_name(order_id)
23-
24-
assert_events(stream) { calculate_sub_amounts(order_id) }
25-
26-
add_item(order_id, product_1_id)
27-
add_item(order_id, product_2_id)
28-
add_item(order_id, product_2_id)
29-
assert_events(
30-
stream,
31-
PriceItemValueCalculated.new(
32-
data: {
33-
order_id: order_id,
34-
product_id: product_1_id,
35-
quantity: 1,
36-
amount: 20,
37-
discounted_amount: 20
38-
}
39-
),
40-
PriceItemValueCalculated.new(
41-
data: {
42-
order_id: order_id,
43-
product_id: product_2_id,
44-
quantity: 2,
45-
amount: 60,
46-
discounted_amount: 60
47-
}
48-
)
49-
) { calculate_sub_amounts(order_id) }
50-
run_command(
51-
Pricing::SetPercentageDiscount.new(order_id: order_id, amount: 10)
52-
)
53-
assert_events(
54-
stream,
55-
PriceItemValueCalculated.new(
56-
data: {
57-
order_id: order_id,
58-
product_id: product_1_id,
59-
quantity: 1,
60-
amount: 20,
61-
discounted_amount: 18
62-
}
63-
),
64-
PriceItemValueCalculated.new(
65-
data: {
66-
order_id: order_id,
67-
product_id: product_2_id,
68-
quantity: 2,
69-
amount: 60,
70-
discounted_amount: 54
71-
}
72-
)
73-
) { calculate_sub_amounts(order_id) }
74-
end
7516

7617
def test_sets_time_promotion_discount
7718
order_id = SecureRandom.uuid
@@ -369,9 +310,6 @@ def stream_name(order_id)
369310
"Pricing::Offer$#{order_id}"
370311
end
371312

372-
def calculate_sub_amounts(order_id)
373-
run_command(CalculateSubAmounts.new(order_id: order_id))
374-
end
375313

376314
def create_active_time_promotion(discount)
377315
run_command(

ecommerce/pricing/test/simple_offer_test.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ def test_adding
1818
base_price: 20,
1919
price: 20
2020
}
21-
),
22-
PriceItemValueCalculated.new(
23-
data: {
24-
order_id: order_id,
25-
product_id: product_id,
26-
quantity: 1,
27-
amount: 20,
28-
discounted_amount: 20,
29-
}
3021
)
3122
) { add_item(order_id, product_id) }
3223

@@ -39,15 +30,6 @@ def test_adding
3930
base_price: 20,
4031
price: 20
4132
}
42-
),
43-
PriceItemValueCalculated.new(
44-
data: {
45-
order_id: order_id,
46-
product_id: product_id,
47-
quantity: 2,
48-
amount: 40,
49-
discounted_amount: 40,
50-
}
5133
)
5234
) { add_item(order_id, product_id) }
5335

@@ -70,15 +52,6 @@ def test_removing
7052
base_price: 20,
7153
price: 20
7254
}
73-
),
74-
PriceItemValueCalculated.new(
75-
data: {
76-
order_id: order_id,
77-
product_id: product_id,
78-
quantity: 1,
79-
amount: 20,
80-
discounted_amount: 20,
81-
}
8255
)
8356
) { remove_item(order_id, product_id) }
8457

ecommerce/pricing/test/subamounts_test.rb

Lines changed: 0 additions & 41 deletions
This file was deleted.

ecommerce/pricing/test/time_promotion_test.rb

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -65,53 +65,6 @@ def test_calculates_total_value_with_time_promotion
6565
) { add_item(order_id, product_1_id) }
6666
end
6767

68-
def test_calculates_sub_amounts_with_combined_discounts
69-
product_1_id = SecureRandom.uuid
70-
product_2_id = SecureRandom.uuid
71-
set_price(product_1_id, 20)
72-
set_price(product_2_id, 30)
73-
order_id = SecureRandom.uuid
74-
stream = stream_name(order_id)
75-
data = {
76-
time_promotion_id: SecureRandom.uuid,
77-
discount: 50,
78-
start_time: Time.current - 1,
79-
end_time: Time.current + 100,
80-
label: "Last Minute"
81-
}
82-
83-
run_command(CreateTimePromotion.new(data))
84-
85-
add_item(order_id, product_1_id)
86-
add_item(order_id, product_2_id)
87-
add_item(order_id, product_2_id)
88-
89-
run_command(
90-
Pricing::SetPercentageDiscount.new(order_id: order_id, amount: 10)
91-
)
92-
93-
assert_events_contain(
94-
stream,
95-
PriceItemValueCalculated.new(
96-
data: {
97-
order_id: order_id,
98-
product_id: product_1_id,
99-
quantity: 1,
100-
amount: 20,
101-
discounted_amount: 8
102-
}
103-
),
104-
PriceItemValueCalculated.new(
105-
data: {
106-
order_id: order_id,
107-
product_id: product_2_id,
108-
quantity: 2,
109-
amount: 60,
110-
discounted_amount: 24
111-
}
112-
)
113-
) { calculate_sub_amounts(order_id) }
114-
end
11568

11669
def test_cant_create_twice
11770
uid = SecureRandom.uuid
@@ -164,8 +117,5 @@ def set_time_promotion_range(time_promotion_id, start_time, end_time, discount)
164117
)
165118
end
166119

167-
def calculate_sub_amounts(order_id)
168-
run_command(CalculateSubAmounts.new(order_id: order_id))
169-
end
170120
end
171121
end

0 commit comments

Comments
 (0)