mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-06 01:08:21 +01:00
fix coupons test
This commit is contained in:
parent
e2ea64cf9c
commit
c23b6fa3e0
@ -26,7 +26,7 @@ class API::CouponsController < API::ApiController
|
|||||||
else
|
else
|
||||||
status = @coupon.status
|
status = @coupon.status
|
||||||
if status != 'active'
|
if status != 'active'
|
||||||
render json: {status: status}, status: :unauthorized
|
render json: {status: status}, status: :unprocessable_entity
|
||||||
else
|
else
|
||||||
render :validate, status: :ok, location: @coupon
|
render :validate, status: :ok, location: @coupon
|
||||||
end
|
end
|
||||||
|
@ -10,6 +10,7 @@ class Coupon < ActiveRecord::Base
|
|||||||
validates :code, uniqueness: true
|
validates :code, uniqueness: true
|
||||||
validates :percent_off, presence: true
|
validates :percent_off, presence: true
|
||||||
validates :percent_off, :inclusion => 0..100
|
validates :percent_off, :inclusion => 0..100
|
||||||
|
validates :validity_per_user, presence: true
|
||||||
|
|
||||||
def safe_destroy
|
def safe_destroy
|
||||||
if self.invoices.size == 0
|
if self.invoices.size == 0
|
||||||
|
8
test/fixtures/coupons.yml
vendored
8
test/fixtures/coupons.yml
vendored
@ -5,10 +5,9 @@ one:
|
|||||||
code: XMAS10
|
code: XMAS10
|
||||||
percent_off: 10
|
percent_off: 10
|
||||||
valid_until: 2015-12-31 23:59:59
|
valid_until: 2015-12-31 23:59:59
|
||||||
max_usages: 0
|
max_usages: nil
|
||||||
usages: 1
|
|
||||||
active: true
|
active: true
|
||||||
stp_coupon_id: a3OlfO4u
|
validity_per_user: once
|
||||||
|
|
||||||
two:
|
two:
|
||||||
name: Summer discounts
|
name: Summer discounts
|
||||||
@ -16,6 +15,5 @@ two:
|
|||||||
percent_off: 15
|
percent_off: 15
|
||||||
valid_until: <%= 1.month.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
valid_until: <%= 1.month.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
max_usages: 10
|
max_usages: 10
|
||||||
usages: 9
|
|
||||||
active: true
|
active: true
|
||||||
stp_coupon_id: a42pm11w
|
validity_per_user: always
|
||||||
|
@ -2,7 +2,17 @@ require 'test_helper'
|
|||||||
|
|
||||||
class CouponTest < ActiveSupport::TestCase
|
class CouponTest < ActiveSupport::TestCase
|
||||||
test 'coupon must have a valid percentage' do
|
test 'coupon must have a valid percentage' do
|
||||||
c = Coupon.new({code: 'DISCOUNT', percent_off: 800})
|
c = Coupon.new({name: 'Amazing deal', code: 'DISCOUNT', percent_off: 200, validity_per_user: 'once'})
|
||||||
|
assert c.invalid?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'expired coupon must return the proper status' do
|
||||||
|
c = Coupon.find_by_code('XMAS10')
|
||||||
|
assert c.status == 'expired'
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'two coupons cannot have the same code' do
|
||||||
|
c = Coupon.new({name: 'Summer deals', code: 'SUNNYFABLAB', percent_off: 15, validity_per_user: 'always'})
|
||||||
assert c.invalid?
|
assert c.invalid?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user