import test from 'node:test'; import assert from 'node:assert/strict'; import {sourceRows,bidSourceSnapshot,restoreBidPrices} from '../src/services/bidSource.js'; const tender = {ikn:'2026/test',aciklama:'120 gün',items:[{id:1,ad:'Kit',miktar:10,birim:'adet'},{id:2,ad:'Cihaz',miktar:2,birim:'adet'}]}; test('reordered source rows retain their own prices without invalidating identical content',()=>{ const original=sourceRows(tender); const draft={priceSchema:1,pricesBySource:{[original[0].priceKey]:'15',[original[1].priceKey]:'900'}}; const reordered={...tender,items:[...tender.items].reverse()}; const rows=sourceRows(reordered),prices=restoreBidPrices(draft); assert.equal(prices[rows[0].priceKey],'900'); assert.equal(prices[rows[1].priceKey],'15'); assert.equal(bidSourceSnapshot(tender),bidSourceSnapshot(reordered)); }); test('changed quantity, requirements and announcement invalidate reviewed source',()=>{ const original=sourceRows(tender),prices={[original[0].priceKey]:'15'}; const changed={...tender,items:[{...tender.items[0],miktar:20},tender.items[1]]}; assert.equal(prices[sourceRows(changed)[0].priceKey],undefined); const snapshot=bidSourceSnapshot(tender); for(const updated of [changed,{...tender,aciklama:'150 gün'},{...tender,saat:'10:30'}]) assert.notEqual(snapshot,bidSourceSnapshot(updated)); assert.notEqual(snapshot,bidSourceSnapshot(tender,{documentChecklist:['Numune']})); }); test('legacy positional prices are not silently assigned to potentially changed source rows',()=>{ assert.deepEqual(restoreBidPrices({fiyatlar:{0:'15',1:'900'}}),{}); });