import test from 'node:test'; import assert from 'node:assert/strict'; import {preparationBlockers,documentKey,HEALTH_CHECKS,documentRevision,documentLinkProblem} from '../src/services/preparationChecks.js'; const rows=[{priceKey:'kit1',name:'Kit'}]; const docs=[{document:'Yetki belgesi',mandatory:true,note:'Şartname 7.1'}]; const complete=()=>({documents:{[documentKey(docs[0])]:{status:'verified',evidence:'Yetki v2, süre kontrol edildi, 7.1'}},products:{kit1:{product:'QA model',source:'Teknik 3.2, katalog s4',status:'suitable',...Object.fromEntries(HEALTH_CHECKS.map(([key])=>[key,{status:'notApplicable',evidence:'Doküman ilgili maddesi kapsamında uygulanmıyor'}]))}}}); test('priced rows without document and health review remain incomplete',()=>{ assert.ok(preparationBlockers(rows,[],{}).length>=6); assert.equal(preparationBlockers(rows,docs,complete()).length,0); }); test('unsuitable product, missing evidence and mandatory document exemption block readiness',()=>{ const c=complete();c.products.kit1.status='unsuitable';assert.ok(preparationBlockers(rows,docs,c).some(x=>x.includes('uygun değil'))); c.products.kit1.status='suitable';c.products.kit1.uts.evidence=' ';assert.ok(preparationBlockers(rows,docs,c).some(x=>x.includes('ÜTS'))); c.documents[documentKey(docs[0])].status='notApplicable';assert.ok(preparationBlockers(rows,docs,c).some(x=>x.includes('Yetki'))); }); test('changed requirement and changed product row require new checks',()=>{ assert.ok(preparationBlockers(rows,[{...docs[0],note:'Zeyilname 2'}],complete()).length>0); assert.ok(preparationBlockers([{...rows[0],priceKey:'kit2'}],docs,complete()).length>0); }); test('linked file must exist, match reviewed metadata and remain valid at tender deadline',()=>{ const file={id:'f1',tur:'firma',olusturma:'2026-09-01',boyut:100,son_kullanma:'2026-09-10',erisilebilir:true}; const c={documentId:file.id,documentRevision:documentRevision(file)}; assert.equal(documentLinkProblem(c,[file],'2026-09-10'),null); assert.ok(documentLinkProblem(c,[],'2026-09-10')); assert.ok(documentLinkProblem(c,[{...file,erisilebilir:false}],'2026-09-10')); assert.ok(documentLinkProblem(c,[{...file,boyut:101}],'2026-09-10')); assert.ok(documentLinkProblem(c,[file],'2026-09-11')); const invalid={...file,son_kullanma:'2026-02-31'}; assert.ok(documentLinkProblem({...c,documentRevision:documentRevision(invalid)},[invalid],'2026-01-01')); }); test('another tender document cannot satisfy preparation but company documents remain reusable',()=>{ const file={id:'doc1',tur:'ihale',ikn:'2026/111',olusturma:'2026-09-01',boyut:20}; const check={documentId:file.id,documentRevision:documentRevision(file)}; assert.match(documentLinkProblem(check,[file],'2026-09-10','2026/222'),/mevcut ihaleye bağlı değil/); assert.equal(documentLinkProblem(check,[file],'2026-09-10','2026/111'),null); const company={...file,tur:'firma',ikn:null}; assert.equal(documentLinkProblem({...check,documentRevision:documentRevision(company)},[company],'2026-09-10','2026/222'),null); const c=complete();c.documents[documentKey(docs[0])]={...c.documents[documentKey(docs[0])],...check}; assert.ok(preparationBlockers(rows,docs,c,{documents:[file],deadlineDate:'2026-09-10',tenderIkn:'2026/222'}).some(e=>e.includes('mevcut ihaleye bağlı değil'))); }); test('classification or tender-link changes invalidate the previous review',()=>{ const file={id:'doc1',tur:'firma',ikn:null,olusturma:'2026-09-01',boyut:20}; const check={documentId:file.id,documentRevision:documentRevision(file)}; assert.match(documentLinkProblem(check,[{...file,tur:'ihale',ikn:'2026/111'}],'2026-09-10','2026/111'),/yeniden seçip/); assert.match(documentLinkProblem(check,[{...file,tur:undefined}],'2026-09-10','2026/111'),/Belge türü/); });