Skip to content

Commit

Permalink
Fix: display API errors from error! exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Aug 5, 2017
1 parent 6857f92 commit 967f194
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
4 changes: 3 additions & 1 deletion public/js/playplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ $(document).ready(function() {
var message;
if (xhr.responseText) {
var rc = JSON.parse(xhr.responseText);
if (rc && rc.message) {
if (rc && rc.error) {
message = rc.error;
} else if (rc && rc.message) {
message = rc.message;
if (message == 'invalid_code') {
message = 'The code returned from the OAuth workflow was invalid.'
Expand Down
75 changes: 44 additions & 31 deletions spec/integration/update_cc_spec.rb
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

0 comments on commit 967f194

Please sign in to comment.