From 4b067e2ece00bd55339ae6cee74ad22c2965b672 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 8 Nov 2022 14:33:30 +0000 Subject: [PATCH 1/2] Creates separate helpers for enabling Stripe and keys --- spec/support/request/stripe_helper.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index 17d8893c2b..3a5ca6b4c2 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -28,9 +28,20 @@ module StripeHelper fill_in "cvc", with: "678" end - def setup_stripe - Stripe.api_key = "sk_test_12345" - Stripe.publishable_key = "pk_test_12345" - allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) + def stripe_enable + RSpec::Mocks.with_temporary_scope do + allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) + end + end + + def with_stripe_setup(api_key = "sk_test_12345", publishable_key = "pk_test_12345") + original_keys = [Stripe.api_key, Stripe.publishable_key] + + Stripe.api_key = api_key + Stripe.publishable_key = publishable_key + + yield + + Stripe.api_key, Stripe.publishable_key = original_keys end end From 1a3c4008fd862d67708edb8ce1bfdada2dccedd3 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 8 Nov 2022 14:34:50 +0000 Subject: [PATCH 2/2] Applies helpers to relevant specs --- spec/support/request/stripe_helper.rb | 4 +--- spec/system/admin/payments_stripe_spec.rb | 6 ++++-- spec/system/consumer/shopping/checkout_stripe_spec.rb | 6 +++++- spec/system/consumer/split_checkout_spec.rb | 6 +++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index 3a5ca6b4c2..3aeef17e43 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -29,9 +29,7 @@ module StripeHelper end def stripe_enable - RSpec::Mocks.with_temporary_scope do - allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) - end + allow(Spree::Config).to receive(:stripe_connect_enabled).and_return(true) end def with_stripe_setup(api_key = "sk_test_12345", publishable_key = "pk_test_12345") diff --git a/spec/system/admin/payments_stripe_spec.rb b/spec/system/admin/payments_stripe_spec.rb index 7852fbfcda..77374225c1 100644 --- a/spec/system/admin/payments_stripe_spec.rb +++ b/spec/system/admin/payments_stripe_spec.rb @@ -18,9 +18,11 @@ describe ' create(:stripe_account, enterprise: order.distributor, stripe_user_id: "abc123") end - before { setup_stripe } + around do |example| + with_stripe_setup { example.run } + end - context "making a new Stripe payment", js: true do + context "making a new Stripe payment" do before do stub_payment_methods_post_request stub_payment_intent_get_request diff --git a/spec/system/consumer/shopping/checkout_stripe_spec.rb b/spec/system/consumer/shopping/checkout_stripe_spec.rb index c91d64de10..15a0aa53cf 100644 --- a/spec/system/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/system/consumer/shopping/checkout_stripe_spec.rb @@ -30,8 +30,12 @@ describe "Check out with Stripe", js: true do calculator: Calculator::FlatRate.new(preferred_amount: 5.67)) } + around do |example| + with_stripe_setup { example.run } + end + before do - setup_stripe + stripe_enable set_order order add_product_to_cart order, product distributor.shipping_methods << [shipping_with_fee, free_shipping] diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index b5e21b83ce..071fccc627 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -644,8 +644,12 @@ describe "As a consumer, I want to checkout my order", js: true do end context "for Stripe SCA", if: pay_method.eql?("Stripe SCA") do + around do |example| + with_stripe_setup { example.run } + end + before do - setup_stripe + stripe_enable visit checkout_step_path(:payment) end