mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Extract some more paypal-specific test code to new helper
This commit is contained in:
@@ -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) {
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<Envelope><Body>
|
||||
<GetExpressCheckoutDetailsResponse>
|
||||
<Ack>Success</Ack>
|
||||
<PaymentDetails>Something</PaymentDetails>
|
||||
<DoExpressCheckoutPaymentResponseDetails>
|
||||
<PaymentInfo><TransactionID>s0metran$act10n</TransactionID></PaymentInfo>
|
||||
</DoExpressCheckoutPaymentResponseDetails>
|
||||
</GetExpressCheckoutDetailsResponse>
|
||||
</Body></Envelope>"
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<Envelope><Body>
|
||||
<GetExpressCheckoutDetailsResponse>
|
||||
<Ack>Success</Ack>
|
||||
<PaymentDetails>Something</PaymentDetails>
|
||||
<DoExpressCheckoutPaymentResponseDetails>
|
||||
<PaymentInfo><TransactionID>s0metran$act10n</TransactionID></PaymentInfo>
|
||||
</DoExpressCheckoutPaymentResponseDetails>
|
||||
</GetExpressCheckoutDetailsResponse>
|
||||
</Body></Envelope>"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user