Created
June 26, 2012 13:17
-
-
Save jevy/2995738 to your computer and use it in GitHub Desktop.
Device Identifier Integration Spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# Type of discount: Free product (postcard) | |
# Conditions: Start/Stop (Aug X, Aug Y) | |
# Minimum number of specified products purchased: 1 Postcard | |
# Maximum # of total uses: 20 | |
# Used by anyone (any device as he might pass it to his friends) | |
describe 'Unique device promo code', :focus do | |
before do | |
@promo = FactoryGirl.create(:promo, | |
code: 'use_me_once', | |
start: Time.now.yesterday.beginning_of_day, | |
stop: Time.now.tomorrow.end_of_day, | |
discount: 'one_free_postcard_per_order', | |
conditions: [Promo::AnyDeviceCanOnlyActivatePromoOnce.create]) | |
end | |
it 'works if not used before' do | |
@order = FactoryGirl.create(:order_with_postcard) | |
json = <<-JSON | |
{ | |
"promo_code": | |
{ | |
"code": "#{@promo.code}", | |
"device-identifier": "11-11-11-11" | |
} | |
} | |
JSON | |
post "/v4/orders/#{@order.id}/promo_code.json", json, "CONTENT_TYPE" => "application/json" | |
response.should be_success | |
end | |
it 'fails if used before' do | |
previous_order = FactoryGirl.create(:order_with_postcard) | |
@promo.apply_to!(previous_order, '11-11-11-11') | |
@order = FactoryGirl.create(:order_with_postcard) | |
json = <<-JSON | |
{ | |
"promo_code": | |
{ | |
"code": "#{@promo.code}", | |
"device-identifier": "11-11-11-11" | |
} | |
} | |
JSON | |
post "/v4/orders/#{@order.id}/promo_code.json", json, "CONTENT_TYPE" => "application/json" | |
response.should be_unprocessable | |
end | |
it 'works if user has used a different promo' do | |
old_promo = FactoryGirl.create(:promo, | |
code: 'someoldcode', | |
start: Time.now.yesterday.beginning_of_day, | |
stop: Time.now.tomorrow.end_of_day, | |
discount: 'one_free_postcard_per_order', | |
conditions: [Promo::AnyDeviceCanOnlyActivatePromoOnce.create]) | |
previous_order = FactoryGirl.create(:order_with_postcard) | |
old_promo.apply_to!(previous_order, '11-11-11-11') | |
order = FactoryGirl.create(:order_with_postcard) | |
json = <<-JSON | |
{ | |
"promo_code": | |
{ | |
"code": "#{@promo.code}", | |
"device-identifier": "11-11-11-11" | |
} | |
} | |
JSON | |
post "/v4/orders/#{order.id}/promo_code.json", json, "CONTENT_TYPE" => "application/json" | |
response.should be_success | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment