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 decimal preference defaults and e2e seeds sent as numbers
Damian Legawiec48c14ae88fb9
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yamlindex 2c580c14be..e9044cefbe 100644--- a/docs/api-reference/admin.yaml+++ b/docs/api-reference/admin.yaml@@ -23778,7 +23778,7 @@ paths:preference_schema:- key: amount_mintype: decimal- default: 100.0+ default: '100'- key: operator_mintype: stringdefault: ">"@@ -35326,7 +35326,7 @@ paths:preference_schema:- key: flat_percenttype: decimal- default: 0+ default: '0'- type: flat_ratename: Flat ratepreference_schema:@@ -35335,7 +35335,7 @@ paths:default: {}- key: amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USD@@ -35344,10 +35344,10 @@ paths:preference_schema:- key: first_itemtype: decimal- default: 0.0+ default: '0'- key: additional_itemtype: decimal- default: 0.0+ default: '0'- key: max_itemstype: integerdefault: 0@@ -35362,7 +35362,7 @@ paths:default: {}- key: amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USD@@ -35371,13 +35371,13 @@ paths:preference_schema:- key: minimal_amounttype: decimal- default: 0+ default: '0'- key: normal_amounttype: decimal- default: 0+ default: '0'- key: discount_amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USD@@ -35389,7 +35389,7 @@ paths:default: {}- key: amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USDdiff --git a/docs/api-reference/seller.yaml b/docs/api-reference/seller.yamlindex ff8593e2af..013649bcce 100644--- a/docs/api-reference/seller.yaml+++ b/docs/api-reference/seller.yaml@@ -12854,7 +12854,7 @@ paths:preference_schema:- key: flat_percenttype: decimal- default: 0+ default: '0'- type: flat_ratename: Flat ratepreference_schema:@@ -12863,7 +12863,7 @@ paths:default: {}- key: amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USD@@ -12872,10 +12872,10 @@ paths:preference_schema:- key: first_itemtype: decimal- default: 0.0+ default: '0'- key: additional_itemtype: decimal- default: 0.0+ default: '0'- key: max_itemstype: integerdefault: 0@@ -12890,7 +12890,7 @@ paths:default: {}- key: amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USD@@ -12899,13 +12899,13 @@ paths:preference_schema:- key: minimal_amounttype: decimal- default: 0+ default: '0'- key: normal_amounttype: decimal- default: 0+ default: '0'- key: discount_amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USD@@ -12917,7 +12917,7 @@ paths:default: {}- key: amounttype: decimal- default: 0+ default: '0'- key: currencytype: stringdefault: USDdiff --git a/packages/dashboard/e2e/catalogs.spec.ts b/packages/dashboard/e2e/catalogs.spec.tsindex c10c12425c..322503e7db 100644--- a/packages/dashboard/e2e/catalogs.spec.ts+++ b/packages/dashboard/e2e/catalogs.spec.ts@@ -426,7 +426,7 @@ test.describe('catalogs', () => {await saveCatalog(page)await page.reload()- await expect(page.getByLabel(/minimum amount/i)).toHaveValue('500.0', { timeout: 15_000 })+ await expect(page.getByLabel(/minimum amount/i)).toHaveValue('500.00', { timeout: 15_000 })})test('renames a catalog from the header Save', async ({ page }) => {diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.tsindex f7bb881e16..4ffb1f7bca 100644--- a/packages/dashboard/e2e/helpers.ts+++ b/packages/dashboard/e2e/helpers.ts@@ -73,7 +73,7 @@ export async function seedCatalogPickerProducts(const name = `${prefix} ${String(index + 1).padStart(2, '0')}`const res = await page.request.post('/api/v3/admin/products', {headers,- data: { name, status: 'active', price: 9.99 },+ data: { name, status: 'active', price: '9.99' },})if (!res.ok()) {throw new Error(diff --git a/packages/dashboard/e2e/products-translations.spec.ts b/packages/dashboard/e2e/products-translations.spec.tsindex 4cc7942ce4..7307772031 100644--- a/packages/dashboard/e2e/products-translations.spec.ts+++ b/packages/dashboard/e2e/products-translations.spec.ts@@ -22,7 +22,7 @@ async function seedProductWithPlainDescriptionTranslation(}const created = await page.request.post('/api/v3/admin/products', {headers,- data: { name, status: 'active', price: 9.99 },+ data: { name, status: 'active', price: '9.99' },})if (!created.ok()) {throw new Error(`Failed to seed product: ${created.status()} ${await created.text()}`)diff --git a/packages/dashboard/e2e/purchase-orders.spec.ts b/packages/dashboard/e2e/purchase-orders.spec.tsindex 96a1f34226..ee5f01346f 100644--- a/packages/dashboard/e2e/purchase-orders.spec.ts+++ b/packages/dashboard/e2e/purchase-orders.spec.ts@@ -44,7 +44,7 @@ async function createPurchaseOrder(destination_location_id: destination.id,currency: 'USD',reference: `E2E PO ${Date.now()}`,- items: [{ variant_id: variants.data[0].id, quantity_ordered: quantity, unit_cost: 7.5 }],+ items: [{ variant_id: variants.data[0].id, quantity_ordered: quantity, unit_cost: '7.50' }],},})expect(created.status(), await created.text()).toBe(201)diff --git a/packages/dashboard/e2e/store-credits.spec.ts b/packages/dashboard/e2e/store-credits.spec.tsindex a600e37cba..9fa1b3a23d 100644--- a/packages/dashboard/e2e/store-credits.spec.ts+++ b/packages/dashboard/e2e/store-credits.spec.ts@@ -14,7 +14,7 @@ async function issueStoreCredit(page: Page, accessToken: string, memo: string) {.then((res) => res.json())const created = await page.request.post(`/api/v3/admin/customers/${customers.data[0].id}/store_credits`,- { headers, data: { amount: 40, currency: 'USD', memo } },+ { headers, data: { amount: '40.00', currency: 'USD', memo } },)expect(created.status(), await created.text()).toBe(201)}diff --git a/spree/core/app/models/concerns/spree/preference_schema.rb b/spree/core/app/models/concerns/spree/preference_schema.rbindex 2190e73e70..21d3ec6c4c 100644--- a/spree/core/app/models/concerns/spree/preference_schema.rb+++ b/spree/core/app/models/concerns/spree/preference_schema.rb@@ -77,6 +77,8 @@ module Spreewire = { key: field[:key], type: field[:type], default: field[:default] }wire[:choices] = field[:choices] if field[:choices].present?wire[:default] = nil if field[:type] == :password+ # A decimal default goes out as the decimal string the API takes back.+ wire[:default] = Spree::Money::Rounding.format_decimal(field[:default]) if field[:type] == :decimal && field[:default].is_a?(Numeric)wire.freezeend.freezeenddiff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rbindex ca0fa80fbb..abdbf91a17 100644--- a/spree/core/spec/models/spree/payment_method_spec.rb+++ b/spree/core/spec/models/spree/payment_method_spec.rb@@ -377,9 +377,17 @@ describe Spree::PaymentMethod, type: :model dopreference :mode, :string, default: 'live', in: %w[test live]preference :label, :string+ preference :threshold, :decimal, default: 0endend+ # The API refuses a JSON number for a decimal, so it must not hand one out.+ it 'serves a decimal default as a decimal string' do+ field = gateway_class.serialized_preference_schema.find { |entry| entry[:key] == :threshold }++ expect(field[:default]).to eq('0')+ end+# The set is what the server validates against, so a form that does not# know it can only offer a text box the operator gets wrong.it 'carries the set into the schema' do