From 98a879a0e9de7152067f47ca2aa94db76dcc3abd Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 25 Aug 2021 14:01:58 +0530 Subject: [PATCH] Restore removed spec to profile_storer_spec --- .../orders/payments/payments_controller_spec.rb | 11 ++++++----- spec/jobs/subscription_confirm_job_spec.rb | 12 +++++++++--- spec/lib/stripe/profile_storer_spec.rb | 13 +++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb b/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb index 9b4610069d..546d67ec86 100644 --- a/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb +++ b/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb @@ -45,13 +45,14 @@ describe Spree::Admin::PaymentsController, type: :controller do end context "with Stripe payment where payment.process! errors out" do - let!(:payment_method) { create(:stripe_sca_payment_method, distributors: [shop]) } before do - allow_any_instance_of(Spree::Payment). - to receive(:process_offline!). - and_raise(Spree::Core::GatewayError.new("Payment Gateway Error")) + allow_any_instance_of(Spree::Payment).to receive(:authorize!) do |payment| + payment.update state: "pending" + end + allow_any_instance_of(Spree::Payment).to receive(:process_offline!). + and_raise(Spree::Core::GatewayError.new("Payment Gateway Error")) end - + it "redirects to new payment page with flash error" do spree_post :create, payment: params, order_id: order.number diff --git a/spec/jobs/subscription_confirm_job_spec.rb b/spec/jobs/subscription_confirm_job_spec.rb index ca93fc0f23..1bd129e603 100644 --- a/spec/jobs/subscription_confirm_job_spec.rb +++ b/spec/jobs/subscription_confirm_job_spec.rb @@ -191,20 +191,26 @@ describe SubscriptionConfirmJob do end end - context "Stripe Connect" do + context "Stripe SCA" do let(:stripe_sca_payment_method) { create(:stripe_sca_payment_method) } let(:stripe_sca_payment) { create(:payment, amount: 10, payment_method: stripe_sca_payment_method) } + let(:provider) { double } before do + allow_any_instance_of(Stripe::CreditCardCloner).to receive(:find_or_clone) { + ["cus_123", "pm_1234"] + } allow(order).to receive(:pending_payments) { [stripe_sca_payment] } - allow(stripe_sca_payment_method).to receive(:purchase) { true } + allow(stripe_sca_payment_method).to receive(:provider) { provider } + allow(stripe_sca_payment_method.provider).to receive(:purchase) { true } + allow(stripe_sca_payment_method.provider).to receive(:capture) { true } end it "runs the charges in offline mode" do job.send(:confirm_order!, order) - expect(stripe_sca_payment_method).to have_received(:purchase) + expect(stripe_sca_payment_method.provider).to have_received(:purchase) end end end diff --git a/spec/lib/stripe/profile_storer_spec.rb b/spec/lib/stripe/profile_storer_spec.rb index e7b69f8c8c..1836517bc1 100644 --- a/spec/lib/stripe/profile_storer_spec.rb +++ b/spec/lib/stripe/profile_storer_spec.rb @@ -25,6 +25,19 @@ module Stripe stub_payment_method_attach_request(payment_method: card_id, customer: customer_id) end + context "when called from Stripe SCA" do + let(:customer_response_body) { + JSON.generate(id: customer_id, default_card: card_id, sources: { data: [{ id: "1" }] }) + } + + it "fetches the customer id and the card id from the correct response fields" do + profile_storer.create_customer_from_token + + expect(payment.source.gateway_customer_profile_id).to eq customer_id + expect(payment.source.gateway_payment_profile_id).to eq card_id + end + end + context "when called from Stripe SCA" do it "fetches the customer id and the card id from the correct response fields" do profile_storer.create_customer_from_token