Reimplement checkout item removal. All existing tests now pass
This commit is contained in:
+17
-35
@@ -127,72 +127,54 @@ class CheckoutTest < Minitest::Test
|
||||
# Item removal
|
||||
|
||||
def test_that_removing_an_item_not_in_the_checkout_removes_nothing
|
||||
skip
|
||||
@checkout.add(product_id: 'PICO2')
|
||||
@checkout.remove(product_id: 'PI5')
|
||||
|
||||
@checkout.add(:PICO2)
|
||||
@checkout.remove(:PI5)
|
||||
|
||||
assert_equal [:PICO2], @checkout.items
|
||||
assert_equal({ 'PICO2' => 1 }, @checkout.item_quantities)
|
||||
end
|
||||
|
||||
def test_that_items_are_removed_one_by_one
|
||||
skip
|
||||
@checkout.add(product_id: 'ZERO2W', quantity: 4)
|
||||
@checkout.add(product_id: 'PICO2', quantity: 3)
|
||||
|
||||
4.times do
|
||||
@checkout.add(:ZERO2W)
|
||||
end
|
||||
assert_equal({ 'ZERO2W' => 4, 'PICO2' => 3 }.sort, @checkout.item_quantities.sort)
|
||||
|
||||
3.times do
|
||||
@checkout.add(:PICO2)
|
||||
end
|
||||
@checkout.remove(product_id: 'ZERO2W')
|
||||
|
||||
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W, :ZERO2W, :PICO2, :PICO2, :PICO2].sort, @checkout.items.sort
|
||||
assert_equal({ 'ZERO2W' => 3, 'PICO2' => 3 }.sort, @checkout.item_quantities.sort)
|
||||
|
||||
@checkout.remove(:ZERO2W)
|
||||
@checkout.remove(product_id: 'PICO2')
|
||||
|
||||
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W, :PICO2, :PICO2, :PICO2].sort, @checkout.items.sort
|
||||
assert_equal({ 'ZERO2W' => 3, 'PICO2' => 2 }.sort, @checkout.item_quantities.sort)
|
||||
|
||||
@checkout.remove(:PICO2)
|
||||
|
||||
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W, :PICO2, :PICO2].sort, @checkout.items.sort
|
||||
@checkout.remove(product_id: 'PICO2', quantity: 2)
|
||||
|
||||
2.times do
|
||||
@checkout.remove(:PICO2)
|
||||
end
|
||||
|
||||
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W].sort, @checkout.items.sort
|
||||
assert_equal({ 'ZERO2W' => 3 }.sort, @checkout.item_quantities.sort)
|
||||
end
|
||||
|
||||
def test_that_total_is_correctly_recalculated_when_items_are_added
|
||||
skip
|
||||
|
||||
2.times do
|
||||
@checkout.add(:PICO2)
|
||||
end
|
||||
@checkout.add(product_id: 'PICO2', quantity: 2)
|
||||
|
||||
assert_equal 8.00, @checkout.total
|
||||
|
||||
@checkout.add(:PICO2) # 3 in total now, so discount applies
|
||||
@checkout.add(product_id: 'PICO2', quantity: 1) # 3 in total now, so discount applies
|
||||
|
||||
assert_equal 10.50, @checkout.total
|
||||
|
||||
4.times do
|
||||
@checkout.add(:ZERO2W) # 30.00 with BOGOF
|
||||
end
|
||||
@checkout.add(product_id: 'ZERO2W', quantity: 4)
|
||||
|
||||
assert_equal 40.50, @checkout.total
|
||||
end
|
||||
|
||||
def test_that_total_is_correctly_recalculated_when_items_are_removed
|
||||
skip
|
||||
|
||||
3.times do
|
||||
@checkout.add(:PICO2) # Bulk discount applies
|
||||
end
|
||||
@checkout.add(product_id: 'PICO2', quantity: 3)
|
||||
|
||||
assert_equal 10.50, @checkout.total
|
||||
|
||||
@checkout.remove(:PICO2) # Bulk discount no longer applies
|
||||
@checkout.remove(product_id: 'PICO2', quantity: 1) # Bulk discount no longer applies
|
||||
|
||||
assert_equal 8.00, @checkout.total
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user