set Stripe api key directly instead of using allow

This commit is contained in:
Andy Brett
2021-05-08 10:57:39 -07:00
committed by Luis Ramos
parent 85508f45b4
commit b3e08b47b9
18 changed files with 26 additions and 26 deletions

View File

@@ -6,7 +6,7 @@ describe Admin::StripeAccountsController, type: :controller do
let(:enterprise) { create(:distributor_enterprise) }
before do
allow(Stripe).to receive(:client_id) { "some_id" }
Stripe.client_id = "some_id"
end
describe "#connect" do
@@ -86,7 +86,7 @@ describe Admin::StripeAccountsController, type: :controller do
end
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
Spree::Config.set(stripe_connect_enabled: false)
end

View File

@@ -30,7 +30,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
context "when a Stripe API key is not set" do
before do
allow(Stripe).to receive(:api_key) { nil }
Stripe.api_key = nil
end
it "sets the account status to :empty_api_key_error_html" do
@@ -42,7 +42,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
context "when a Stripe API key is set" do
before do
allow(Stripe).to receive(:api_key) { "sk_test_xxxx" }
Stripe.api_key = "sk_test_xxxx"
end
context "and the request to retrieve Stripe account info fails" do

View File

@@ -153,7 +153,7 @@ describe CheckoutController, type: :controller do
}
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
stub_payment_intent_get_request
stub_successful_capture_request(order: order)

View File

@@ -31,7 +31,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
end
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
end
context "where the request succeeds" do
@@ -90,7 +90,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
end
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
end
context "where the request succeeds" do
@@ -152,7 +152,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
let(:stripe_account) { create(:stripe_account, enterprise: shop) }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
allow(StripeAccount).to receive(:find_by) { stripe_account }
end
@@ -236,7 +236,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
end
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
stub_payment_intent_get_request stripe_account_header: false
end

View File

@@ -7,7 +7,7 @@ describe Spree::CreditCardsController, type: :controller do
let(:token) { "tok_234bd2c22" }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
allow(controller).to receive(:spree_current_user) { user }
end

View File

@@ -47,7 +47,7 @@ feature '
before do
Spree::Config.set(stripe_connect_enabled: true)
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
stub_request(:get, "https://api.stripe.com/v1/accounts/acc_connected123").to_return(body: JSON.generate(stripe_account_mock))
stub_request(:get, "https://api.stripe.com/v1/accounts/acc_revoked123").to_return(status: 404)
end

View File

@@ -22,8 +22,8 @@ feature "Credit Cards", js: true do
before do
login_as user
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
allow(Stripe).to receive(:publishable_key) { "some_token" }
Stripe.api_key = "sk_test_12345"
Stripe.publishable_key = "some_token"
Spree::Config.set(stripe_connect_enabled: true)
stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ").

View File

@@ -266,7 +266,7 @@ describe EnterprisesHelper, type: :helper do
before do
Spree::Config.set(stripe_connect_enabled: true)
allow(Stripe).to receive(:publishable_key) { "some_key" }
Stripe.publishable_key = "some_key"
end
it "includes Stripe payment methods with a valid stripe accounts" do

View File

@@ -15,7 +15,7 @@ module Stripe
let(:connector) { AccountConnector.new(user, params) }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
end
context "when the connection was cancelled by the user" do

View File

@@ -24,7 +24,7 @@ module Stripe
}
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
stub_customers_post_request email: credit_card.user.email,
response: { customer_id: new_customer_id },

View File

@@ -12,7 +12,7 @@ module Stripe
let(:payment_intent_response_mock) { { status: 200, body: payment_intent_response_body } }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}")
.with(headers: { 'Stripe-Account' => stripe_account_id })

View File

@@ -14,7 +14,7 @@ module Stripe
let(:customer_response_mock) { { status: 200, body: customer_response_body } }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
stub_request(:post, "https://api.stripe.com/v1/customers")
.with(basic_auth: ["sk_test_12345", ""], body: { email: payment.order.email })

View File

@@ -15,7 +15,7 @@ describe Spree::Gateway::StripeConnect, type: :model do
let(:stripe_account_id) { "acct_123" }
before do
allow(Stripe).to receive(:api_key) { "sk_test_123456" }
Stripe.api_key = "sk_test_123456"
allow(subject).to receive(:stripe_account_id) { stripe_account_id }
allow(subject).to receive(:options_for_purchase_or_auth).and_return(['money', 'cc', 'opts'])
allow(subject).to receive(:provider).and_return provider

View File

@@ -3,7 +3,7 @@
require 'spec_helper'
describe Spree::Gateway::StripeSCA, type: :model do
before { allow(Stripe).to receive(:api_key) { "sk_test_12345" } }
before { Stripe.api_key = "sk_test_12345" }
describe "#purchase" do
let(:order) { create(:order_with_totals_and_distribution) }

View File

@@ -12,8 +12,8 @@ describe StripeAccount do
let!(:stripe_account) { create(:stripe_account, enterprise: enterprise, stripe_user_id: stripe_user_id) }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
allow(Stripe).to receive(:client_id) { client_id }
Stripe.api_key = "sk_test_12345"
Stripe.client_id = client_id
end
context "when the Stripe API disconnect fails" do

View File

@@ -68,7 +68,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
allow(OrderCycleDistributedVariants).to receive(:new) { order_cycle_distributed_variants }
allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true }
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id)
order.reload.update_totals
set_order order

View File

@@ -87,7 +87,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques
allow(OrderCycleDistributedVariants).to receive(:new) { order_cycle_distributed_variants }
allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true }
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
Stripe.api_key = "sk_test_12345"
order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id)
order.reload.update_totals
set_order order

View File

@@ -30,8 +30,8 @@ module StripeHelper
end
def setup_stripe
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
allow(Stripe).to receive(:publishable_key) { "pk_test_12345" }
Stripe.api_key = "sk_test_12345"
Stripe.publishable_key = "pk_test_12345"
Spree::Config.set(stripe_connect_enabled: true)
end
end