// Printing problems as plain data (plan step 6.10). import { test } from 'node:test' import assert from 'node:assert/strict' import { actionRequest, byPrinter, itemsText, minutesSince, otherPrinters, placeOf, problemsOf } from '../src/printProblems.js' const p = (job, order, printer, extra = {}) => ({ job_id: job, order_id: order, table_name: null, printer: { id: printer, name: `P${printer}` }, items: [{ name: 'Burger', quantity: 2, unit_type: 'piece' }, { name: 'Freddo', quantity: 1, unit_type: 'piece' }], since: '2026-11-19T10:00:00', ...extra, }) test('what a ticket holds, where it belongs, how long it waits', () => { const a = p(1, 7, 1, { table_name: 'T5' }) assert.equal(itemsText(a), '2× Burger, Freddo') assert.equal(placeOf(a), 'T5') assert.equal(placeOf(p(2, 8, 1)), '#8') assert.equal(minutesSince(a, Date.parse('2026-11-19T10:07:30Z')), 7) // a time without a zone is UTC assert.equal(minutesSince({ ...a, since: '2026-11-19T10:00:00+02:00' }, Date.parse('2026-11-19T08:03:00Z')), 3) }) test('per order, per printer, the printers to send to, the requests', () => { const list = [p(1, 7, 1), p(2, 7, 2), p(3, 8, 1)] assert.deepEqual(problemsOf(list, 7).map(x => x.job_id), [1, 2]) assert.deepEqual(byPrinter(list).map(x => [x.printer.id, x.count]), [[1, 2], [2, 1]]) assert.deepEqual(otherPrinters(list[0], [{ id: 1 }, { id: 2 }, { id: 3 }]).map(x => x.id), [2, 3]) assert.deepEqual(actionRequest('redirect', list[0], 3), ['/api/print-problems/1/redirect', { printer_id: 3 }]) assert.deepEqual(actionRequest('handled', list[0]), ['/api/print-problems/1/handled', {}]) assert.deepEqual(actionRequest('retry', list[0]), ['/api/print-problems/1/retry', {}]) })