jam-cloud/web/spec/features/activate_account_spec.rb

127 lines
4.0 KiB
Ruby

require 'spec_helper'
# tests what happens when the websocket connection goes away
describe "Activate Account Card", :js => true, :type => :feature, :capybara_feature => true do
subject { page }
let(:user1) { FactoryGirl.create(:user) }
let(:amazon_2_free_card) { FactoryGirl.create(:amazon_2_free) }
before(:all) do
User.delete_all
end
describe "not logged in" do
describe "amazon_2_free_card" do
it "succeeds" do
visit '/account/activate/code'
amazon_2_free_card.credits.should eql 2
find('h2', text: 'Activate Account')
fill_in "code", with: amazon_2_free_card.code
fill_in "email", with: "amzposa1@jamkazam.com"
fill_in "password", with: "jam123"
find('.redeem-container ins', visible: false).trigger(:click)
find('button.redeem-giftcard', text: 'ACTIVATE ACCOUNT').trigger(:click)
find('.jam-class.all-done span.amount-gifted', text: amazon_2_free_card.credits)
find('.done-action a.go-browse').trigger(:click)
find('h2', text: 'search teachers')
user = User.find_by_email("amzposa1@jamkazam.com")
amazon_2_free_card.reload
amazon_2_free_card.user.should eq(user)
amazon_2_free_card.requires_purchase.should be false
amazon_2_free_card.purchased.should be true
user.reload
user.jamclass_credits.should eq(amazon_2_free_card.credits)
end
it "validates correctly" do
visit '/account/activate/code'
find('h2', text: 'Activate Account')
find('button.redeem-giftcard', text: 'ACTIVATE ACCOUNT').trigger(:click)
find('.errors.active', text: "Email can't be blank")
find('h2', text: 'Activate Account')
fill_in "code", with: amazon_2_free_card.code
fill_in "email", with: "amzpos2@jamkazam.com"
fill_in "password", with: "jam123"
find('.redeem-container ins', visible: false).trigger(:click)
find('button.redeem-giftcard', text: 'ACTIVATE ACCOUNT').trigger(:click)
find('.done-action a.go-browse').trigger(:click)
find('h2', text: 'search teachers')
user = User.find_by_email("amzpos2@jamkazam.com")
amazon_2_free_card.reload
amazon_2_free_card.user.should eq(user)
amazon_2_free_card.requires_purchase.should be false
amazon_2_free_card.purchased.should be true
user.reload
user.jamclass_credits.should eq(amazon_2_free_card.credits)
end
end
end
describe "logged in" do
it "succeeds" do
fast_signin(user1, '/account/activate/code')
find('h2', text: 'Activate Account')
fill_in "code", with: amazon_2_free_card.code
find('button.redeem-giftcard', text: 'ACTIVATE COUPON CODE').trigger(:click)
find('.done-action a.go-browse').trigger(:click)
find('h2', text: 'search teachers')
user1.reload
amazon_2_free_card.reload
amazon_2_free_card.user.should eq(user1)
amazon_2_free_card.requires_purchase.should be false
amazon_2_free_card.purchased.should be true
user1.jamclass_credits.should eq(amazon_2_free_card.credits)
end
end
describe "logged in" do
it "validates" do
fast_signin(user1, '/account/activate/code')
find('h2', text: 'Activate Account')
find('button.redeem-giftcard').trigger(:click)
find('.errors.active', text: "This is not a valid code. Please carefully re-enter the code and try again. If it still does not work, please email us at support@jamkazam.com to report this problem.")
fill_in "code", with: amazon_2_free_card.code
find('button.redeem-giftcard').trigger(:click)
find('.done-action a.go-browse').trigger(:click)
find('h2', text: 'search teachers')
user1.reload
amazon_2_free_card.reload
amazon_2_free_card.user.should eq(user1)
amazon_2_free_card.requires_purchase.should be false
amazon_2_free_card.purchased.should be true
user1.jamclass_credits.should eq(amazon_2_free_card.credits)
end
end
end