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.

Fix: specs and the seller panel starter for the typed preferences contract

Damian Legawiecbd7c51ea7cff
diff --git a/packages/seller-dashboard-starter/package.json b/packages/seller-dashboard-starter/package.json
index 06c6cb2718..f68a04ebfb 100644
--- a/packages/seller-dashboard-starter/package.json
+++ b/packages/seller-dashboard-starter/package.json
@@ -18,6 +18,7 @@
"dependencies": {
"@spree/admin-sdk": "workspace:^",
"@spree/seller-dashboard": "workspace:^",
+ "@spree/admin-sdk": "workspace:^",
"@spree/dashboard-core": "workspace:^",
"@spree/dashboard-ui": "workspace:^",
"@spree/seller-sdk": "workspace:^",
diff --git a/spree/core/spec/models/spree/delivery_method_rule_spec.rb b/spree/core/spec/models/spree/delivery_method_rule_spec.rb
index d55e5162f4..4104dca49d 100644
--- a/spree/core/spec/models/spree/delivery_method_rule_spec.rb
+++ b/spree/core/spec/models/spree/delivery_method_rule_spec.rb
@@ -226,7 +226,7 @@ describe Spree::DeliveryMethodRule, type: :model do
describe 'Spree::DeliveryMethod#rules=' do
it 'creates rules alongside a new method in one save' do
method = Spree::DeliveryMethod.new(name: 'Express', store: store)
- method.rules = [{ type: 'item_total_rule', preferences: { minimum_amount: 50 } }]
+ method.rules = [{ type: 'item_total_rule', preferences: { minimum_amount: '50' } }]
method.save!
expect(method.delivery_method_rules.reload.sole.preferred_minimum_amount).to eq(50)
@@ -238,8 +238,8 @@ describe Spree::DeliveryMethodRule, type: :model do
)
delivery_method.rules = [
- { id: existing.prefixed_id, type: 'item_total_rule', preferences: { minimum_amount: 99 } },
- { type: 'weight_rule', preferences: { maximum_weight: 5 } }
+ { id: existing.prefixed_id, type: 'item_total_rule', preferences: { minimum_amount: '99' } },
+ { type: 'weight_rule', preferences: { maximum_weight: '5' } }
]
delivery_method.save!
diff --git a/spree/core/spec/models/spree/order_routing_rule_spec.rb b/spree/core/spec/models/spree/order_routing_rule_spec.rb
index 3dbec5f632..1072995ff6 100644
--- a/spree/core/spec/models/spree/order_routing_rule_spec.rb
+++ b/spree/core/spec/models/spree/order_routing_rule_spec.rb
@@ -67,7 +67,7 @@ RSpec.describe Spree::OrderRoutingRule, type: :model do
expect(entry[:label]).to eq('Default location')
expect(entry[:description]).to be_present
- expect(entry[:preference_schema]).to eq([])
+ expect(entry[:schema]).to include('type' => 'object', 'properties' => {})
end
end
diff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rb
index 4e969fd500..90815606ac 100644
--- a/spree/core/spec/models/spree/payment_method_spec.rb
+++ b/spree/core/spec/models/spree/payment_method_spec.rb
@@ -472,8 +472,9 @@ describe Spree::PaymentMethod, type: :model do
# Describing a class needs a connection, so the schema can be asked for
# before there is one — at boot, or in a rake task on an empty database.
- # Settling on the empty answer would leave that class describing no
- # preferences for the life of the process.
+ # The preferences are still described, from the declarations alone, but
+ # settling on that answer would leave out every default the database holds
+ # for the life of the process.
describe 'a schema asked for before the database was up' do
let(:gateway_class) do
Class.new(Spree::Gateway) do
@@ -485,11 +486,13 @@ describe Spree::PaymentMethod, type: :model do
it 'is retried rather than settled on' do
allow(gateway_class).to receive(:new).and_raise(ActiveRecord::ConnectionNotEstablished)
- expect(gateway_class.preference_schema).to be_empty
+ expect(gateway_class.preference_schema.map { |field| field[:key] }).to eq([:api_key])
+ expect(gateway_class.instance_variable_get(:@preference_schema)).to be_nil
allow(gateway_class).to receive(:new).and_call_original
expect(gateway_class.preference_schema.map { |field| field[:key] }).to eq([:api_key])
+ expect(gateway_class.instance_variable_get(:@preference_schema)).to be_present
end
# These memoize off the schema, so caching what they derived from its
diff --git a/spree/core/spec/models/spree/promotion_spec.rb b/spree/core/spec/models/spree/promotion_spec.rb
index 98ec93b352..1569c9d842 100644
--- a/spree/core/spec/models/spree/promotion_spec.rb
+++ b/spree/core/spec/models/spree/promotion_spec.rb
@@ -953,7 +953,7 @@ describe Spree::Promotion, type: :model do
let(:category) { create(:category) }
it 'builds a rule from a {type, preferences} hash' do
- promotion.rules = [{ type: 'item_total', preferences: { amount_min: 50 } }]
+ promotion.rules = [{ type: 'item_total', preferences: { amount_min: '50' } }]
promotion.reload
expect(promotion.rules.size).to eq(1)
@@ -964,7 +964,7 @@ describe Spree::Promotion, type: :model do
it 'updates an existing rule when matched by id' do
existing = promotion.rules.create!(type: 'Spree::Promotion::Rules::ItemTotal', preferences: { amount_min: 10 })
- promotion.rules = [{ id: existing.id, type: 'item_total', preferences: { amount_min: 99 } }]
+ promotion.rules = [{ id: existing.id, type: 'item_total', preferences: { amount_min: '99' } }]
promotion.reload
expect(promotion.rules.size).to eq(1)
@@ -1059,7 +1059,7 @@ describe Spree::Promotion, type: :model do
it 'defers application until after_save on a new promotion record' do
promotion = build(:promotion)
- promotion.rules = [{ type: 'item_total', preferences: { amount_min: 25 } }]
+ promotion.rules = [{ type: 'item_total', preferences: { amount_min: '25' } }]
expect(promotion).to be_pending_rules_or_actions
expect(promotion.rules).to be_empty
@@ -1094,7 +1094,7 @@ describe Spree::Promotion, type: :model do
type: 'create_adjustment',
calculator: {
type: 'flat_rate',
- preferences: { amount: 7.5, currency: 'USD' }
+ preferences: { amount: '7.5', currency: 'USD' }
}
}]
promotion.reload
@@ -1115,7 +1115,7 @@ describe Spree::Promotion, type: :model do
promotion.actions = [{
id: action.id,
type: 'create_adjustment',
- calculator: { type: 'flat_percent_item_total', preferences: { flat_percent: 15 } }
+ calculator: { type: 'flat_percent_item_total', preferences: { flat_percent: '15' } }
}]
promotion.reload
diff --git a/spree/core/spec/models/spree/stock/estimator_spec.rb b/spree/core/spec/models/spree/stock/estimator_spec.rb
index 69e9954f1c..5cb3d09491 100644
--- a/spree/core/spec/models/spree/stock/estimator_spec.rb
+++ b/spree/core/spec/models/spree/stock/estimator_spec.rb
@@ -328,7 +328,7 @@ module Spree
retail = create(:channel, store: @default_store, name: "Retail #{SecureRandom.hex(3)}")
wholesale_rate = create(:delivery_method, store: @default_store, name: 'Wholesale Rate')
- wholesale_rate.rules = [{ type: 'channel_rule', preferences: { channel_ids: [wholesale.id] } }]
+ wholesale_rate.rules = [{ type: 'channel_rule', preferences: { channel_ids: [wholesale.prefixed_id] } }]
wholesale_rate.save!
wholesale_order = create(:order_with_line_items, store: @default_store, channel: wholesale)