1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-06 01:08:21 +01:00
fab-manager/test/services/coupon_apply_service_test.rb

29 lines
827 B
Ruby
Raw Normal View History

require 'test_helper'
class CouponApplyServiceTest < ActiveSupport::TestCase
setup do
@jdupond = User.find_by(username: 'jdupond')
@cash_coupon = Coupon.find_by(code: 'ZERG6H1R65H')
end
test 'user apply percent coupon to cart' do
total = CouponApplyService.new.(1000, 'SUNNYFABLAB', @jdupond.id)
assert_equal 850, total
end
test 'user cannot apply excessive coupon to cart' do
total = CouponApplyService.new.(1000, @cash_coupon, @jdupond.id)
assert_equal 1000, total
end
test 'user cannot apply invalid coupon to cart' do
total = CouponApplyService.new.(1000, 'INVALIDCODE', @jdupond.id)
assert_equal 1000, total
end
test 'user cannot apply expired coupon to cart' do
total = CouponApplyService.new.(1000, 'XMAS10', @jdupond.id)
assert_equal 1000, total
end
end