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
fix including many shipping rates
KacperMekarski806e36374c81
diff --git a/api/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb b/api/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rbindex 9a4531ca28..6b67d29cd6 100644--- a/api/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb+++ b/api/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb@@ -4,6 +4,8 @@ module Spreeclass EstimatedShippingRateSerializer < BaseSerializerset_type :shipping_rate+ cache_options store: nil+attributes :name, :selected, :cost, :tax_amount, :shipping_method_idattribute :final_price do |shipping_rate|diff --git a/api/spec/requests/spree/api/v2/storefront/cart_spec.rb b/api/spec/requests/spree/api/v2/storefront/cart_spec.rbindex f29ab62f95..78cf609575 100644--- a/api/spec/requests/spree/api/v2/storefront/cart_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/cart_spec.rb@@ -775,16 +775,19 @@ describe 'API V2 Storefront Cart Spec', type: :request dolet(:country) { create(:country, iso: 'USA') }let(:zone) { create(:zone, name: 'US') }let(:shipping_method) { create(:shipping_method) }+ let(:shipping_method_2) { create(:shipping_method) }let(:address) { create(:address, country: country) }let(:shipment) { order.shipments.first }let(:shipping_rate) { shipment.selected_shipping_rate }+ let(:shipping_rate_2) { shipment.shipping_rates.where(selected: false).first }shared_examples 'returns a list of shipments with shipping rates' dobefore doorder.shipping_address = addresszone.countries << countryshipping_method.zones = [zone]+ shipping_method_2.zones = [zone]order.create_proposed_shipmentsexecuteend@@ -792,20 +795,18 @@ describe 'API V2 Storefront Cart Spec', type: :request doit_behaves_like 'returns 200 HTTP status'it 'returns valid shipments JSON' do- expect(json_response['data']).not_to be_empty- expect(json_response['data'][0]).to have_type('shipping_rate')- expect(json_response['data'][0]['attributes']).to be_present- expect(json_response['data'][0]).to have_type('shipping_rate')- expect(json_response['data'][0]).to have_attribute(:name).with_value(shipping_method.name)- expect(json_response['data'][0]).to have_attribute(:cost).with_value(shipping_rate.cost.to_s)- expect(json_response['data'][0]).to have_attribute(:tax_amount).with_value(shipping_rate.tax_amount.to_s)- expect(json_response['data'][0]).to have_attribute(:shipping_method_id).with_value(shipping_method.id)- expect(json_response['data'][0]).to have_attribute(:selected).with_value(shipping_rate.selected)- expect(json_response['data'][0]).to have_attribute(:final_price).with_value(shipping_rate.final_price.to_s)- expect(json_response['data'][0]).to have_attribute(:free).with_value(shipping_rate.free?)- expect(json_response['data'][0]).to have_attribute(:display_final_price).with_value(shipping_rate.display_final_price.to_s)- expect(json_response['data'][0]).to have_attribute(:display_cost).with_value(shipping_rate.display_cost.to_s)- expect(json_response['data'][0]).to have_attribute(:display_tax_amount).with_value(shipping_rate.display_tax_amount.to_s)+ [{shipping_method: shipping_method, shipping_rate: shipping_rate}, {shipping_method: shipping_method_2, shipping_rate: shipping_rate_2}].each do |shipping|+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:name).with_value(shipping[:shipping_method].name))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:shipping_method_id).with_value(shipping[:shipping_method].id))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:cost).with_value(shipping[:shipping_rate].cost.to_s))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:tax_amount).with_value(shipping[:shipping_rate].tax_amount.to_s))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:selected).with_value(shipping[:shipping_rate].selected))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:final_price).with_value(shipping[:shipping_rate].final_price.to_s))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:free).with_value(shipping[:shipping_rate].free?))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:display_final_price).with_value(shipping[:shipping_rate].display_final_price.to_s))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:display_cost).with_value(shipping[:shipping_rate].display_cost.to_s))+ expect(json_response['data']).to include(have_type('shipping_rate').and have_attribute(:display_tax_amount).with_value(shipping[:shipping_rate].display_tax_amount.to_s))+ endendenddiff --git a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rbindex dc9fa1a51e..ca0f3edea5 100644--- a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb@@ -582,10 +582,12 @@ describe 'API V2 Storefront Checkout Spec', type: :request dolet(:country) { Spree::Country.default }let(:zone) { create(:zone, name: 'US') }let(:shipping_method) { create(:shipping_method) }+ let(:shipping_method_2) { create(:shipping_method) }let(:address) { create(:address, country: country) }let(:shipment) { order.shipments.first }let(:shipping_rate) { shipment.selected_shipping_rate }+ let(:shipping_rate_2) { shipment.shipping_rates.where(selected: false).first }shared_examples 'returns a list of shipments with shipping rates' dobefore do@@ -593,6 +595,7 @@ describe 'API V2 Storefront Checkout Spec', type: :request doorder.save!zone.countries << countryshipping_method.zones = [zone]+ shipping_method_2.zones = [zone]order.create_proposed_shipmentsexecuteorder.reload@@ -608,22 +611,19 @@ describe 'API V2 Storefront Checkout Spec', type: :request doexpect(json_response['data'][0]).to have_relationships(:shipping_rates)expect(json_response['included']).to be_presentexpect(json_response['included'].size).to eq(shipment.shipping_rates.count + 1)- shipment.shipping_rates.each do |shipping_rate|- expect(json_response['included']).to include(have_type('shipping_rate').and have_id(shipping_rate.id.to_s))- end- expect(json_response['included'][0]).to have_id(shipping_rate.id.to_s)- expect(json_response['included'][0]).to have_type('shipping_rate')- expect(json_response['included'][0]).to have_attribute(:name).with_value(shipping_method.name)- expect(json_response['included'][0]).to have_attribute(:final_price).with_value(shipping_rate.final_price.to_s)- expect(json_response['included'][0]).to have_attribute(:display_final_price).with_value(shipping_rate.display_final_price.to_s)- expect(json_response['included'][0]).to have_attribute(:cost).with_value(shipping_rate.cost.to_s)- expect(json_response['included'][0]).to have_attribute(:display_cost).with_value(shipping_rate.display_cost.to_s)- expect(json_response['included'][0]).to have_attribute(:tax_amount).with_value(shipping_rate.tax_amount.to_s)- expect(json_response['included'][0]).to have_attribute(:display_tax_amount).with_value(shipping_rate.display_tax_amount.to_s)- expect(json_response['included'][0]).to have_attribute(:shipping_method_id).with_value(shipping_method.id)- expect(json_response['included'][0]).to have_attribute(:selected).with_value(shipping_rate.selected)- expect(json_response['included'][0]).to have_attribute(:free).with_value(shipping_rate.free?)-+ [{shipping_method: shipping_method, shipping_rate: shipping_rate}, {shipping_method: shipping_method_2, shipping_rate: shipping_rate_2}].each do |shipping|+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:name).with_value(shipping[:shipping_method].name))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:shipping_method_id).with_value(shipping[:shipping_method].id))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_id(shipping[:shipping_rate].id.to_s))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:cost).with_value(shipping[:shipping_rate].cost.to_s))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:tax_amount).with_value(shipping[:shipping_rate].tax_amount.to_s))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:selected).with_value(shipping[:shipping_rate].selected))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:final_price).with_value(shipping[:shipping_rate].final_price.to_s))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:free).with_value(shipping[:shipping_rate].free?))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:display_final_price).with_value(shipping[:shipping_rate].display_final_price.to_s))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:display_cost).with_value(shipping[:shipping_rate].display_cost.to_s))+ expect(json_response['included']).to include(have_type('shipping_rate').and have_attribute(:display_tax_amount).with_value(shipping[:shipping_rate].display_tax_amount.to_s))+ endexpect(json_response['included']).to include(have_type('stock_location').and have_id(shipment.stock_location_id.to_s))expect(json_response['included']).to include(have_type('stock_location').and have_attribute(:name).with_value(shipment.stock_location.name))end