Add redirect specs for PaypalController#express

This commit is contained in:
Matt-Yorkley
2021-04-12 17:23:49 +01:00
parent 06c01955f5
commit 0dde8112d2

View File

@@ -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)