Files
xenia-pos-local/waiter_pwa/tests/lines.test.mjs
T
bonaminandClaude Opus 5.5 72e175ab73 feat(backend,waiter,terminal,manager): +1 on a sent line and changing a line's quantity
Owner 2026-11-23 (plan 6F.5). Product flag one_more_enabled (off by default; product editor).
POST /api/orders/{id}/items/{item}/again: a new line like the old one (choices, removed, note,
course), priced now, sent to the kitchen like any new line. Waiter app and the counter's table
panel: +1 beside such lines; the first tap arms it, more taps count up, 'Send +N' sends, 4 s idle
disarms (no stray sends).
POST /api/orders/{id}/items/{item}/quantity: venue setting orders.quantity_change (off | add_only |
add_and_remove, default off), key ordering.items.change_quantity (owner, store manager; Alembic 0049
grants it); up only changes the line, down cuts a cancelled part ('quantity lowered', split_from_id)
and prints a cancellation only when asked (the dialog presets yes while the kitchen hasn't finished).
Waiter: 'Change quantity' in a line's actions (now -> new, -/+). cut_part() now shared with split.
GET /api/orders/{id} items carry the product's one_more_enabled / unit_type, deal ids, split_from_id,
cancel_reason.

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

31 lines
1.7 KiB
JavaScript

import assert from 'node:assert/strict'
import { test } from 'node:test'
import { cancelByDefault, canChangeQuantity, canOneMore, lowestQuantity, quantityMode } from '../src/logic/lines.js'
const beer = (o = {}) => ({ status: 'active', quantity: 3, unit_type: 'piece', product: { one_more_enabled: true }, kds_status: 'pending', ...o })
test('one more: the product allows it, pieces, a line still there (6F.5)', () => {
assert.equal(canOneMore(beer()), true)
assert.equal(canOneMore(beer({ status: 'paid' })), true)
assert.equal(canOneMore(beer({ status: 'cancelled' })), false)
assert.equal(canOneMore(beer({ product: { one_more_enabled: false } })), false)
assert.equal(canOneMore(beer({ unit_type: 'kg' })), false)
assert.equal(canOneMore(beer({ deal_id: 4 })), false)
})
test('changing a quantity: the venue, unpaid whole pieces; how low; the ticket question', () => {
const s = v => ({ 'orders.quantity_change': { value: v } })
assert.equal(quantityMode(null), 'off')
assert.equal(quantityMode(s('add_only')), 'add_only')
assert.equal(quantityMode(s('nonsense')), 'off')
assert.equal(canChangeQuantity(beer(), 'off'), false)
assert.equal(canChangeQuantity(beer(), 'add_only'), true)
assert.equal(canChangeQuantity(beer({ status: 'paid' }), 'add_and_remove'), false)
assert.equal(canChangeQuantity(beer({ quantity: 1.5 }), 'add_and_remove'), false)
assert.equal(lowestQuantity(beer(), 'add_only'), 3)
assert.equal(lowestQuantity(beer(), 'add_and_remove'), 1)
assert.equal(cancelByDefault(beer({ kds_status: 'preparing' })), true)
assert.equal(cancelByDefault(beer({ kds_status: 'served' })), false)
assert.equal(cancelByDefault(beer({ kds_status: 'done' })), false)
})