From 21d67a0723c679a0bcc13fdcfe2e6c89baa0abb1 Mon Sep 17 00:00:00 2001
From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com>
Date: Thu, 19 Nov 2020 01:44:38 +0000
Subject: [PATCH] Extract some more paypal-specific test code to new helper
---
spec/requests/checkout/paypal_spec.rb | 16 ++--------------
spec/support/request/paypal_helper.rb | 25 ++++++++++++++++++++++++-
2 files changed, 26 insertions(+), 15 deletions(-)
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