Files
ihaleist/tests/health-portfolio.test.mjs

41 lines
3.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test';
import assert from 'node:assert/strict';
import {selectPortfolioProduct} from '../src/services/healthPortfolio.js';
import {HEALTH_CHECKS} from '../src/services/preparationChecks.js';
test('portfolio selection preserves declaration snapshot without approving tender requirements',()=>{
const item={id:'device',group:'Analiz',brand:'QA',model:'M1',kind:'device',utsStatus:'declared',utsReference:'TEST',serviceCapacity:'2 uzman'};
const check=selectPortfolioProduct(item);item.model='Changed';
assert.equal(check.portfolioSnapshot.model,'M1');assert.equal(check.product,'Analiz · QA · M1');
assert.equal(check.status,'pending');assert.equal(check.source,'');
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')));
});