Add BuyXGetOneFreeDiscount
This commit is contained in:
+22
-13
@@ -1,13 +1,30 @@
|
||||
require "minitest/autorun"
|
||||
|
||||
require "checkout.rb"
|
||||
require "buy_x_get_one_free_discount.rb"
|
||||
|
||||
class CheckoutTest < Minitest::Test
|
||||
def setup
|
||||
@shop = Shop.new
|
||||
@shop.add_product(Product.new(id: 'PI5', price: 60.00))
|
||||
@shop.add_product(Product.new(id: 'ZERO2W', price: 15.00))
|
||||
@shop.add_product(Product.new(id: 'PICO2', price: 4.00))
|
||||
@shop.add_product(
|
||||
Product.new(
|
||||
id: 'PI5',
|
||||
price: 60.00
|
||||
)
|
||||
)
|
||||
@shop.add_product(
|
||||
Product.new(
|
||||
id: 'ZERO2W',
|
||||
price: 15.00,
|
||||
discount: BuyXGetOneFreeDiscount.new(unit_price: 15.00, trigger_quantity: 2)
|
||||
)
|
||||
)
|
||||
@shop.add_product(
|
||||
Product.new(
|
||||
id: 'PICO2',
|
||||
price: 4.00
|
||||
)
|
||||
)
|
||||
@checkout = Checkout.new(shop: @shop)
|
||||
end
|
||||
|
||||
@@ -69,21 +86,13 @@ class CheckoutTest < Minitest::Test
|
||||
# Discounts
|
||||
|
||||
def test_that_bogof_applied
|
||||
skip
|
||||
|
||||
4.times do
|
||||
@checkout.add(:ZERO2W) # Should remove 2 Zeros
|
||||
end
|
||||
@checkout.add(product_id: 'ZERO2W', quantity: 4) # Should remove 2 Zeros
|
||||
|
||||
assert_equal 30.00, @checkout.total
|
||||
end
|
||||
|
||||
def test_that_bogof_applied_with_odd_number
|
||||
skip
|
||||
|
||||
5.times do
|
||||
@checkout.add(:ZERO2W) # Should still remove 2 Zeros, 5th is full price
|
||||
end
|
||||
@checkout.add(product_id: 'ZERO2W', quantity: 5) # Should still remove 2 Zeros, 5th is full price
|
||||
|
||||
assert_equal 45.00, @checkout.total
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user