1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/test/services/cart/update_total_service_test.rb

24 lines
774 B
Ruby
Raw Normal View History

2022-10-25 19:10:14 +02:00
# frozen_string_literal: true
require 'test_helper'
class Cart::UpdateTotalServiceTest < ActiveSupport::TestCase
setup do
@panneaux = Product.find_by(slug: 'panneaux-de-mdf')
end
test 'total equal to product amount multiplied quantity' do
order = Order.new
order.order_items.push OrderItem.new(orderable: @panneaux, amount: @panneaux.amount, quantity: 10)
cart = Cart::UpdateTotalService.new.call(order)
assert_equal cart.total, @panneaux.amount * 10
end
test 'total equal to zero if product offered' do
order = Order.new
order.order_items.push OrderItem.new(orderable: @panneaux, amount: @panneaux.amount, quantity: 10, is_offered: true)
cart = Cart::UpdateTotalService.new.call(order)
assert_equal cart.total, 0
end
end