- Products: the categories and the list as two containers side by side (the tree sticky), the toolbar on the shared controls (search, filters, list/grid, New all one height), archive / delete red in a container. - Product editor: a wide dialog (Dialog size=wide: ~88% of a 16:9 screen, capped on ultrawides), the shared tab strip (no up/down scrollbar), one name and description with a language switch above them, unit (modern dropdown) and price on one row, 'Edit alternate prices' under Where it's sold (the product's own price per sales point: default / set / +- amount / +- %, rounding). - Pricing: shared tabs in the address, a new 'Order channel prices' tab (rules per product, category or sales point, multi-select, the most precise wins). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
2.2 KiB
JavaScript
35 lines
2.2 KiB
JavaScript
// Order channel prices as plain data (2026-11-20): what a rule makes of the default price, what
|
|
// a rule needs, and the product editor's quick edit.
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { applyRule, levelOf, pointRowFromApi, pointsBody, rowPrice, ruleBody, ruleProblems, blankRule } from '../src/pages/pricing/channelPricing.js'
|
|
|
|
test('a rule makes the price there from the default price', () => {
|
|
assert.equal(applyRule(10, { action_type: 'set', value: 8.5 }), 8.5)
|
|
assert.equal(applyRule(10, { action_type: 'add_amount', value: -1.2 }), 8.8)
|
|
assert.equal(applyRule(3, { action_type: 'add_percent', value: 10 }), 3.3)
|
|
assert.equal(applyRule(9.3, { action_type: 'add_percent', value: 0, round_to: '0.50' }), 9.5)
|
|
assert.equal(applyRule(1, { action_type: 'add_amount', value: -5 }), 0)
|
|
assert.equal(levelOf({ product_ids: [1], category_ids: [] }), 'product')
|
|
assert.equal(levelOf({ product_ids: [], category_ids: [2] }), 'category')
|
|
assert.equal(levelOf({ product_ids: [], category_ids: [] }), 'channel')
|
|
})
|
|
|
|
test('what a rule needs: a sales point, a value, a set price for one product', () => {
|
|
const f = blankRule()
|
|
assert.deepEqual(ruleProblems(f), ['points', 'value'])
|
|
assert.deepEqual(ruleProblems({ ...f, sales_points: ['qr_table'], value: '-10' }), [])
|
|
assert.deepEqual(ruleProblems({ ...f, sales_points: ['qr_table'], action_type: 'set', value: '2', category_ids: [3] }), ['set_one'])
|
|
assert.deepEqual(ruleBody({ ...f, sales_points: ['qr_table'], value: '-10,5' }).value, -10.5)
|
|
})
|
|
|
|
test('the product quick edit: default rows send null, own rows their rule; the price shown', () => {
|
|
const rows = [
|
|
pointRowFromApi({ sales_point: 'in_store', base_price: 10, own: null, fallback: null }),
|
|
pointRowFromApi({ sales_point: 'online_delivery', base_price: 10, own: null, fallback: { level: 'channel', action_type: 'add_percent', value: 10, round_to: null } }),
|
|
pointRowFromApi({ sales_point: 'in_store_takeaway', base_price: 10, own: { action_type: 'set', value: 9, round_to: null }, fallback: null }),
|
|
]
|
|
assert.deepEqual(rows.map(rowPrice), [10, 11, 9])
|
|
assert.deepEqual(pointsBody(rows), { in_store: null, online_delivery: null, in_store_takeaway: { action_type: 'set', value: 9, round_to: null } })
|
|
})
|