1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-12 23:09:03 +01:00
fab-manager/test/services/cart/set_offer_service_test.rb

25 lines
783 B
Ruby
Raw Normal View History

2022-10-25 19:10:14 +02:00
# frozen_string_literal: true
require 'test_helper'
class Cart::SetOfferServiceTest < ActiveSupport::TestCase
setup do
@caisse_en_bois = Product.find_by(slug: 'caisse-en-bois')
@panneaux = Product.find_by(slug: 'panneaux-de-mdf')
@cart = Order.find_by(token: '0DKxbAOzSXRx-amXyhmDdg1666691976019')
end
test 'set offer product in cart' do
cart = Cart::SetOfferService.new.call(@cart, @caisse_en_bois, true)
assert_equal cart.total, 0
assert_equal cart.order_items.first.amount, @caisse_en_bois.amount
assert_equal cart.order_items.first.is_offered, true
end
test 'cannot set offer if product that isnt in cart' do
assert_raise ActiveRecord::RecordNotFound do
Cart::SetOfferService.new.call(@cart, @panneaux, true)
end
end
end