import test from 'node:test' import assert from 'node:assert/strict' import { defaultPackingBoxes, packingBoxPayload, validPackingAllocation } from '../src/utils/return-packing-allocation.js' const measured = box => ({ ...box, length: '20', width: '30', height: '40', weight: '5' }) test('default one box per SKU preserves all planned quantities', () => { const boxes = defaultPackingBoxes([{ skuCode: 'A', quantity: 7 }, { skuCode: 'B', quantity: 3 }, { skuCode: 'C', quantity: 0 }]).map(measured) assert.equal(boxes.length, 2) assert.equal(validPackingAllocation(boxes, { A: 7, B: 3 }), true) assert.deepEqual(packingBoxPayload(boxes[0]).items, [{ skuCode: 'A', quantity: 7 }]) }) test('split and mixed boxes must equal the complete locked plan', () => { const boxes = [measured({ quantities: { A: 2, B: 3 } }), measured({ quantities: { A: 5 } })] assert.equal(validPackingAllocation(boxes, { A: 7, B: 3 }), true) assert.equal(validPackingAllocation(boxes, { A: 8, B: 3 }), false) assert.equal(validPackingAllocation(boxes, { A: 6, B: 3 }), false) assert.equal(validPackingAllocation(boxes, { A: 7 }), false) }) test('empty boxes, decimal quantities and invalid measurements block completion', () => { assert.equal(validPackingAllocation([], { A: 1 }), false) assert.equal(validPackingAllocation([measured({ quantities: {} })], {}), false) assert.equal(validPackingAllocation([measured({ quantities: { A: 1.5 } })], { A: 1.5 }), false) assert.equal(validPackingAllocation([{ ...measured({ quantities: { A: 1 } }), weight: '0' }], { A: 1 }), false) })