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.

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.yaml
index 2c580c14be..e9044cefbe 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -23778,7 +23778,7 @@ paths:
preference_schema:
- key: amount_min
type: decimal
- default: 100.0
+ default: '100'
- key: operator_min
type: string
default: ">"
@@ -35326,7 +35326,7 @@ paths:
preference_schema:
- key: flat_percent
type: decimal
- default: 0
+ default: '0'
- type: flat_rate
name: Flat rate
preference_schema:
@@ -35335,7 +35335,7 @@ paths:
default: {}
- key: amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
@@ -35344,10 +35344,10 @@ paths:
preference_schema:
- key: first_item
type: decimal
- default: 0.0
+ default: '0'
- key: additional_item
type: decimal
- default: 0.0
+ default: '0'
- key: max_items
type: integer
default: 0
@@ -35362,7 +35362,7 @@ paths:
default: {}
- key: amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
@@ -35371,13 +35371,13 @@ paths:
preference_schema:
- key: minimal_amount
type: decimal
- default: 0
+ default: '0'
- key: normal_amount
type: decimal
- default: 0
+ default: '0'
- key: discount_amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
@@ -35389,7 +35389,7 @@ paths:
default: {}
- key: amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
diff --git a/docs/api-reference/seller.yaml b/docs/api-reference/seller.yaml
index ff8593e2af..013649bcce 100644
--- a/docs/api-reference/seller.yaml
+++ b/docs/api-reference/seller.yaml
@@ -12854,7 +12854,7 @@ paths:
preference_schema:
- key: flat_percent
type: decimal
- default: 0
+ default: '0'
- type: flat_rate
name: Flat rate
preference_schema:
@@ -12863,7 +12863,7 @@ paths:
default: {}
- key: amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
@@ -12872,10 +12872,10 @@ paths:
preference_schema:
- key: first_item
type: decimal
- default: 0.0
+ default: '0'
- key: additional_item
type: decimal
- default: 0.0
+ default: '0'
- key: max_items
type: integer
default: 0
@@ -12890,7 +12890,7 @@ paths:
default: {}
- key: amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
@@ -12899,13 +12899,13 @@ paths:
preference_schema:
- key: minimal_amount
type: decimal
- default: 0
+ default: '0'
- key: normal_amount
type: decimal
- default: 0
+ default: '0'
- key: discount_amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
@@ -12917,7 +12917,7 @@ paths:
default: {}
- key: amount
type: decimal
- default: 0
+ default: '0'
- key: currency
type: string
default: USD
diff --git a/packages/dashboard/e2e/catalogs.spec.ts b/packages/dashboard/e2e/catalogs.spec.ts
index 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.ts
index 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.ts
index 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.ts
index 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.ts
index 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.rb
index 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 Spree
wire = { 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.freeze
end.freeze
end
diff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rb
index 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 do
preference :mode, :string, default: 'live', in: %w[test live]
preference :label, :string
+ preference :threshold, :decimal, default: 0
end
end
+ # 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