1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/test/services/coupon_service_test.rb
2016-11-29 14:57:43 +01:00

29 lines
822 B
Ruby

require 'test_helper'
class CouponServiceTest < 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 = CouponService.new.apply(1000, 'SUNNYFABLAB', @jdupond.id)
assert_equal 850, total
end
test 'user cannot apply excessive coupon to cart' do
total = CouponService.new.apply(1000, @cash_coupon, @jdupond.id)
assert_equal 1000, total
end
test 'user cannot apply invalid coupon to cart' do
total = CouponService.new.apply(1000, 'INVALIDCODE', @jdupond.id)
assert_equal 1000, total
end
test 'user cannot apply expired coupon to cart' do
total = CouponService.new.apply(1000, 'XMAS10', @jdupond.id)
assert_equal 1000, total
end
end