-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: display API errors from error! exceptions.
- Loading branch information
Showing
2 changed files
with
47 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,57 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Update cc', js: true, type: :feature do | ||
let!(:game) { Fabricate(:game, name: 'pong') } | ||
|
||
shared_examples 'updates cc' do | ||
it 'updates cc' do | ||
visit "/update_cc?team_id=#{team.team_id}&game=#{team.game.name}" | ||
expect(find('h3')).to have_text('PLAYPLAY.IO: UPDATE CREDIT CARD INFO') | ||
|
||
customer = double | ||
expect(Stripe::Customer).to receive(:retrieve).and_return(customer) | ||
expect(customer).to receive(:source=) | ||
expect(customer).to receive(:save) | ||
|
||
click_button 'Update Credit Card' | ||
sleep 1 | ||
stripe_iframe = all('iframe[name=stripe_checkout_app]').last | ||
Capybara.within_frame stripe_iframe do | ||
page.find_field('Email').set 'foo@bar.com' | ||
page.find_field('Card number').set '4012 8888 8888 1881' | ||
page.find_field('MM / YY').set '12/42' | ||
page.find_field('CVC').set '345' | ||
find('button[type="submit"]').click | ||
end | ||
|
||
sleep 5 | ||
|
||
expect(find('#messages')).to have_text("Successfully updated team #{team.name} credit card for #{team.game.name}. Thank you for your support!") | ||
end | ||
end | ||
context 'with a stripe key' do | ||
before do | ||
ENV['STRIPE_API_PUBLISHABLE_KEY'] = 'pk_test_804U1vUeVeTxBl8znwriXskf' | ||
end | ||
after do | ||
ENV.delete 'STRIPE_API_PUBLISHABLE_KEY' | ||
end | ||
context 'a team' do | ||
let!(:team) { Fabricate(:team, game: game, stripe_customer_id: 'stripe_customer_id') } | ||
it_behaves_like 'updates cc' | ||
context 'a game' do | ||
let!(:game) { Fabricate(:game, name: 'pong') } | ||
context 'a team with a stripe customer ID' do | ||
let!(:team) { Fabricate(:team, game: game, stripe_customer_id: 'stripe_customer_id') } | ||
it 'updates cc' do | ||
visit "/update_cc?team_id=#{team.team_id}&game=#{team.game.name}" | ||
expect(find('h3')).to have_text('PLAYPLAY.IO: UPDATE CREDIT CARD INFO') | ||
customer = double | ||
expect(Stripe::Customer).to receive(:retrieve).and_return(customer) | ||
expect(customer).to receive(:source=) | ||
expect(customer).to receive(:save) | ||
click_button 'Update Credit Card' | ||
sleep 1 | ||
stripe_iframe = all('iframe[name=stripe_checkout_app]').last | ||
Capybara.within_frame stripe_iframe do | ||
page.find_field('Email').set 'foo@bar.com' | ||
page.find_field('Card number').set '4012 8888 8888 1881' | ||
page.find_field('MM / YY').set '12/42' | ||
page.find_field('CVC').set '345' | ||
find('button[type="submit"]').click | ||
end | ||
sleep 5 | ||
expect(find('#messages')).to have_text("Successfully updated team #{team.name} credit card for #{team.game.name}. Thank you for your support!") | ||
end | ||
end | ||
context 'a team without a stripe customer ID' do | ||
let!(:team) { Fabricate(:team, game: game, stripe_customer_id: nil) } | ||
it 'displays error' do | ||
visit "/update_cc?team_id=#{team.team_id}&game=#{team.game.name}" | ||
expect(find('h3')).to have_text('PLAYPLAY.IO: UPDATE CREDIT CARD INFO') | ||
click_button 'Update Credit Card' | ||
sleep 1 | ||
stripe_iframe = all('iframe[name=stripe_checkout_app]').last | ||
Capybara.within_frame stripe_iframe do | ||
page.find_field('Email').set 'foo@bar.com' | ||
page.find_field('Card number').set '4012 8888 8888 1881' | ||
page.find_field('MM / YY').set '12/42' | ||
page.find_field('CVC').set '345' | ||
find('button[type="submit"]').click | ||
end | ||
sleep 5 | ||
expect(find('#messages')).to have_text('Not a Premium Customer') | ||
end | ||
end | ||
end | ||
end | ||
end |