Skip to content

Commit 3ac2b57

Browse files
committed
kill mutants
1 parent 41cebf0 commit 3ac2b57

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

ecommerce/pricing/lib/pricing/default_pricing_policy.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ def initialize(pricing_catalog)
66
end
77

88
def apply(items, add_product_id = nil)
9-
items
10-
items += [catalog_price_for(add_product_id)] if add_product_id
11-
items.map { |item| apply_discounts(item) }
9+
ret = items.map do |item|
10+
Offer::ItemPrice.new(
11+
item.product_id,
12+
item.catalog_price,
13+
apply_discounts(item.catalog_price)
14+
)
15+
end
16+
ret << Offer::ItemPrice.new(
17+
add_product_id,
18+
catalog_price_for(add_product_id),
19+
apply_discounts(catalog_price_for(add_product_id))
20+
) if add_product_id
21+
ret
1222
end
1323

1424
def add_discount(discount)
1525
@discounts << discount
16-
self
1726
end
1827

1928
private
2029

2130
def catalog_price_for(product_id)
22-
price = @pricing_catalog.price_by_product_id(product_id)
23-
Offer::ItemPrice.new(product_id, price, price)
31+
@pricing_catalog.price_by_product_id(product_id)
2432
end
2533

26-
def apply_discounts(item)
27-
price = @discounts.inject(Discounts::NoPercentageDiscount.new, :add).apply(item.catalog_price)
28-
Offer::ItemPrice.new(item.product_id, item.catalog_price, price)
34+
def apply_discounts(price)
35+
@discounts.inject(Discounts::NoPercentageDiscount.new, :add).apply(price)
2936
end
3037
end
3138
end

ecommerce/pricing/lib/pricing/offer.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def remove_discount(type, pricing_policy)
6868
type: type
6969
}
7070
)
71-
apply_discounts_to_pricing_policy(pricing_policy, except_type: type)
71+
apply_discounts_to_pricing_policy(pricing_policy)
7272
recalculate_prices(pricing_policy)
7373
end
7474

@@ -120,11 +120,8 @@ def use_coupon(coupon_id, discount)
120120

121121
private
122122

123-
def apply_discounts_to_pricing_policy(pricing_policy, discount = nil, except_type: nil)
124-
@discounts.each do |discount|
125-
pricing_policy.add_discount(discount) unless discount.type == except_type
126-
end
127-
pricing_policy.add_discount(discount) if discount
123+
def apply_discounts_to_pricing_policy(pricing_policy)
124+
@discounts.each {|discount| pricing_policy.add_discount(discount) }
128125
end
129126

130127
on PriceItemAdded do |event|
@@ -163,10 +160,6 @@ def apply_discounts_to_pricing_policy(pricing_policy, discount = nil, except_typ
163160
@list.replace(FreeProduct, Product, event.data.fetch(:product_id))
164161
end
165162

166-
def calculate_total_sub_discounts(pricing_catalog)
167-
@list.sub_discounts(pricing_catalog, @discounts)
168-
end
169-
170163
on CouponUsed do |event|
171164
end
172165

ecommerce/pricing/lib/pricing/services.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ def call(cmd)
4646
class ChangePercentageDiscountHandler
4747
def initialize(event_store)
4848
@repository = Infra::AggregateRootRepository.new(event_store)
49-
@event_store = event_store
5049
end
5150

5251
def call(cmd)
5352
@repository.with_aggregate(Offer, cmd.aggregate_id) do |order|
5453
order.change_discount(
5554
Discounts::PercentageDiscount.new(cmd.amount),
56-
DefaultPricingPolicy.new(PricingCatalog.new(@event_store))
55+
DefaultPricingPolicy.new(nil)
5756
)
5857
end
5958
end

0 commit comments

Comments
 (0)