Stripe Helper specs

This commit is contained in:
Steve Pettitt
2016-10-01 19:34:39 +01:00
committed by Rob Harrington
parent 05a69ff0c6
commit 1c69f2c670
2 changed files with 43 additions and 0 deletions

View File

@@ -362,6 +362,12 @@ FactoryGirl.define do
tr.calculator = Spree::Calculator::FlatPercentItemTotal.new(calculable: tr)
end
end
factory :stripe_account do
enterprise { FactoryGirl.create :distributor_enterprise }
stripe_user_id "abc123"
stripe_publishable_key "xyz456"
end
end

View File

@@ -0,0 +1,37 @@
require 'spec_helper'
describe Admin::StripeHelper do
let!(:enterprise) { create(:enterprise) }
let!(:stripe_account) { create(:stripe_account, enterprise: enterprise) }
it "calls the Stripe API to get a token" do
expect(Admin::StripeHelper.client.auth_code).to receive(:get_token).with("abc",{scope: "read_write"})
helper.get_stripe_token("abc")
end
it "calls the Stripe API for authorization, passing the enterprise in the state param" do
expect(Admin::StripeHelper.client.auth_code).to receive(:authorize_url).with({state: {enterprise_id: "enterprise-permalink"}})
helper.authorize_stripe("enterprise-permalink")
end
context "Disconnecting an account" do
it "doesn't destroy the database record if the Stripe API disconnect failed" do
disconnection = Admin::StripeHelper.client
.deauthorize(stripe_account.stripe_user_id)
.stub(:deauthorize_request)
.and_return(nil)
deauthorize_stripe(stripe_account.id)
StripeAccount.last.should eq stripe_account
end
it "destroys the record if the Stripe API disconnect succeeds" do
disconnection = Admin::StripeHelper.client
.deauthorize(stripe_account.stripe_user_id)
.stub(:deauthorize_request)
.and_return("something truthy")
deauthorize_stripe(stripe_account.id)
expect(StripeAccount.all).not_to include(stripe_account)
end
end
end