diff --git a/spec/requests/checkout/paypal_spec.rb b/spec/requests/checkout/paypal_spec.rb index e309d0ea5d..85ce495b9d 100644 --- a/spec/requests/checkout/paypal_spec.rb +++ b/spec/requests/checkout/paypal_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe "checking out an order with a paypal express payment method", type: :request do include ShopWorkflow + include PaypalHelper let!(:address) { create(:address) } let!(:shop) { create(:enterprise) } @@ -25,18 +26,6 @@ describe "checking out an order with a paypal express payment method", type: :re ) end let(:params) { { token: 'lalalala', PayerID: 'payer1', payment_method_id: payment_method.id } } - let(:mocked_xml_response) { - " - - - Success - Something - - s0metran$act10n - - - " - } before do order.reload.update_totals @@ -45,8 +34,7 @@ describe "checking out an order with a paypal express payment method", type: :re expect(order.next).to be true # => payment set_order order - stub_request(:post, "https://api-3t.sandbox.paypal.com/2.0/") - .to_return(status: 200, body: mocked_xml_response ) + stub_paypal_confirm end context "with a flat percent calculator" do diff --git a/spec/support/request/paypal_helper.rb b/spec/support/request/paypal_helper.rb index 7f0ad8b5c2..6796bb14b5 100644 --- a/spec/support/request/paypal_helper.rb +++ b/spec/support/request/paypal_helper.rb @@ -1,14 +1,37 @@ # frozen_string_literal: true module PaypalHelper + # Initial request to confirm the payment can be placed (before redirecting to paypal) def stub_paypal_response(options) paypal_response = double(:response, success?: options[:success], errors: []) paypal_provider = double( :provider, build_set_express_checkout: nil, - set_express_checkout: paypal_response + set_express_checkout: paypal_response, + express_checkout_url: options[:redirect] ) allow_any_instance_of(Spree::PaypalController).to receive(:provider). and_return(paypal_provider) end + + # Additional request to re-confirm the payment, when the order is finalised. + def stub_paypal_confirm + stub_request(:post, "https://api-3t.sandbox.paypal.com/2.0/") + .to_return(status: 200, body: mocked_xml_response ) + end + + private + + def mocked_xml_response + " + + + Success + Something + + s0metran$act10n + + + " + end end