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')
|
2022-11-07 18:52:43 +01:00
|
|
|
@filament = Product.find_by(slug: 'filament-pla-blanc')
|
2022-10-25 19:10:14 +02:00
|
|
|
@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)
|
2022-11-07 18:52:43 +01:00
|
|
|
assert_equal cart.total, 1000
|
2022-10-25 19:10:14 +02:00
|
|
|
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
|
2022-11-07 18:52:43 +01:00
|
|
|
Cart::SetOfferService.new.call(@cart, @filament, true)
|
2022-10-25 19:10:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|