mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Stub Spree::Config.stripe_connect_enabled instead of changing it before and back after tests
It's less code and sometimes there can be issues when config cache values are changed. Co-authored-by: Maikel <maikel@email.org.au>
This commit is contained in:
@@ -79,15 +79,9 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
describe "#status" do
|
||||
let(:params) { { format: :json, enterprise_id: enterprise.id } }
|
||||
|
||||
around do |example|
|
||||
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
|
||||
example.run
|
||||
Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled)
|
||||
end
|
||||
|
||||
before do
|
||||
Stripe.api_key = "sk_test_12345"
|
||||
Spree::Config.set(stripe_connect_enabled: false)
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(false)
|
||||
end
|
||||
|
||||
context "when I don't manage the specified enterprise" do
|
||||
@@ -117,7 +111,7 @@ describe Admin::StripeAccountsController, type: :controller do
|
||||
end
|
||||
|
||||
context "when Stripe is enabled" do
|
||||
before { Spree::Config.set(stripe_connect_enabled: true) }
|
||||
before { allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) }
|
||||
|
||||
context "when no stripe account is associated with the specified enterprise" do
|
||||
it "returns with a status of 'account_missing'" do
|
||||
|
||||
@@ -50,15 +50,9 @@ describe Spree::PaymentMethod do
|
||||
context "Stripe payment method" do
|
||||
let(:payment_method) { create(:stripe_sca_payment_method) }
|
||||
|
||||
around do |example|
|
||||
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
|
||||
example.run
|
||||
Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled)
|
||||
end
|
||||
|
||||
before do
|
||||
Spree::Config.set(stripe_connect_enabled: true)
|
||||
Stripe.publishable_key = "some_key"
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true)
|
||||
allow(Stripe).to receive(:publishable_key) { "some_key" }
|
||||
end
|
||||
|
||||
context "and Stripe Connect is enabled and a Stripe publishable key, account id, account
|
||||
@@ -69,7 +63,7 @@ describe Spree::PaymentMethod do
|
||||
end
|
||||
|
||||
context "and Stripe Connect is disabled" do
|
||||
before { Spree::Config.set(stripe_connect_enabled: false) }
|
||||
before { allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(false) }
|
||||
|
||||
it "returns false" do
|
||||
expect(payment_method).not_to be_configured
|
||||
@@ -77,7 +71,7 @@ describe Spree::PaymentMethod do
|
||||
end
|
||||
|
||||
context "and a Stripe publishable key is not present" do
|
||||
before { Spree::Config.set(stripe_connect_enabled: false) }
|
||||
before { allow(Stripe).to receive(:publishable_key) { nil } }
|
||||
|
||||
it "returns false" do
|
||||
expect(payment_method).not_to be_configured
|
||||
|
||||
@@ -82,18 +82,12 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques
|
||||
}
|
||||
end
|
||||
|
||||
around do |example|
|
||||
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
|
||||
example.run
|
||||
Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled)
|
||||
end
|
||||
|
||||
before do
|
||||
order_cycle_distributed_variants = double(:order_cycle_distributed_variants)
|
||||
allow(OrderCycleDistributedVariants).to receive(:new) { order_cycle_distributed_variants }
|
||||
allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true }
|
||||
allow(Stripe).to receive(:publishable_key).and_return("some_token")
|
||||
Spree::Config.set(stripe_connect_enabled: true)
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true)
|
||||
Stripe.api_key = "sk_test_12345"
|
||||
order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id)
|
||||
order.reload.update_totals
|
||||
|
||||
@@ -31,6 +31,6 @@ module StripeHelper
|
||||
def setup_stripe
|
||||
Stripe.api_key = "sk_test_12345"
|
||||
Stripe.publishable_key = "pk_test_12345"
|
||||
Spree::Config.set(stripe_connect_enabled: true)
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,14 +53,8 @@ describe '
|
||||
{ id: "acc_connected123", business_name: "My Org", charges_enabled: true }
|
||||
}
|
||||
|
||||
around do |example|
|
||||
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
|
||||
example.run
|
||||
Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled)
|
||||
end
|
||||
|
||||
before do
|
||||
Spree::Config.set(stripe_connect_enabled: true)
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true)
|
||||
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))
|
||||
|
||||
@@ -18,19 +18,13 @@ describe "Credit Cards", js: true do
|
||||
create(:stored_credit_card, user_id: user.id, gateway_customer_profile_id: 'cus_FDTG')
|
||||
}
|
||||
|
||||
around do |example|
|
||||
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
|
||||
example.run
|
||||
Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled)
|
||||
end
|
||||
|
||||
before do
|
||||
login_as user
|
||||
|
||||
allow(Stripe).to receive(:api_key).and_return("sk_test_12345")
|
||||
allow(Stripe.config).to receive(:api_key).and_return("sk_test_12345")
|
||||
allow(Stripe).to receive(:publishable_key).and_return("some_token")
|
||||
Spree::Config.set(stripe_connect_enabled: true)
|
||||
allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true)
|
||||
|
||||
stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ").
|
||||
to_return(status: 200, body: JSON.generate(id: "cus_AZNMJ"))
|
||||
|
||||
Reference in New Issue
Block a user