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

777 lines
28 KiB
Ruby

require 'spec_helper'
describe "Checkout", :js => true, :type => :feature, :capybara_feature => true do
let(:user) { FactoryGirl.create(:user) }
let(:jamtrack_acdc_backinblack) { @jamtrack_acdc_backinblack }
let(:jamtrack_pearljam_evenflow) { @jamtrack_pearljam_evenflow }
let(:billing_info) {
{
first_name: 'Seth',
last_name: 'Call',
address1: '10704 Buckthorn Drive',
city: 'Austin',
state: 'Texas',
country: 'US',
zip: '78759',
number: '4111111111111111',
month: '08',
year: '2017',
verification_value: '012'
}
}
def create_account(user, billing_info)
@recurlyClient.create_account(user, billing_info)
@created_accounts << user
end
before(:all) do
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = Capybara.javascript_driver
Capybara.default_wait_time = 20 # these tests are SLOOOOOW
@recurlyClient = RecurlyClient.new
@created_accounts = []
@jamtrack_acdc_backinblack = FactoryGirl.create(:jam_track, name: 'Back in Black', original_artist: 'AC/DC', sales_region: 'United States', make_track: true, plan_code: 'jamtrack-acdc-backinblack')
@jamtrack_pearljam_evenflow = FactoryGirl.create(:jam_track, name: 'Even Flow', original_artist: 'Pearl Jam', sales_region: 'United States', make_track: true, plan_code: 'jamtrack-pearljam-evenflow')
# make sure plans are there
@recurlyClient.create_jam_track_plan(@jamtrack_acdc_backinblack) unless @recurlyClient.find_jam_track_plan(@jamtrack_acdc_backinblack)
end
before(:each) do
ShoppingCart.delete_all
Sale.delete_all
User.delete_all
stub_const("APP_CONFIG", web_config)
end
after(:each) do
@created_accounts.each do |user|
if user.recurly_code
begin
@account = Recurly::Account.find(user.recurly_code)
if @account.present?
@account.destroy
end
rescue
end
end
end
end
def verify_nav(selected)
3.times do |i|
badge = i + 1
if badge == selected
find('.badge-number', text:badge)
else
find('.badge-number.disabled', text:badge)
end
end
end
describe "Checkout Signin" do
it "allows user to log in on the signin page" do
visit '/client#/checkoutSignin'
find('h3', text: 'ALREADY A MEMBER OF THE JAMKAZAM COMMUNITY?')
verify_nav(1)
# try a bogus user/pass first
fill_in "email", with: user.email
fill_in "password", with: 'wrong'
find('.signin-submit').trigger(:click)
find('.login-error-msg', text: 'Invalid login')
# try successfully
fill_in "email", with: user.email
fill_in "password", with: user.password
find('.signin-submit').trigger(:click)
# this should take us to the payment screen
find('p.payment-prompt')
end
it "allows user to skip login and go to payment screen" do
visit '/client#/checkoutSignin'
find('h3', text: 'ALREADY A MEMBER OF THE JAMKAZAM COMMUNITY?')
verify_nav(1)
# skip to payment without signing in
find('a.btnNext').trigger(:click)
# this should take us to the payment screen
find('p.payment-prompt')
end
it "indicates already logged in" do
fast_signin(user, '/client#/checkoutSignin')
# verify that the signin page shows, but indicates to the user that they are already signed in
find('h3', text: 'YOU ARE ALREADY LOGGED IN')
verify_nav(1)
find('p.carry-on-prompt', text: 'You can move on to the next step of checkout.')
# let them move on to the next step
find('a.btnNext').trigger(:click)
find('p.payment-prompt')
end
end
describe "Checkout Payment" do
it "allows anonymous to visit" do
visit '/client#/checkoutPayment'
find('p.payment-prompt.free-jamtrack')
find('.jamkazam-account-signup')
# try to submit, and see slew of errors
find('#payment-info-next').trigger(:click)
find('#divBillingFirstName.error .error-text', text: 'First Name is required')
find('#divBillingLastName.error .error-text', text: 'Last Name is required')
find('#divBillingAddress1.error .error-text', text: 'Address is required')
find('#divBillingCity.error .error-text', text: 'City is required')
find('#divBillingState.error .error-text', text: 'State is required')
find('#divBillingZip.error .error-text', text: 'Zip Code is required')
find('#divCardNumber.error .error-text', text: 'Card Number is required')
find('#divCardVerify.error .error-text', text: 'Card Verification Value is required')
# fill out all billing info, but not account info
fill_in 'billing-first-name', with: 'Seth'
fill_in 'billing-last-name', with: 'Call'
fill_in 'billing-address1', with: '10704 Buckthorn Drive'
fill_in 'billing-city', with: 'Austin'
fill_in 'billing-state', with: 'Texas'
fill_in 'billing-zip', with: '78759'
fill_in 'card-number', with: '4111111111111111'
fill_in 'card-verify', with: '012'
# try to submit, and see new account errors
find('#payment-info-next').trigger(:click)
find('#divJamKazamEmail.error .error-text', text: "can't be blank,is invalid")
find('#divJamKazamPassword.error .error-text', text: "is too short (minimum is 6 characters)")
find('#divJamKazamTos.error .error-text', text: "must be accepted")
# verify that all filled out fields have had errors removed
find('#divBillingFirstName').has_no_css?('.error')
find('#divBillingLastName').has_no_css?('.error')
find('#divBillingAddress1').has_no_css?('.error')
find('#divBillingCity').has_no_css?('.error')
find('#divBillingState').has_no_css?('.error')
find('#divBillingZip').has_no_css?('.error')
find('#divCardNumber').has_no_css?('.error')
find('#divCardVerify').has_no_css?('.error')
# fill in user/email/tos
fill_in 'email', with: 'seth@jamkazam.com'
fill_in 'password', with: 'jam123'
find('#divJamKazamTos ins.iCheck-helper').trigger(:click) # accept TOS
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# find empty shopping cart prompt notice
find('p.empty-cart-prompt')
user.reload
user.reuse_card.should be_true
end
it "shows card error correctly" do
fast_signin(user, '/client#/checkoutPayment')
find('p.payment-prompt.free-jamtrack')
expect(page).to_not have_selector('.jamkazam-account-signup')
# fill out all billing info, but not account info
fill_in 'billing-first-name', with: 'Seth'
fill_in 'billing-last-name', with: 'Call'
fill_in 'billing-address1', with: '10704 Buckthorn Drive'
fill_in 'billing-city', with: 'Austin'
fill_in 'billing-state', with: 'Texas'
fill_in 'billing-zip', with: '78759'
fill_in 'card-number', with: '4000-0000-0000-0002'
fill_in 'card-verify', with: '012'
# try to submit, and see slew of errors
find('#payment-info-next').trigger(:click)
find('#payment_error', text:'Your transaction was declined. Please use a different card or contact your bank.')
end
it "allows billing info submit for existing user" do
fast_signin(user, '/client#/checkoutPayment')
find('p.payment-prompt.free-jamtrack')
expect(page).to_not have_selector('.jamkazam-account-signup')
# try to submit, and see slew of errors
find('#payment-info-next').trigger(:click)
find('#divBillingAddress1.error .error-text', text: 'Address is required')
find('#divBillingZip.error .error-text', text: 'Zip Code is required')
find('#divCardNumber.error .error-text', text: 'Card Number is required')
find('#divCardVerify.error .error-text', text: 'Card Verification Value is required')
# fill out all billing info, but not account info
fill_in 'billing-first-name', with: 'Seth'
fill_in 'billing-last-name', with: 'Call'
fill_in 'billing-address1', with: '10704 Buckthorn Drive'
fill_in 'billing-city', with: 'Austin'
fill_in 'billing-state', with: 'Texas'
fill_in 'billing-zip', with: '78759'
fill_in 'card-number', with: '4111111111111111'
fill_in 'card-verify', with: '012'
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# find empty shopping cart prompt notice
find('p.empty-cart-prompt')
user.reload
user.reuse_card.should be_true
end
it "allows user to specify don't save card" do
fast_signin(user, '/client#/checkoutPayment')
find('p.payment-prompt.free-jamtrack')
expect(page).to_not have_selector('.jamkazam-account-signup')
# fill out all billing info, but not account info
fill_in 'billing-first-name', with: 'Seth'
fill_in 'billing-last-name', with: 'Call'
fill_in 'billing-address1', with: '10704 Buckthorn Drive'
fill_in 'billing-city', with: 'Austin'
fill_in 'billing-state', with: 'Texas'
fill_in 'billing-zip', with: '78759'
fill_in 'card-number', with: '4111111111111111'
fill_in 'card-verify', with: '012'
find('.save-card-checkbox ins.iCheck-helper').trigger(:click) # don't accept re-use card default
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# find empty shopping cart prompt notice
find('p.empty-cart-prompt')
user.reload
user.reuse_card.should be_false
end
it "payment shows saved card info correctly if user has billing info and reuse_card set to true" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reuse_card = true
@recurlyClient.create_account(user, billing_info)
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutPayment')
# ok, the user has a free jamtrack... verify that display confirms this
find('p.payment-prompt.free-jamtrack')
# verify that all billing info looks disabled
have_field('billing-first-name', disabled: true)
have_field('billing-last-name', disabled: true)
have_field('billing-address1', disabled: true)
have_field('billing-address2', disabled: true)
have_field('billing-city', disabled: true)
have_field('billing-state', disabled: true)
have_field('billing-zip', disabled: true)
have_field('billing-country', disabled: true)
have_field('card-number', disabled: true)
have_field('card_expire-date_2i', disabled: true)
have_field('card_expire-date_1i', disabled: true)
have_field('card-number', disabled: true)
have_field('card-verify', disabled: true)
# verify that the use current card checkbox is checked, and that the 'save card' checkbox is checking
find('#reuse-existing-card').checked?.should be_true
find('#save-card:checked').checked?.should be_true
# then uncheck 'reuse-existing-card', which should re-enable all the fields that were just disabled
find('.reuse-existing-card-checkbox ins.iCheck-helper').trigger(:click)
# verify that all billing info looks enabled now, since 'reuse-existing-card' was unchecked
have_field('billing-first-name', disabled: false)
have_field('billing-last-name', disabled: false)
have_field('billing-address1', disabled: false)
have_field('billing-address2', disabled: false)
have_field('billing-city', disabled: false)
have_field('billing-state', disabled: false)
have_field('billing-zip', disabled: false)
have_field('billing-country', disabled: false)
have_field('card-number', disabled: false)
have_field('card_expire-date_2i', disabled: false)
have_field('card_expire-date_1i', disabled: false)
have_field('card-number', disabled: false)
have_field('card-verify', disabled: false)
# ok, we want to fiddle some values, and later prove that they will be ignored once we set reuse-existing-card back to checked
fill_in 'billing-first-name', with: 'Bobby'
fill_in 'billing-last-name', with: 'Junk'
fill_in 'billing-address1', with: '10702 Buckthorn Drive'
# flip it back to reuse existing
find('.reuse-existing-card-checkbox ins.iCheck-helper').trigger(:click)
# hit next... we should move on to the payment screen
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# find empty shopping cart prompt notice
find('p.order-prompt')
account = @recurlyClient.get_account(user)
account.billing_info.address1.should eq(billing_info[:address1])
account.billing_info.first_name.should eq(billing_info[:first_name])
account.billing_info.last_name.should eq(billing_info[:last_name])
find('.order-items-value.sub-total', text:'0.00')
find('.order-items-value.taxes', text:'0.00')
find('.order-items-value.order-total', text:'0.00')
end
it "payment allows user to enter new billing info" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reuse_card = true
@recurlyClient.create_account(user, billing_info)
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutPayment')
# ok, the user has a free jamtrack... verify that display confirms this
find('p.payment-prompt.free-jamtrack')
# verify that the use current card checkbox is checked, and that the 'save card' checkbox is checking
find('#reuse-existing-card').checked?.should be_true
find('#save-card:checked').checked?.should be_true
# then uncheck 'reuse-existing-card', which should re-enable all the fields that were just disabled
find('.reuse-existing-card-checkbox ins.iCheck-helper').trigger(:click)
# ok, we want to fiddle some values, and later prove that they will be ignored once we set reuse-existing-card back to checked
fill_in 'billing-first-name', with: 'Bobby'
fill_in 'billing-last-name', with: 'Junk'
fill_in 'billing-address1', with: '10702 Buckthorn Drive'
fill_in 'card-number', with: '4111111111111111'
fill_in 'card-verify', with: '013'
# hit next... we should move on to the payment screen
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# find empty shopping cart prompt notice
find('p.order-prompt')
account = @recurlyClient.get_account(user)
account.billing_info.first_name.should eq('Bobby')
account.billing_info.last_name.should eq('Junk')
account.billing_info.address1.should eq('10702 Buckthorn Drive')
find('.order-items-value.sub-total', text:'0.00')
find('.order-items-value.taxes', text:'0.00')
find('.order-items-value.order-total', text:'0.00')
end
it "user with no redeemable jamtrack is not show the free-jamtrack prompt" do
user.has_redeemable_jamtrack = false
user.save!
fast_signin(user, '/client#/checkoutPayment')
# ok, the user has a free jamtrack... verify that display confirms this
find('p.payment-prompt.no-free-jamtrack')
end
end
describe "Checkout Order" do
it "shows no billing info notice" do
fast_signin(user, '/client#/checkoutOrder')
# the user should be toldy they have a empty cart
find('p.no-account-info-prompt')
end
it "shows empty cart notice" do
@recurlyClient.create_account(user, billing_info)
fast_signin(user, '/client#/checkoutOrder')
# the user should be toldy they have a empty cart
find('p.empty-cart-prompt')
find('.order-items-value.order-total', text:'-.--')
find('.order-items-value.sub-total', text:'-.--')
find('.order-items-value.taxes', text:'-.--')
find('.order-items-value.order-total', text:'-.--')
# verify that both Place Your Orders are disabled
find('.order-content .place-order.disabled')
find('.order-panel .action-bar .place-order.disabled')
end
it "shows one free item correctly" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$0.00')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$0.00')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$0.00')
end
it "shows one free, one not free item correctly" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reload
ShoppingCart.add_jam_track_to_cart(user, jamtrack_pearljam_evenflow)
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$1.99')
end
it "shows one non-free item correctly" do
user.has_redeemable_jamtrack = false
user.save!
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$1.99')
end
it "shows two non-free items correctly" do
user.has_redeemable_jamtrack = false
user.save!
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reload
ShoppingCart.add_jam_track_to_cart(user, jamtrack_pearljam_evenflow)
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$3.98')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$3.98')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$3.98')
find('.place-order-center a.button-orange.place-order').trigger(:click)
# and now we should see confirmation, and a notice that we are in a normal browser
find('.thanks-detail.jam-tracks-in-browser')
acdc = jamtrack_acdc_backinblack.right_for_user(user)
acdc.redeemed.should be_false
pearljam = jamtrack_pearljam_evenflow.right_for_user(user)
pearljam.redeemed.should be_false
# verify sales data
user.sales.length.should eq(1)
sale = user.sales.first
sale.sale_line_items.length.should eq(2)
acdc_sale = SaleLineItem.find_by_recurly_adjustment_uuid(acdc.recurly_adjustment_uuid)
acdc_sale.recurly_plan_code.should eq(jamtrack_acdc_backinblack.plan_code)
acdc_sale.product_type.should eq('JamTrack')
acdc_sale.product_id.should eq(jamtrack_acdc_backinblack.id)
acdc_sale.quantity.should eq(1)
acdc_sale.free.should eq(0)
acdc_sale.unit_price.should eq(1.99)
acdc_sale.sale.should eq(sale)
pearljam_sale = SaleLineItem.find_by_recurly_adjustment_uuid(pearljam.recurly_adjustment_uuid)
pearljam_sale.recurly_plan_code.should eq(jamtrack_pearljam_evenflow.plan_code)
pearljam_sale.product_type.should eq('JamTrack')
pearljam_sale.product_id.should eq(jamtrack_pearljam_evenflow.id)
pearljam_sale.quantity.should eq(1)
pearljam_sale.free.should eq(0)
pearljam_sale.unit_price.should eq(1.99)
pearljam_sale.sale.should eq(sale)
end
it "shows purchase error correctly" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
# fiddle with the user's recurly-code so that the checkout fails
user.recurly_code = 'bleh'
user.save!
find('.place-order-center a.button-orange.place-order').trigger(:click)
find('#order_error', text: "Error submitting payment: message: Couldn't find Account with account_code = bleh")
end
end
describe "Complete Checkout Flow" do
it "for anonymous user" do
visit "/client#/jamtrack"
find('h1', text: 'jamtracks')
#find('a', text: 'What is a JamTrack?')
find("a.jamtrack-add-cart[data-jamtrack-id=\"#{jamtrack_acdc_backinblack.id}\"]").trigger(:click)
find('h1', text: 'shopping cart')
find('.cart-item-caption', text: "JamTrack: #{jamtrack_acdc_backinblack.name}")
find('.cart-item-price', text: "$ #{jamtrack_acdc_backinblack.price}")
# attempt to checkout
find('a.button-orange', text: 'PROCEED TO CHECKOUT').trigger(:click)
# we should now be on checkoutSignin
find('h3', text: 'ALREADY A MEMBER OF THE JAMKAZAM COMMUNITY?')
verify_nav(1)
# skip to payment without signing in
find('a.btnNext').trigger(:click)
# this should take us to the payment screen
find('p.payment-prompt')
find('.jamkazam-account-signup')
# fill out all billing info and account info
fill_in 'billing-first-name', with: 'Seth'
fill_in 'billing-last-name', with: 'Call'
fill_in 'billing-address1', with: '10704 Buckthorn Drive'
fill_in 'billing-city', with: 'Austin'
fill_in 'billing-state', with: 'Texas'
fill_in 'billing-zip', with: '78759'
fill_in 'card-number', with: '4111111111111111'
fill_in 'card-verify', with: '012'
fill_in 'checkout-signup-email', with: 'guy@jamkazam.com'
fill_in 'checkout-signup-password', with: 'jam123'
find('#divJamKazamTos ins.iCheck-helper').trigger(:click) # accept TOS
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# now see order page, and everything should appear free
find('p.order-prompt')
find('.order-items-value.order-total', text:'$0.00')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$0.00')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$0.00')
# click the ORDER button
find('.place-order-center a.button-orange.place-order').trigger(:click)
# and now we should see confirmation, and a notice that we are in a normal browser
find('.thanks-detail.jam-tracks-in-browser')
guy = User.find_by_email('guy@jamkazam.com')
jam_track_right = jamtrack_acdc_backinblack.right_for_user(guy)
# make sure it appears the user actually bought the jamtrack!
jam_track_right.should_not be_nil
jam_track_right.redeemed.should be_true
guy.has_redeemable_jamtrack.should be_false
# verify sales data
guy.sales.length.should eq(1)
sale = guy.sales.first
sale.sale_line_items.length.should eq(1)
acdc_sale = SaleLineItem.find_by_recurly_adjustment_uuid(jam_track_right.recurly_adjustment_uuid)
acdc_sale.recurly_plan_code.should eq(jamtrack_acdc_backinblack.plan_code)
acdc_sale.product_type.should eq('JamTrack')
acdc_sale.product_id.should eq(jamtrack_acdc_backinblack.id)
acdc_sale.quantity.should eq(1)
acdc_sale.free.should eq(1)
acdc_sale.unit_price.should eq(1.99)
acdc_sale.sale.should eq(sale)
# now, go back to checkout flow again, and make sure we are told there are no free jam tracks
visit "/client#/jamtrack"
find("a.jamtrack-add-cart[data-jamtrack-id=\"#{jamtrack_pearljam_evenflow.id}\"]").trigger(:click)
find('h1', text: 'shopping cart')
find('.cart-item-caption', text: "JamTrack: #{jamtrack_pearljam_evenflow.name}")
find('.cart-item-price', text: "$ #{jamtrack_pearljam_evenflow.price}")
# attempt to checkout
find('a.button-orange', text: 'PROCEED TO CHECKOUT').trigger(:click)
# should be taken straight to order page
# now see order page, and everything should appear free
find('p.order-prompt')
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$1.99')
# click the ORDER button
find('.place-order-center a.button-orange.place-order').trigger(:click)
# and now we should see confirmation, and a notice that we are in a normal browser
find('.thanks-detail.jam-tracks-in-browser')
guy.reload
jam_track_right = jamtrack_pearljam_evenflow.right_for_user(guy)
# make sure it appears the user actually bought the jamtrack!
jam_track_right.should_not be_nil
jam_track_right.redeemed.should be_false
guy.has_redeemable_jamtrack.should be_false
# verify sales data
guy.sales.length.should eq(2)
sale = guy.sales.last
sale.sale_line_items.length.should eq(1)
acdc_sale = SaleLineItem.find_by_recurly_adjustment_uuid(jam_track_right.recurly_adjustment_uuid)
acdc_sale.recurly_plan_code.should eq(jamtrack_pearljam_evenflow.plan_code)
acdc_sale.product_type.should eq('JamTrack')
acdc_sale.product_id.should eq(jamtrack_pearljam_evenflow.id)
acdc_sale.quantity.should eq(1)
acdc_sale.free.should eq(0)
acdc_sale.unit_price.should eq(1.99)
acdc_sale.sale.should eq(sale)
end
it "for existing user" do
fast_signin(user, "/client#/jamtrack")
find('h1', text: 'jamtracks')
#find('a', text: 'What is a JamTrack?')
find("a.jamtrack-add-cart[data-jamtrack-id=\"#{jamtrack_acdc_backinblack.id}\"]").trigger(:click)
find('h1', text: 'shopping cart')
find('.cart-item-caption', text: "JamTrack: #{jamtrack_acdc_backinblack.name}")
find('.cart-item-price', text: "$ #{jamtrack_acdc_backinblack.price}")
# attempt to checkout
find('a.button-orange', text: 'PROCEED TO CHECKOUT').trigger(:click)
# we should be skipping the signin screen, and be taken directly to payment
# this should take us to the payment screen
find('p.payment-prompt')
# fill out all billing info and account info
fill_in 'billing-first-name', with: 'Seth'
fill_in 'billing-last-name', with: 'Call'
fill_in 'billing-address1', with: '10704 Buckthorn Drive'
fill_in 'billing-city', with: 'Austin'
fill_in 'billing-state', with: 'Texas'
fill_in 'billing-zip', with: '78759'
fill_in 'card-number', with: '4111111111111111'
fill_in 'card-verify', with: '012'
# try to submit, and see order page
find('#payment-info-next').trigger(:click)
# now see order page, and everything should appear free
find('p.order-prompt')
find('.order-items-value.order-total', text:'$0.00')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$0.00')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$0.00')
# click the ORDER button
find('.place-order-center a.button-orange.place-order').trigger(:click)
# and now we should see confirmation, and a notice that we are in a normal browser
find('.thanks-detail.jam-tracks-in-browser')
user.reload
jam_track_right = jamtrack_acdc_backinblack.right_for_user(user)
# make sure it appears the user actually bought the jamtrack!
jam_track_right.should_not be_nil
jam_track_right.redeemed.should be_true
user.has_redeemable_jamtrack.should be_false
end
end
end