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 tests for payment methods, and fix payment_method_factory.rb

Matthew Kennedy7f701a1232e1
diff --git a/backend/spec/features/admin/configuration/payment_methods_spec.rb b/backend/spec/features/admin/configuration/payment_methods_spec.rb
index 6f14c826ad..52c0b73984 100644
--- a/backend/spec/features/admin/configuration/payment_methods_spec.rb
+++ b/backend/spec/features/admin/configuration/payment_methods_spec.rb
@@ -8,10 +8,31 @@ describe 'Payment Methods', type: :feature do
let!(:store_2) { create(:store) }
let!(:store_3) { create(:store) }
+ let!(:payment_method_one) { create(:payment_method) }
+ let!(:payment_method_two) { create(:payment_method, name: 'Should Be MIA' ,stores: [store_3]) }
+
before do
visit spree.admin_payment_methods_path
end
+ context 'managine payment methods by store' do
+ it 'only displays payment methods for current store' do
+ within('table#listing_payment_methods') do
+ expect(page).to have_content(payment_method_one.name)
+ expect(page).not_to have_content(payment_method_two.name)
+ end
+ end
+
+ it 'is able to show payment methods for all stores using filter' do
+ check 'q_all_stores'
+ click_on 'Search'
+
+ expect(page).to have_checked_field(id: 'q_all_stores')
+ expect(page).to have_content(payment_method_one.name)
+ expect(page).to have_content(payment_method_two.name)
+ end
+ end
+
context 'admin visiting payment methods listing page' do
it 'displays existing payment methods' do
create(:check_payment_method)
diff --git a/core/lib/spree/testing_support/factories/payment_method_factory.rb b/core/lib/spree/testing_support/factories/payment_method_factory.rb
index 316c97222e..23a4b37e01 100644
--- a/core/lib/spree/testing_support/factories/payment_method_factory.rb
+++ b/core/lib/spree/testing_support/factories/payment_method_factory.rb
@@ -1,5 +1,6 @@
FactoryBot.define do
factory :payment_method, class: Spree::PaymentMethod do
+ type { 'Spree::PaymentMethod' }
name { 'Test' }
before(:create) do |payment_method|
@@ -7,22 +8,25 @@ FactoryBot.define do
default_store = Spree::Store.default.persisted? ? Spree::Store.default : nil
store = default_store || create(:store)
- payment_method.stores << [store]
+ payment_method.stores << store
end
end
end
factory :check_payment_method, parent: :payment_method, class: Spree::PaymentMethod::Check do
+ type { 'Spree::PaymentMethod::Check' }
name { 'Check' }
end
factory :credit_card_payment_method, parent: :payment_method, class: Spree::Gateway::Bogus do
+ type { 'Spree::Gateway::Bogus' }
name { 'Credit Card' }
end
# authorize.net was moved to spree_gateway.
# Leaving this factory in place with bogus in case anyone is using it.
factory :simple_credit_card_payment_method, parent: :payment_method, class: Spree::Gateway::BogusSimple do
+ type { 'Spree::Gateway::BogusSimple' }
name { 'Credit Card' }
end