From 7b8e1f5c30c85ecda5546dc897fad4472b1baa6d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 15 Dec 2021 23:32:36 +0000 Subject: [PATCH] Update/improve paypal controller specs --- .../paypal_controller_spec.rb | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/spec/controllers/payment_gateways/paypal_controller_spec.rb b/spec/controllers/payment_gateways/paypal_controller_spec.rb index a3095a8222..a86d0f3773 100644 --- a/spec/controllers/payment_gateways/paypal_controller_spec.rb +++ b/spec/controllers/payment_gateways/paypal_controller_spec.rb @@ -6,7 +6,7 @@ module PaymentGateways describe PaypalController, type: :controller do context '#cancel' do it 'redirects back to checkout' do - expect(spree_get(:cancel)).to redirect_to checkout_path + expect(get(:cancel)).to redirect_to checkout_path end end @@ -16,15 +16,16 @@ module PaymentGateways before do allow(previous_order).to receive(:complete?).and_return(true) + allow(previous_order).to receive(:checkout_allowed?).and_return(true) end it 'resets the order' do - spree_post :confirm, payment_method_id: payment_method.id + post :confirm, params: { payment_method_id: payment_method.id } expect(controller.current_order).not_to eq(previous_order) end it 'sets the access token of the session' do - spree_post :confirm, payment_method_id: payment_method.id + post :confirm, params: { payment_method_id: payment_method.id } expect(session[:access_token]).to eq(controller.current_order.token) end @@ -34,7 +35,7 @@ module PaymentGateways end it "redirects to the cart with out of stock error" do - expect(spree_post(:confirm, payment_method_id: payment_method.id)). + expect(post(:confirm, params: { payment_method_id: payment_method.id })). to redirect_to cart_path order = controller.current_order.reload @@ -51,14 +52,16 @@ module PaymentGateways end it "redirects to checkout state path" do - expect(spree_post(:confirm, payment_method_id: payment_method.id)). - to redirect_to checkout_state_path(:cart) + expect(post(:confirm, params: { payment_method_id: payment_method.id })). + to redirect_to checkout_path + + expect(flash[:error]).to eq I18n.t(:payment_processing_failed) end end end describe "#express" do - let(:order) { create(:order_with_distributor) } + let(:order) { create(:order_with_totals_and_distribution) } let(:response) { true } let(:provider_success_url) { "https://test.com/success" } let(:response_mock) { double(:response, success?: response, errors: [] ) } @@ -76,7 +79,7 @@ module PaymentGateways 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 + expect(post(:express)).to redirect_to provider_success_url end end @@ -84,7 +87,7 @@ module PaymentGateways 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(post(:express)).to redirect_to checkout_state_path(:payment) expect(flash[:error]).to eq "PayPal failed. " end end @@ -95,7 +98,7 @@ module PaymentGateways end it "redirects to checkout_state_path with a flash error" do - expect(spree_post(:express)).to redirect_to checkout_state_path(:payment) + expect(post(:express)).to redirect_to checkout_state_path(:payment) expect(flash[:error]).to eq "Could not connect to PayPal." end end