Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add more tests for Payment Methods

Damian Legawiec477c63a99e34
diff --git a/backend/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/backend/spec/controllers/spree/admin/payment_methods_controller_spec.rb
index ef84e86dd0..395af4a2d0 100644
--- a/backend/spec/controllers/spree/admin/payment_methods_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/payment_methods_controller_spec.rb
@@ -52,7 +52,6 @@ module Spree
expect(Spree::PaymentMethod.last.stores).to eq([store])
- expect(response).to be_redirect
expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method))
end
@@ -61,8 +60,67 @@ module Spree
post :create, params: { payment_method: { name: 'Invalid Payment Method', type: 'Spree::InvalidType' } }
end.to change(Spree::PaymentMethod, :count).by(0)
- expect(response).to be_redirect
expect(response).to redirect_to spree.new_admin_payment_method_path
end
+
+ describe '#index' do
+ let!(:payment_method_1) { create(:payment_method, stores: [store]) }
+ let!(:payment_method_2) { create(:payment_method, stores: [store]) }
+ let!(:payment_method_3) { create(:payment_method, stores: [create(:store)]) }
+
+ it 'assigns the payment_methods for current store' do
+ get :index
+ expect(assigns(:collection)).to include payment_method_1
+ expect(assigns(:collection)).to include payment_method_2
+ expect(assigns(:collection)).not_to include payment_method_3
+ end
+ end
+
+ describe '#edit' do
+ subject(:send_request) do
+ get :edit, params: { id: payment_method }
+ end
+
+ it { expect(send_request).to have_http_status(:ok) }
+
+ context 'payment method from different store' do
+ let(:payment_method) { create(:payment_method, stores: [create(:store)]) }
+
+ it { expect(send_request).to redirect_to(spree.admin_payment_methods_path) }
+ end
+ end
+
+ describe '#destroy' do
+ subject(:send_request) do
+ delete :destroy, params: { id: payment_method, format: :js }
+ end
+
+ let(:payment_method) { create(:payment_method, stores: [store], name: 'Test') }
+
+ shared_examples 'correct response' do
+ it { expect(assigns(:payment_method)).to eq(payment_method) }
+ it { expect(response).to have_http_status(:ok) }
+ end
+
+ context 'will successfully destroy payment_method' do
+ describe 'returns response' do
+ before { send_request }
+
+ it_behaves_like 'correct response'
+ it { expect(flash[:success]).to eq('Payment Method "Test" has been successfully removed!') }
+ end
+ end
+
+ context 'cannot destroy payment_method from different store' do
+ let(:payment_method) { create(:payment_method, stores: [create(:store)]) }
+
+ it { expect(send_request).to redirect_to(spree.admin_payment_methods_path) }
+
+ it do
+ send_request
+ expect(flash[:error]).to eq('Payment Method is not found')
+ end
+ end
+ end
end
end