mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Stripe Helper specs
This commit is contained in:
committed by
Rob Harrington
parent
05a69ff0c6
commit
1c69f2c670
@@ -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
|
||||
|
||||
|
||||
|
||||
37
spec/helpers/admin/stripe_helper_spec.rb
Normal file
37
spec/helpers/admin/stripe_helper_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user