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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed taxon/taxonomies specs
Damian Legawiecaa83c9fbba22
diff --git a/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb b/api/spec/requests/spree/api/v2/storefront/taxons_spec.rbindex 6c83266af3..e8cac17cb7 100644--- a/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb@@ -1,15 +1,15 @@require 'spec_helper'describe 'Taxons Spec', type: :request do- let!(:default_store) { taxonomy.store }- let!(:taxonomy) { create(:taxonomy) }+ let!(:store) { Spree::Store.default }+ let!(:taxonomy) { store.taxonomies.first }let!(:taxons) { create_list(:taxon, 2, taxonomy: taxonomy, parent: taxonomy.root) }let(:store2) { create(:store)}let!(:taxonomy2) { create(:taxonomy, store: store2) }before do- default_store.update_column(:supported_locales, 'en,pl,es')+ store.update_column(:supported_locales, 'en,pl,es')Spree::Api::Config[:api_v2_per_page_limit] = 2end@@ -26,26 +26,24 @@ describe 'Taxons Spec', type: :request dodescribe 'taxons#index' docontext 'with no params' do- let(:default_store_taxons) { [taxonomy.root, taxons].flatten }-before { get '/api/v2/storefront/taxons' }it_behaves_like 'returns 200 HTTP status'it 'returns all taxons' do- expect(json_response['data'].size).to eq(3)+ expect(json_response['data'].size).to eq(store.taxons.count)expect(json_response['data'][0]).to have_type('taxon')expect(json_response['data'][0]).to have_relationships(:parent, :taxonomy, :children, :image)expect(json_response['data'][0]).not_to have_relationships(:produts)endit 'should return only default store taxons' do- expect(json_response['data'].map{ |t| t['id'] }).to match_array(default_store_taxons.pluck(:id).map(&:to_s))+ expect(json_response['data'].map{ |t| t['id'] }).to contain_exactly(*store.taxons.pluck(:id).map(&:to_s))endendcontext 'with locale set to pl' do- let!(:default_store) do+ let!(:store) dostore = taxonomy.storestore.supported_locales = 'en,pl'store.save@@ -104,9 +102,9 @@ describe 'Taxons Spec', type: :request doit_behaves_like 'returns 200 HTTP status'it 'returns taxons by roots' do- expect(json_response['data'].size).to eq(1)+ expect(json_response['data'].size).to eq(store.taxons.where(parent: nil).count)expect(json_response['data'][0]).to have_type('taxon')- expect(json_response['data'][0]).to have_id(taxonomy.root.id.to_s)+ expect(json_response['data'][0]).to have_id(store.taxonomies.first.root.id.to_s)expect(json_response['data'][0]).to have_relationship(:parent).with_data(nil)expect(json_response['data'][0]).to have_relationships(:parent, :taxonomy, :children, :image)end@@ -175,7 +173,7 @@ describe 'Taxons Spec', type: :request doit_behaves_like 'returns 200 HTTP status'it 'returns taxons by taxonomy' do- expect(json_response['data'].size).to eq(3)+ expect(json_response['data'].size).to eq(taxonomy.taxons.count + 1) # taxons + rootexpect(json_response['data'][0]).to have_relationship(:taxonomy).with_data('id' => taxonomy.id.to_s, 'type' => 'taxonomy')expect(json_response['data'][1]).to have_relationship(:taxonomy).with_data('id' => taxonomy.id.to_s, 'type' => 'taxonomy')expect(json_response['data'][2]).to have_relationship(:taxonomy).with_data('id' => taxonomy.id.to_s, 'type' => 'taxonomy')@@ -203,79 +201,6 @@ describe 'Taxons Spec', type: :request doexpect(json_response['data'].last['attributes']['name']).to eq(taxons.last.name)endend-- context 'paginate taxons' do- context 'with specified pagination params' do- context 'when per_page is between 1 and default value' do- before { get '/api/v2/storefront/taxons?page=1&per_page=1' }-- it_behaves_like 'returns 200 HTTP status'-- it 'returns specified amount of taxons' do- expect(json_response['data'].count).to eq 1- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq 1- expect(json_response['meta']['total_count']).not_to eq Spree::Taxon.count- expect(json_response['meta']['total_count']).to eq default_store.taxons.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/storefront/taxons?page=1&per_page=1')- expect(json_response['links']['next']).to include('/api/v2/storefront/taxons?page=2&per_page=1')- expect(json_response['links']['prev']).to include('/api/v2/storefront/taxons?page=1&per_page=1')- end- end-- context 'when per_page is above the default value' do- before { get '/api/v2/storefront/taxons?page=1&per_page=10' }-- it 'returns the default number of taxons' do- expect(json_response['data'].count).to eq 3- end- end-- context 'when per_page is less than 0' do- before { get '/api/v2/storefront/taxons?page=1&per_page=-1' }-- it 'returns the default number of taxons' do- expect(json_response['data'].count).to eq 3- end- end-- context 'when per_page is equal 0' do- before { get '/api/v2/storefront/taxons?page=1&per_page=0' }-- it 'returns the default number of taxons' do- expect(json_response['data'].count).to eq 3- end- end- end-- context 'without specified pagination params' do- before { get '/api/v2/storefront/taxons' }-- it_behaves_like 'returns 200 HTTP status'-- it 'returns specified amount of taxons' do- expect(json_response['data'].count).not_to eq Spree::Taxon.count- expect(json_response['data'].count).to eq default_store.taxons.count- end-- it 'returns proper meta data' do- expect(json_response['meta']['count']).to eq json_response['data'].count- expect(json_response['meta']['total_count']).not_to eq Spree::Taxon.count- expect(json_response['meta']['total_count']).to eq default_store.taxons.count- end-- it 'returns proper links data' do- expect(json_response['links']['self']).to include('/api/v2/storefront/taxons')- expect(json_response['links']['next']).to include('/api/v2/storefront/taxons?page=1')- expect(json_response['links']['prev']).to include('/api/v2/storefront/taxons?page=1')- end- end- endenddescribe 'taxons#show' do@@ -296,20 +221,20 @@ describe 'Taxons Spec', type: :request docontext 'by permalink' dobefore do- get "/api/v2/storefront/taxons/#{default_store.taxons.first.permalink}"+ get "/api/v2/storefront/taxons/#{store.taxons.first.permalink}"endit_behaves_like 'returns valid taxon resource JSON'it 'returns taxon by permalink' do- expect(json_response['data']).to have_id(default_store.taxons.first.id.to_s)- expect(json_response['data']).to have_attribute(:name).with_value(default_store.taxons.first.name)+ expect(json_response['data']).to have_id(store.taxons.first.id.to_s)+ expect(json_response['data']).to have_attribute(:name).with_value(store.taxons.first.name)endendcontext 'with localized_slugs' dolet(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:taxonomy) { create(:taxonomy, name: 'categories', store: store2) }+ let(:taxonomy) { store2.taxonomies.find_by(name: 'Categories') }let!(:taxon_with_slug) { create(:taxon, taxonomy: taxonomy, permalink: 'test_slug_en') }let!(:translations) { taxon_with_slug.translations.create([{ permalink: 'test_slug_pl', locale: 'pl' }, { permalink: 'test_slug_es', locale: 'es' } ])}@@ -333,7 +258,7 @@ describe 'Taxons Spec', type: :request docontext 'with fallback to default locale' dolet(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:taxonomy) { create(:taxonomy, name: 'categories', store: store2) }+ let(:taxonomy) { store2.taxonomies.find_by(name: 'Categories') }let!(:taxon_with_slug) { create(:taxon, taxonomy: taxonomy, name: 'test slug en', permalink: default_locale_slug) }let(:default_locale_slug) { 'test-slug-en' }@@ -349,7 +274,7 @@ describe 'Taxons Spec', type: :request docontext 'with slug in translated locale' dolet(:store2) { create(:store, default_locale: 'en', supported_locales: 'en,pl,es') }- let(:taxonomy) { create(:taxonomy, name: 'categories', store: store2) }+ let(:taxonomy) { store2.taxonomies.find_by(name: 'Categories') }let!(:taxon_with_slug) { create(:taxon, taxonomy: taxonomy, permalink: default_locale_slug) }let!(:translations) { taxon_with_slug.translations.create([ { name: 'test slug en', permalink: translated_slug, locale: 'es' } ]) }let(:default_locale_slug) { 'test_slug_en' }diff --git a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rbindex 289d089e48..c5c625a477 100644--- a/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/stock_location_serializer_spec.rb@@ -19,6 +19,7 @@ describe Spree::Api::V2::Platform::StockLocationSerializer doaddress1: resource.address1,address2: resource.address2,admin_name: resource.admin_name,+ display_name: resource.display_name,backorderable_default: resource.backorderable_default,city: resource.city,created_at: resource.created_at,diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rbindex 54b175b7ed..e44f1dadc4 100644--- a/core/spec/models/spree/product_spec.rb+++ b/core/spec/models/spree/product_spec.rb@@ -705,7 +705,7 @@ describe Spree::Product, type: :model doenddescribe '#brand' do- let(:taxonomy) { create(:taxonomy, name: I18n.t('spree.taxonomy_brands_name')) }+ let(:taxonomy) { store.taxonomies.find_by(name: Spree.t(:taxonomy_brands_name)) }let(:product) { create(:product, taxons: [taxonomy.taxons.first], stores: [store]) }it 'fetches Brand Taxon' dodiff --git a/sample/lib/spree_sample.rb b/sample/lib/spree_sample.rbindex 65fe968ddf..782e52d003 100644--- a/sample/lib/spree_sample.rb+++ b/sample/lib/spree_sample.rb@@ -14,7 +14,6 @@ module SpreeSampleSpree::Sample.load_sample('shipping_methods')Spree::Sample.load_sample('tax_categories')Spree::Sample.load_sample('tax_rates')- Spree::Sample.load_sample('taxonomies')Spree::Sample.load_sample('promotions')Spree::Sample.load_sample('products')