diff --git a/spec/lib/stripe/profile_storer_spec.rb b/spec/lib/stripe/profile_storer_spec.rb index e7b69f8c8c..0553fe5fc4 100644 --- a/spec/lib/stripe/profile_storer_spec.rb +++ b/spec/lib/stripe/profile_storer_spec.rb @@ -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