diff --git a/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb b/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb index 23febd49da..594b9e2dbb 100644 --- a/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb +++ b/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb @@ -216,17 +216,12 @@ describe Spree::Admin::PaymentsController, type: :controller do before do allow(Stripe).to receive(:api_key) { "sk_test_12345" } - # Retrieves payment intent info - stub_request(:get, "https://api.stripe.com/v1/payment_intents/pi_123") - .to_return({ status: 200, body: JSON.generate( - amount_received: 2000, - charges: { data: [{ id: "ch_1a2b3c" }] } - ) }) + stub_payment_intent_get_request stripe_account_header: false end context "where the request succeeds" do before do - stub_request(:post, "https://api.stripe.com/v1/charges/ch_1a2b3c/refunds"). + stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds"). with(basic_auth: ["sk_test_12345", ""]). to_return(status: 200, body: JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') ) @@ -246,7 +241,7 @@ describe Spree::Admin::PaymentsController, type: :controller do context "where the request fails" do before do - stub_request(:post, "https://api.stripe.com/v1/charges/ch_1a2b3c/refunds"). + stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds"). with(basic_auth: ["sk_test_12345", ""]). to_return(status: 200, body: JSON.generate(error: { message: "Bup-bow!" }) ) end diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index 122c35d5a8..0af9ac97ca 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -20,10 +20,10 @@ module StripeHelper .to_return(payment_intent_authorize_response_mock(response)) end - def stub_payment_intent_get_request(response: {}) - stub_request(:get, "https://api.stripe.com/v1/payment_intents/pi_123") - .with(headers: { 'Stripe-Account' => 'abc123' }) - .to_return(payment_intent_authorize_response_mock(response)) + def stub_payment_intent_get_request(response: {}, stripe_account_header: true) + stub = stub_request(:get, "https://api.stripe.com/v1/payment_intents/pi_123") + stub = stub.with(headers: { 'Stripe-Account' => 'abc123' }) if stripe_account_header + stub.to_return(payment_intent_authorize_response_mock(response)) end def stub_hub_payment_methods_request(response: {})