1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/test/services/cart/refresh_item_service_test.rb
2022-10-25 19:10:14 +02:00

26 lines
813 B
Ruby

# frozen_string_literal: true
require 'test_helper'
class Cart::RefreshItemServiceTest < ActiveSupport::TestCase
setup do
@panneaux = Product.find_by(slug: 'panneaux-de-mdf')
@cart1 = Order.find_by(token: 'KbSmmD_gi9w_CrpwtK9OwA1666687433963')
@cart2 = Order.find_by(token: 'MkI5z9qVxe_YdNYCR_WN6g1666628074732')
end
test 'refresh total and item amount if product change amount' do
@panneaux.amount = 10_000
@panneaux.save
cart = Cart::RefreshItemService.new.call(@cart1, @panneaux)
assert_equal cart.total, 10_000
assert_equal cart.order_items.first.amount, 10_000
end
test 'cannot refresh total and item amount if product isnt in cart' do
assert_raise ActiveRecord::RecordNotFound do
Cart::RefreshItemService.new.call(@cart2, @panneaux)
end
end
end