Files
xenia-pos-local/waiter_pwa/tests/priceRules.test.mjs
bonaminandClaude Opus 5.5 0a353c5f97 feat(backend,waiter,manager): moves between tables and orders on the record
Owner 2026-11-23 (plan 6F.4). services/moves.py: every table transfer, lines moved and orders merged
is an order_moves row with its lines (order_move_items: line, quantity then); OrderItem.split_from_id
links a split part to its line, so a part carries the moves made before the split; combining moves
the removed lines' moves to the kept one. Alembic 0048: the tables, the column, and a backfill from
the audit notes written before (note='backfill'). A split part now also keeps the line's price change,
kitchen state, course, cost and names (it used to restart as pending at the menu price).
GET /api/orders/{id}/moves (the order's path, each line's); GET /api/reports/moves (+ export).
Waiter: a moved order's banner (T2 -> T5), moved lines marked, a line's Move history. Manager: the
order's Moves tab, each moved line's path, Reports -> Moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 08:03:11 +02:00

35 lines
2.0 KiB
JavaScript

import assert from 'node:assert/strict'
import { test } from 'node:test'
import { priceRules } from '../src/logic/priceRules.js'
const set = o => Object.fromEntries(Object.entries(o).map(([k, value]) => [k, { value }]))
test('the venue rules for prices changed by hand (6F.3)', () => {
assert.deepEqual(priceRules(null), { mode: 'anytime', inCart: true, afterSending: true, reasonRequired: false, reasons: [] })
const off = priceRules(set({ 'orders.price_change': 'off' }))
assert.equal(off.inCart, false); assert.equal(off.afterSending, false)
const cart = priceRules(set({ 'orders.price_change': 'before_sending', 'orders.price_change_reason': 'true' }))
assert.equal(cart.inCart, true); assert.equal(cart.afterSending, false); assert.equal(cart.reasonRequired, true)
assert.deepEqual(priceRules(set({ 'orders.price_change_reasons': '[" Friend ", "", 3]' })).reasons, ['Friend'])
assert.deepEqual(priceRules(set({ 'orders.price_change_reasons': 'not json' })).reasons, [])
assert.equal(priceRules(set({ 'orders.price_change': 'weird' })).mode, 'anytime')
})
test('the reason sent: a quick reason, a typed one, or none', async () => {
const { priceReasonText } = await import('../src/logic/priceRules.js')
const t = k => `T:${k}`
const builtIn = priceRules(null)
assert.equal(priceReasonText(builtIn, t, { choice: 'regular', other: '' }), 'T:price.reasons.regular')
assert.equal(priceReasonText(builtIn, t, { choice: 'other', other: ' burnt ' }), 'burnt')
assert.equal(priceReasonText(builtIn, t, { choice: '', other: 'x' }), '')
const own = priceRules(set({ 'orders.price_change_reasons': '["Friend"]' }))
assert.equal(priceReasonText(own, t, { choice: 'v0' }), 'Friend')
})
test('a moved order\'s path (6F.4)', async () => {
const { pathText } = await import('../src/logic/moves.js')
assert.equal(pathText([]), '')
assert.equal(pathText([{ from_table: 'T2', to_table: 'T5' }, { from_table: 'T5', to_table: 'T7' }]), 'T2 → T5 → T7')
assert.equal(pathText([{ from_table: null, to_table: 'T1' }]), '— → T1')
})