diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 761ff189ab..b239667772 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -57,6 +57,48 @@ module Spree end end + describe "#express" do + let(:order) { create(:order_with_distributor) } + let(:response) { true } + let(:provider_success_url) { "https://test.com/success" } + let(:response_mock) { double(:response, success?: response, errors: [] ) } + let(:provider_mock) { double(:provider, build_set_express_checkout: true, + set_express_checkout: response_mock, + express_checkout_url: provider_success_url) } + + before do + allow(controller).to receive(:current_order) { order } + allow(controller).to receive(:provider) { provider_mock } + allow(controller).to receive(:express_checkout_request_details) { {} } + end + + context "when processing is successful" do + it "redirects to a success URL generated by the payment provider" do + expect(spree_post :express).to redirect_to provider_success_url + end + end + + context "when processing fails" do + let(:response) { false } + + it "redirects to checkout_state_path with a flash error" do + expect(spree_post :express).to redirect_to checkout_state_path(:payment) + expect(flash[:error]).to eq "PayPal failed. " + end + end + + context "when a SocketError is encountered during processing" do + before do + allow(response_mock).to receive(:success?).and_raise(SocketError) + end + + it "redirects to checkout_state_path with a flash error" do + expect(spree_post :express).to redirect_to checkout_state_path(:payment) + expect(flash[:error]).to eq "Could not connect to PayPal." + end + end + end + describe '#expire_current_order' do it 'empties the order_id of the session' do expect(session).to receive(:[]=).with(:order_id, nil)