Restore removed spec to profile_storer_spec

This commit is contained in:
Nihal
2021-08-25 14:01:58 +05:30
parent 98ff3980f8
commit 98a879a0e9
3 changed files with 28 additions and 8 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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