const { findBestMaterialMatch, scoreCandidate } = require('../src/services/smartPackageMaterialMatchService'); describe('smartPackageMaterialMatchService', () => { const catalog = [ { id: 10, sku: 'TAG-001', name: 'Taglægte 38x73 mm C24', unit: 'lbm', price: 14.5 }, { id: 11, sku: 'ISO-200', name: 'Mineraluld 200 mm', unit: 'm²', price: 135 }, { id: 12, sku: 'TAG-002', name: 'Taglægte 25x50 mm', unit: 'lbm', price: 9.5 } ]; test('prefers an exact master material SKU', () => { const match = findBestMaterialMatch({ name: 'Andet navn', itemCode: 'TAG-001' }, catalog); expect(match).toMatchObject({ status: 'matched_sku', score: 1 }); expect(match.material.id).toBe(10); }); test('matches a descriptive package line to the master material', () => { const match = findBestMaterialMatch({ name: 'Mineraluld 200mm', unit: 'm²' }, catalog, { minimumMargin: 0 }); expect(match.material.id).toBe(11); expect(match.status).toBe('matched_name'); }); test('scores a dimensionally matching name above a generic alternative', () => { const line = { name: 'Taglægte 38x73 mm', unit: 'lbm' }; expect(scoreCandidate(line, catalog[0])).toBeGreaterThan(scoreCandidate(line, catalog[2])); }); });