Improve Stripe::ProfileStorer specs

* Use `with_stripe_setup` helper
* add the request failing scenario
This commit is contained in:
Gaetan Craig-Riou
2024-02-05 16:24:41 +11:00
parent 62fbaa8a6e
commit 8a0c32eec0

View File

@@ -5,6 +5,7 @@ require 'spec_helper'
module Stripe
describe ProfileStorer do
include StripeStubs
include StripeHelper
describe "create_customer_from_token" do
let(:stripe_payment_method) { create(:stripe_sca_payment_method) }
@@ -18,9 +19,11 @@ module Stripe
{ status: 200, body: JSON.generate(id: customer_id, sources: { data: [{ id: "1" }] }) }
}
before do
Stripe.api_key = "sk_test_12345"
around do |example|
with_stripe_setup { example.run }
end
before do
stub_customers_post_request(email: payment.order.email, response: customer_response_mock)
stub_payment_method_attach_request(payment_method: card_id, customer: customer_id)
end
@@ -32,6 +35,18 @@ module Stripe
expect(payment.source.gateway_customer_profile_id).to eq customer_id
expect(payment.source.gateway_payment_profile_id).to eq card_id
end
context "when request fails" do
it "raises an error" do
expect(stripe_payment_method.provider).to receive(:store).and_return(
ActiveMerchant::Billing::Response.new(false, "some error")
)
expect { profile_storer.create_customer_from_token }.to raise_error(
Spree::Core::GatewayError
)
end
end
end
end
end