Files
ihaleist/tests/source-requirements.test.mjs
T

28 lines
1.8 KiB
JavaScript
Raw 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 {sourceRequirements} from '../server/source-requirements.mjs';
test('every source character is scanned and late conditions retain exact location and wording',async()=>{
const text='Standart metin ve açıklamalar. '.repeat(500)+'SON ŞART: Cihazların kurulumu 16 ay boyunca firma sorumluluğundadır.';
const parts=[];
const result=await sourceRequirements(text,async part=>{
parts.push(part);
const start=part.text.indexOf('SON ŞART:');
return {requirements:start<0?[]:[{quote:part.text.slice(start)}]};
});
assert.equal(parts.sort((a,b)=>a.index-b.index).map(p=>p.text).join(''),text);
assert.ok(parts.every(p=>p.text.length<=6000));
assert.equal(result.sourceReview.scannedParts,parts.length);
assert.match(result.requirements[0],/16 ay boyunca/);
const row=result.sourceReview.evidence[0];assert.equal(text.slice(row.start,row.end),row.quote);
});
test('fabricated source quotes and failed source parts stop the audit rather than hiding missing coverage',async()=>{
await assert.rejects(sourceRequirements('Kaynakta yalnız 120 gün vardır.',async()=>({requirements:[{quote:'Kaynakta 60 gün vardır.'}]})),/alıntısı doğrulanamadı/);
await assert.rejects(sourceRequirements('Kaynakta yalnız 120 gün vardır.',async()=>({})),/geçerli liste/);
await assert.rejects(sourceRequirements('X'.repeat(14000),async part=>{if(part.index===1)throw new Error('provider error');return {requirements:[]};}),/provider error/);
});
test('source scan cancellation stops later batches',async()=>{
const controller=new AbortController();let calls=0;
await assert.rejects(sourceRequirements('X'.repeat(20000),async()=>{calls++;controller.abort();return {requirements:[]};},{signal:controller.signal}),{name:'AbortError'});
assert.ok(calls<=2);
});