import assert from 'node:assert/strict' import { describe, it } from 'node:test' import { alignStopProductUnitToContract, allowedPackageSpecsForStopProduct, collectContractProductRows, stopProductUnitLocked } from './pl-plan-contract-product' const hydrochloricAcid = collectContractProductRows([ { id: 'line-hcl', productId: 'hcl', productName: '工业盐酸', packageSpecs: ['25kg/桶', '吨桶'] }, { id: 'line-other', productId: 'hcl', productName: '工业盐酸', packageSpec: '槽车' } ]) describe('allowedPackageSpecsForStopProduct', () => { it('keeps every package on the bound contract line after rows are split by spec', () => { assert.deepEqual( allowedPackageSpecsForStopProduct(hydrochloricAcid, { productId: 'hcl', contractProductId: 'line-hcl' }), ['25kg/桶', '吨桶'] ) }) it('does not include another line of the same product', () => { assert.deepEqual( allowedPackageSpecsForStopProduct(hydrochloricAcid, { productId: 'hcl', contractProductId: 'line-other' }), ['槽车'] ) }) it('uses all specs of the product when the stop row is not bound', () => { assert.deepEqual( allowedPackageSpecsForStopProduct(hydrochloricAcid, { productId: 'hcl' }), ['25kg/桶', '吨桶', '槽车'] ) }) }) describe('stop product unit from contract', () => { const lines = [ { id: 'line-1', productId: 'acid', unit: '吨' }, { id: 'line-1', productId: 'acid', unit: '' } ] it('locks the unit only after a contract line is bound', () => { assert.equal(stopProductUnitLocked({ contractProductId: '' }), false) assert.equal(stopProductUnitLocked({ contractProductId: 'line-1' }), true) }) it('rewrites a different unit to the contract unit', () => { const row = { contractProductId: 'line-1', unit: 'kg' } assert.equal(alignStopProductUnitToContract(row, lines), true) assert.equal(row.unit, 'dun') }) it('treats 吨 and dun as the same unit', () => { const row = { contractProductId: 'line-1', unit: 'dun' } assert.equal(alignStopProductUnitToContract(row, lines), false) assert.equal(row.unit, 'dun') }) it('leaves an unbound row unit unchanged', () => { const row = { contractProductId: '', unit: 'kg' } assert.equal(alignStopProductUnitToContract(row, lines), false) assert.equal(row.unit, 'kg') }) })