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 6216228619..23febd49da 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 @@ -3,6 +3,8 @@ require 'spec_helper' describe Spree::Admin::PaymentsController, type: :controller do + include StripeHelper + let!(:shop) { create(:enterprise) } let!(:user) { shop.owner } let!(:order) { create(:order, distributor: shop, state: 'complete') } @@ -152,19 +154,13 @@ describe Spree::Admin::PaymentsController, type: :controller do allow(Stripe).to receive(:api_key) { "sk_test_12345" } allow(StripeAccount).to receive(:find_by) { stripe_account } - # Retrieves payment intent info - stub_request(:get, "https://api.stripe.com/v1/payment_intents/pi_123") - .with(headers: { 'Stripe-Account' => 'abc123' }) - .to_return({ status: 200, body: JSON.generate( - amount_received: 2000, - charges: { data: [{ id: "ch_1a2b3c" }] } - ) }) + stub_payment_intent_get_request end context "where the request succeeds" do before do # Issues the refund - 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') ) @@ -184,7 +180,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 ce981a06dc..122c35d5a8 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -55,6 +55,7 @@ module StripeHelper body: JSON.generate(id: "pi_123", object: "payment_intent", amount: 2000, + amount_received: 2000, status: options[:intent_status] || "requires_capture", last_payment_error: nil, charges: { data: [{ id: "ch_1234", amount: 2000 }] }) }