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
Add tests for stock items and product name filtering
wjwitek39a61388f89d
diff --git a/api/spec/requests/spree/api/v2/platform/line_items_spec.rb b/api/spec/requests/spree/api/v2/platform/line_items_spec.rbindex 88a35314b6..6436ee690d 100644--- a/api/spec/requests/spree/api/v2/platform/line_items_spec.rb+++ b/api/spec/requests/spree/api/v2/platform/line_items_spec.rb@@ -6,7 +6,7 @@ describe 'API V2 Platform Line Items Spec' dolet(:bearer_token) { { 'Authorization' => valid_authorization } }let!(:line_items) { create_list(:line_item, 5) }-+describe 'line_items#index' docontext 'with no params' dobefore { get '/api/v2/platform/line_items', headers: bearer_token }@@ -59,6 +59,14 @@ describe 'API V2 Platform Line Items Spec' doexpect(json_response['data'].first['id']).to eq line_item.id.to_sendend++ context 'by variant name' do+ before { get "/api/v2/platform/line_items?filter[variant_product_name_or_variant_sku_cont]=#{line_items.first.variant.name}", headers: bearer_token }++ it 'returns line items with correct variant name' do+ expect(json_response['data'].count).to eq 1+ end+ endendcontext 'sorting' dodiff --git a/api/spec/requests/spree/api/v2/platform/products_spec.rb b/api/spec/requests/spree/api/v2/platform/products_spec.rbindex 90db92f32d..2808ae5063 100644--- a/api/spec/requests/spree/api/v2/platform/products_spec.rb+++ b/api/spec/requests/spree/api/v2/platform/products_spec.rb@@ -307,6 +307,14 @@ describe 'API V2 Platform Products Spec' doendendend++ context 'filtering' do+ before { get "/api/v2/platform/products?filter[name_cont]=#{in_stock_product.name}", headers: bearer_token }++ it 'returns line items with correct variant name' do+ expect(json_response['data'].count).to eq 1+ end+ endenddescribe 'products#show' dodiff --git a/api/spec/requests/spree/api/v2/platform/stock_items_spec.rb b/api/spec/requests/spree/api/v2/platform/stock_items_spec.rbnew file mode 100644index 0000000000..2493658a37--- /dev/null+++ b/api/spec/requests/spree/api/v2/platform/stock_items_spec.rb@@ -0,0 +1,36 @@+require 'spec_helper'++describe 'Platform API v2 Stock Items API' do+ include_context 'Platform API v2'++ let(:bearer_token) { { 'Authorization' => valid_authorization } }++ let(:product_1) { create(:product, stores: [store]) }+ let(:product_2) { create(:product, stores: [store]) }+ let!(:stock_location_1) { create(:stock_location) }+ let!(:stock_location_2) { create(:stock_location) }++ describe 'stock_items#index' do+ let!(:variants) { create_list(:variant, 2, product: product_1) }+ let!(:variants) { create_list(:variant, 2, product: product_2) }++ context 'filtering by stock location id' do+ before { get "/api/v2/platform/stock_items?filter[stock_location_id_eq]=#{stock_location_1.id}", headers: bearer_token }++ it 'returns stock_items with matching stock location ids' do+ expect(json_response['data'].count).to eq 3+ expect(json_response['data'].first).to have_type('stock_item')+ end+ end++ context 'filtering by variant product name or sku' do+ before { get "/api/v2/platform/stock_items?filter[variant_product_name_or_variant_sku_cont]=#{product_2.name}", headers: bearer_token }++ it 'returns stock_items with matching stock location ids' do+ expect(json_response['data'].count).to eq 2+ expect(json_response['data'].first).to have_type('stock_item')+ end+ end+ end+end+diff --git a/api/spec/requests/spree/api/v2/platform/variants_spec.rb b/api/spec/requests/spree/api/v2/platform/variants_spec.rbindex 1043c3e677..cbf6f86521 100644--- a/api/spec/requests/spree/api/v2/platform/variants_spec.rb+++ b/api/spec/requests/spree/api/v2/platform/variants_spec.rb@@ -7,7 +7,7 @@ describe 'API V2 Platform Variants Spec' dolet(:product) { create(:product, stores: [store]) }let!(:variants) { create_list(:variant, 5, product: product) }-+describe 'variants#index' docontext 'with no params' dobefore { get '/api/v2/platform/variants', headers: bearer_token }@@ -41,7 +41,7 @@ describe 'API V2 Platform Variants Spec' dolet(:product_2) { create(:product, stores: [store], name: 'Vendo T-shirt') }let!(:variant) { create(:variant, product: product_2) }- before { get "/api/v2/platform/variants?filter[product_name_cont]=vendo&filter[is_master_eq]=false", headers: bearer_token }+ before { get '/api/v2/platform/variants?filter[product_name_cont]=vendo&filter[is_master_eq]=false', headers: bearer_token }it 'returns variant with a specified name' doexpect(json_response['data'].count).to eq 1@@ -52,7 +52,7 @@ describe 'API V2 Platform Variants Spec' doxcontext 'by price' dolet!(:variant) { create(:variant, price: 100) }- before { get "/api/v2/platform/variants?filter[product_price_between]=100,200", headers: bearer_token }+ before { get '/api/v2/platform/variants?filter[product_price_between]=100,200', headers: bearer_token }it 'returns variants with price greater than or equal to the given price' doexpect(json_response['data'].count).to eq 1