2016-11-28 10:40:02 +01:00
|
|
|
require 'test_helper'
|
|
|
|
|
2016-11-29 14:57:21 +01:00
|
|
|
class CouponServiceTest < ActiveSupport::TestCase
|
2016-11-28 10:40:02 +01:00
|
|
|
setup do
|
|
|
|
@jdupond = User.find_by(username: 'jdupond')
|
|
|
|
@cash_coupon = Coupon.find_by(code: 'ZERG6H1R65H')
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'user apply percent coupon to cart' do
|
2016-11-29 14:57:21 +01:00
|
|
|
total = CouponService.new.(1000, 'SUNNYFABLAB', @jdupond.id)
|
2016-11-28 10:40:02 +01:00
|
|
|
assert_equal 850, total
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'user cannot apply excessive coupon to cart' do
|
2016-11-29 14:57:21 +01:00
|
|
|
total = CouponService.new.(1000, @cash_coupon, @jdupond.id)
|
2016-11-28 10:40:02 +01:00
|
|
|
assert_equal 1000, total
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'user cannot apply invalid coupon to cart' do
|
2016-11-29 14:57:21 +01:00
|
|
|
total = CouponService.new.(1000, 'INVALIDCODE', @jdupond.id)
|
2016-11-28 10:40:02 +01:00
|
|
|
assert_equal 1000, total
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'user cannot apply expired coupon to cart' do
|
2016-11-29 14:57:21 +01:00
|
|
|
total = CouponService.new.(1000, 'XMAS10', @jdupond.id)
|
2016-11-28 10:40:02 +01:00
|
|
|
assert_equal 1000, total
|
|
|
|
end
|
|
|
|
end
|