Skip to content

Commit 54996c6

Browse files
committed
Revert "Three plus one gratis alternative implementation"
This reverts commit 41f02bd.
1 parent 63b936a commit 54996c6

File tree

5 files changed

+0
-231
lines changed

5 files changed

+0
-231
lines changed

ecommerce/pricing/lib/pricing/discounts.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ module Discounts
66
class UnacceptableDiscountRange < StandardError
77
end
88

9-
class BasePriceNotProvided < StandardError
10-
end
11-
129
class Discount
1310
def self.build(discount)
1411
if discount.zero?
@@ -63,16 +60,5 @@ def add(other_discount)
6360
def exists?
6461
end
6562
end
66-
67-
class ThreePlusOneGratis
68-
def apply(product_quantities, product_id, base_price)
69-
raise BasePriceNotProvided unless base_price
70-
product = product_quantities.find { |product_quantity| product_quantity.fetch(:product_id) == product_id }
71-
return [false, base_price] if product.nil?
72-
quantity = product.fetch(:quantity) + 1
73-
return [false, base_price] if !quantity.%(4).eql?(0)
74-
[true, 0]
75-
end
76-
end
7763
end
7864
end

ecommerce/pricing/lib/pricing/events.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ class PriceItemRemoved < Infra::Event
5656
attribute :total_value, Infra::Types::Price
5757
end
5858

59-
class DiscountApplied < Infra::Event
60-
attribute :order_id, Infra::Types::UUID
61-
attribute :base_total_value, Infra::Types::Price
62-
attribute :total_value, Infra::Types::Price
63-
end
64-
6559
class PercentageDiscountRemoved < Infra::Event
6660
attribute :order_id, Infra::Types::UUID
6761
attribute :type, Infra::Types::String

ecommerce/pricing/lib/pricing/offer.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ def initialize(id)
1010
@list = List.new
1111
@discounts = []
1212
@state = :draft
13-
14-
@three_plus_one_gratis = Discounts::ThreePlusOneGratis.new(@list)
1513
end
1614

1715
def add_item(product_id, base_price)
@@ -26,15 +24,6 @@ def add_item(product_id, base_price)
2624
total_value: @list.actual_sum + price
2725
}
2826
)
29-
30-
anything_applied = @three_plus_one_gratis.apply(base_price)
31-
apply DiscountApplied.new(
32-
data: {
33-
order_id: @id,
34-
base_total_value: @list.base_sum,
35-
total_value: @list.actual_sum
36-
}
37-
) if anything_applied
3827
end
3928

4029
def remove_item(product_id)
@@ -173,10 +162,6 @@ def expire
173162

174163
private
175164

176-
on DiscountApplied do |event|
177-
# TODO: Something about discount?
178-
end
179-
180165
on PriceItemAdded do |event|
181166
@list.add_item(event.data.fetch(:product_id), event.data.fetch(:base_price), event.data.fetch(:price))
182167
end

ecommerce/pricing/test/discounts_test.rb

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -64,61 +64,5 @@ def test_doesnt_change_total
6464
assert_equal(100, NoPercentageDiscount.new.apply(100))
6565
end
6666
end
67-
class ThreePlusOneGratisTest < Test
68-
cover "Pricing::Discounts*"
69-
def setup
70-
@three_plus_one_gratis = ThreePlusOneGratis.new
71-
@product_id = SecureRandom.uuid
72-
end
73-
74-
def test_returns_full_price_when_product_not_found
75-
result = @three_plus_one_gratis.apply([], @product_id, 20)
76-
assert_equal [false, 20], result
77-
end
78-
79-
def test_returns_full_price_when_quantity_plus_one_is_less_than_4
80-
quantities = [{ product_id: @product_id, quantity: 2 }]
81-
result = @three_plus_one_gratis.apply(quantities, @product_id, 20)
82-
assert_equal [false, 20], result
83-
end
84-
85-
def test_returns_free_when_quantity_plus_one_is_4
86-
quantities = [{ product_id: @product_id, quantity: 3 }]
87-
result = @three_plus_one_gratis.apply(quantities, @product_id, 20)
88-
assert_equal [true, 0], result
89-
end
90-
91-
def test_returns_full_price_when_quantity_plus_one_is_5
92-
quantities = [{ product_id: @product_id, quantity: 4 }]
93-
result = @three_plus_one_gratis.apply(quantities, @product_id, 20)
94-
assert_equal [false, 20], result
95-
end
96-
97-
def test_returns_free_when_quantity_plus_one_is_8
98-
quantities = [{ product_id: @product_id, quantity: 7 }]
99-
result = @three_plus_one_gratis.apply(quantities, @product_id, 20)
100-
assert_equal [true, 0], result
101-
end
102-
103-
def test_returns_full_price_when_quantity_plus_one_is_9
104-
quantities = [{ product_id: @product_id, quantity: 8 }]
105-
result = @three_plus_one_gratis.apply(quantities, @product_id, 20)
106-
assert_equal [false, 20], result
107-
end
108-
109-
def test_does_not_confuse_other_product_ids
110-
other_product_id = SecureRandom.uuid
111-
quantities = [{ product_id: other_product_id, quantity: 3 }]
112-
result = @three_plus_one_gratis.apply(quantities, @product_id, 20)
113-
assert_equal [false, 20], result
114-
end
115-
116-
def test_raises_exeption_when_base_price_is_nil
117-
quantities = [{ product_id: @product_id, quantity: 8 }]
118-
assert_raises BasePriceNotProvided do
119-
@three_plus_one_gratis.apply(quantities, @product_id, nil)
120-
end
121-
end
122-
end
12367
end
12468
end

ecommerce/pricing/test/three_plus_one_test.rb

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

0 commit comments

Comments
 (0)