|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'Subscribe', js: true, type: :feature do |
| 4 | + context 'without team_id' do |
| 5 | + before do |
| 6 | + visit '/subscribe' |
| 7 | + end |
| 8 | + it 'requires a team' do |
| 9 | + expect(find('#messages')).to have_text('Missing or invalid team ID.') |
| 10 | + find('#subscribe', visible: false) |
| 11 | + end |
| 12 | + end |
| 13 | + unless ENV['CI'] |
| 14 | + context 'stripe' do |
| 15 | + before do |
| 16 | + SlackRubyBotServer::Stripe.configure do |config| |
| 17 | + config.stripe_api_publishable_key = 'pk_test_804U1vUeVeTxBl8znwriXskf' |
| 18 | + config.subscription_plan_id = 'prod_HAd97WaHg4XxNM' |
| 19 | + config.subscription_plan_amount = 3999 |
| 20 | + end |
| 21 | + end |
| 22 | + context 'not subscribed' do |
| 23 | + let!(:team) { Fabricate(:team) } |
| 24 | + it 'subscribes team' do |
| 25 | + visit "/subscribe?team_id=#{team.team_id}" |
| 26 | + expect(find('#messages')).to have_text("Subscribe team #{team.name} for $39.99 a year.") |
| 27 | + |
| 28 | + find('#subscribe', visible: true) |
| 29 | + |
| 30 | + expect_any_instance_of(Team).to receive(:subscribe!).and_return( |
| 31 | + 'stripe_customer_id' => 'customer_id') |
| 32 | + |
| 33 | + find('.stripe-button-el').click |
| 34 | + |
| 35 | + sleep 1 |
| 36 | + |
| 37 | + stripe_iframe = all('iframe[name=stripe_checkout_app]').last |
| 38 | + Capybara.within_frame stripe_iframe do |
| 39 | + page.find_field('Email').set '[email protected]' |
| 40 | + page.find_field('Card number').set '4242 4242 4242 4242' |
| 41 | + page.find_field('MM / YY').set '12/42' |
| 42 | + page.find_field('CVC').set '123' |
| 43 | + find('button[type="submit"]').click |
| 44 | + end |
| 45 | + |
| 46 | + sleep 5 |
| 47 | + |
| 48 | + find('#subscribe', visible: false) |
| 49 | + expect(find('#messages')).to have_text("Team #{team.name} successfully subscribed.") |
| 50 | + end |
| 51 | + end |
| 52 | + context 'subscribed' do |
| 53 | + let!(:team) { Fabricate(:team, subscribed: true, stripe_customer_id: 'stripe-customer-id') } |
| 54 | + it 'updates cc' do |
| 55 | + visit "/subscribe?team_id=#{team.team_id}" |
| 56 | + expect(find('#messages')).to have_text("Update credit card for team #{team.name}.") |
| 57 | + |
| 58 | + find('.stripe-button-el').click |
| 59 | + |
| 60 | + sleep 1 |
| 61 | + |
| 62 | + stripe_iframe = all('iframe[name=stripe_checkout_app]').last |
| 63 | + |
| 64 | + |
| 65 | + expect_any_instance_of(Team).to receive(:update_subscription!).and_return( |
| 66 | + 'stripe_customer_id' => 'customer_id' |
| 67 | + ) |
| 68 | + |
| 69 | + Capybara.within_frame stripe_iframe do |
| 70 | + page.find_field('Email').set '[email protected]' |
| 71 | + page.find_field('Card number').set '4012 8888 8888 1881' |
| 72 | + page.find_field('MM / YY').set '12/42' |
| 73 | + page.find_field('CVC').set '345' |
| 74 | + find('button[type="submit"]').click |
| 75 | + end |
| 76 | + |
| 77 | + sleep 5 |
| 78 | + |
| 79 | + find('#subscribe', visible: false) |
| 80 | + expect(find('#messages')).to have_text("Credit card for team #{team.name} successfully updated.") |
| 81 | + end |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | +end |
0 commit comments