1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

fix coupons test

This commit is contained in:
Sylvain 2016-08-08 15:43:02 +02:00
parent e2ea64cf9c
commit c23b6fa3e0
4 changed files with 16 additions and 7 deletions

View File

@ -26,7 +26,7 @@ class API::CouponsController < API::ApiController
else
status = @coupon.status
if status != 'active'
render json: {status: status}, status: :unauthorized
render json: {status: status}, status: :unprocessable_entity
else
render :validate, status: :ok, location: @coupon
end

View File

@ -10,6 +10,7 @@ class Coupon < ActiveRecord::Base
validates :code, uniqueness: true
validates :percent_off, presence: true
validates :percent_off, :inclusion => 0..100
validates :validity_per_user, presence: true
def safe_destroy
if self.invoices.size == 0

View File

@ -5,10 +5,9 @@ one:
code: XMAS10
percent_off: 10
valid_until: 2015-12-31 23:59:59
max_usages: 0
usages: 1
max_usages: nil
active: true
stp_coupon_id: a3OlfO4u
validity_per_user: once
two:
name: Summer discounts
@ -16,6 +15,5 @@ two:
percent_off: 15
valid_until: <%= 1.month.from_now.utc.strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
max_usages: 10
usages: 9
active: true
stp_coupon_id: a42pm11w
validity_per_user: always

View File

@ -2,7 +2,17 @@ require 'test_helper'
class CouponTest < ActiveSupport::TestCase
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?
end
end