mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Update/improve paypal controller specs
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user