// The shared cart rules (plan step 6.9); the counter's own cases are in terminal/tests/pos.test.mjs. import { test } from 'node:test' import assert from 'node:assert/strict' import { defaultSelection, missingChoices, needsChoices, toLine } from '../src/cart.js' const burger = { id: 1, unit_type: 'piece', quick: [{ id: 5, name: 'Cheese', price: 1 }], options: [], ingredients: [{ id: 9, name: 'Onion' }], prefs: [{ id: 3, name: 'Cooking', default_choice_id: null, multi: false, shared: null, choices: [{ id: 7, name: 'Rare', subs: [] }] }], } test('a product with a preference to pick needs the dialog; the line holds ids only', () => { assert.equal(needsChoices(burger), true) const sel = defaultSelection(burger) assert.deepEqual(missingChoices(burger, sel).map(m => m.name), ['Cooking']) sel.prefs[3] = { choices: [{ id: 7, qty: 1 }] } sel.quick[5] = 2 sel.removed = [9] assert.deepEqual(missingChoices(burger, sel), []) const line = toLine(burger, sel, 1) assert.equal(line.product_id, 1) assert.equal('unit_price' in line, false) assert.deepEqual(line.removed, [9]) }) test('search: the stored name or its text in any language (6R.L)', async () => { const { searchProducts } = await import('../src/cart.js') const list = [ { id: 1, name: 'Πίτα γύρος', translations: { el: { name: 'Πίτα γύρος' }, en: { name: 'Gyros pita' } } }, { id: 2, name: 'Freddo', translations: {} }, ] assert.deepEqual(searchProducts(list, 'gyros').map(p => p.id), [1]) assert.deepEqual(searchProducts(list, 'γυρος πιτα').map(p => p.id), [1]) assert.deepEqual(searchProducts(list, 'fred').map(p => p.id), [2]) assert.deepEqual(searchProducts(list, 'gyros fred').map(p => p.id), []) })