mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-29 06:21:16 +00:00
Extract customers stripe stub to StripeStubs helper
This commit is contained in:
@@ -204,23 +204,11 @@ feature "Check out with Stripe", js: true do
|
||||
end
|
||||
|
||||
context "saving a card and re-using it" do
|
||||
let(:customers_response_mock) do
|
||||
{ status: 200,
|
||||
body: JSON.generate(id: "cus_A123",
|
||||
sources: { data: [id: "cus_A123"] }) }
|
||||
end
|
||||
|
||||
before do
|
||||
stub_payment_methods_post_request request: { payment_method: "pm_123", customer: "cus_A123" }, response: { pm_id: "pm_123" }
|
||||
stub_payment_intents_post_request order: order
|
||||
stub_successful_capture_request order: order
|
||||
|
||||
# Creates a customer
|
||||
# This stubs the customers call to both the main stripe account and the connected account
|
||||
stub_request(:post, "https://api.stripe.com/v1/customers")
|
||||
.with(body: { email: user.email })
|
||||
.to_return(customers_response_mock)
|
||||
|
||||
stub_customer_post_request email: user.email
|
||||
stub_payment_method_attach_request
|
||||
end
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@ module StripeStubs
|
||||
.to_return(hub_payment_method_response_mock({ pm_id: "pm_123" }))
|
||||
end
|
||||
|
||||
# Stubs the customers call to both the main stripe account and the connected account
|
||||
def stub_customer_post_request(email:)
|
||||
stub_request(:post, "https://api.stripe.com/v1/customers")
|
||||
.with(body: { email: email })
|
||||
.to_return(customers_response_mock)
|
||||
end
|
||||
|
||||
def stub_successful_capture_request(order:, response: {})
|
||||
stub_capture_request(order, payment_successful_capture_mock(response))
|
||||
end
|
||||
@@ -98,6 +105,12 @@ module StripeStubs
|
||||
body: JSON.generate(id: options[:pm_id] || "pm_456", customer: "cus_A123") }
|
||||
end
|
||||
|
||||
def customers_response_mock
|
||||
{ status: 200,
|
||||
body: JSON.generate(id: "cus_A123",
|
||||
sources: { data: [id: "cus_A123"] }) }
|
||||
end
|
||||
|
||||
def payment_successful_refund_mock
|
||||
{ status: 200,
|
||||
body: JSON.generate(object: "refund",
|
||||
|
||||
Reference in New Issue
Block a user