fix: invalidate preparation approval for changed portfolio products

This commit is contained in:
2026-09-06 13:52:40 +03:00
parent 52fdb5fe17
commit 36859188bf
7 changed files with 72 additions and 7 deletions
+28
View File
@@ -10,3 +10,31 @@ test('portfolio selection preserves declaration snapshot without approving tende
for(const [key] of HEALTH_CHECKS)assert.deepEqual(check[key],{status:'pending',evidence:''});
const manual=selectPortfolioProduct(null);assert.equal(manual.portfolioId,null);assert.equal(manual.portfolioSnapshot,null);
});
test('portfolio revisions reject changed, missing and ambiguous declarations',async()=>{
const {portfolioSelectionProblem}=await import('../src/services/portfolioRevision.js');
const item={id:'device',group:'Analiz',brand:'QA',model:'M1',kind:'device',utsStatus:'declared',utsReference:'TEST',serviceCapacity:'2 uzman'};
const check=selectPortfolioProduct(item);
assert.equal(portfolioSelectionProblem(check,[{...item,updatedAt:'later'}]),null);
for(const key of ['group','brand','model','kind','utsStatus','utsReference','serviceCapacity'])
assert.match(portfolioSelectionProblem(check,[{...item,[key]:'changed'}]),/değişti/,key);
assert.match(portfolioSelectionProblem(check,[]),/kaldırılmış/);
assert.match(portfolioSelectionProblem(check,[item,item]),/belirsiz/);
assert.match(portfolioSelectionProblem(check,undefined),/doğrulanamadı/);
assert.match(portfolioSelectionProblem({...check,portfolioSnapshot:null},[item]),/değişti/);
assert.equal(portfolioSelectionProblem(selectPortfolioProduct(null),undefined),null);
});
test('fully approved product is blocked when its portfolio changes; reselecting requires new evidence',async()=>{
const {preparationBlockers}=await import('../src/services/preparationChecks.js');
const item={id:'kit',group:'Test kiti',model:'M1',kind:'consumable'};
const approved={...selectPortfolioProduct(item),status:'suitable',source:'Teknik madde 2',
...Object.fromEntries(HEALTH_CHECKS.map(([key])=>[key,{status:'verified',evidence:'Kontrol belgesi 1'}]))};
const rows=[{priceKey:'p1',name:'Kit'}],documents=[{document:'İsteğe bağlı',mandatory:false}];
const checks={products:{p1:approved},documents:{'["İsteğe bağlı",false,""]':{status:'notApplicable',evidence:'Şartname 4'}}};
assert.deepEqual(preparationBlockers(rows,documents,checks,{healthPortfolio:[item]}),[]);
const changed={...item,model:'M2'};
assert.ok(preparationBlockers(rows,documents,checks,{healthPortfolio:[changed]}).some(e=>e.includes('değişti')));
const refreshed={...checks,products:{p1:selectPortfolioProduct(changed)}};
const errors=preparationBlockers(rows,documents,refreshed,{healthPortfolio:[changed]});
assert.equal(errors.length,5);assert.ok(errors.every(e=>!e.includes('değişti')));
});