mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Make helper more flexible and use it in a spec
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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: {})
|
||||
|
||||
Reference in New Issue
Block a user