Persist observed tender source revisions and expose paginated history
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import test,{after} from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {mkdtempSync,rmSync} from 'node:fs';
|
||||
import {join} from 'node:path';
|
||||
import {tmpdir} from 'node:os';
|
||||
const root=mkdtempSync(join(tmpdir(),'ihaleist-history-'));
|
||||
process.env.IHALEIST_SHARED_DATA_DIR=root;
|
||||
const {observeTenders,tenderHistory}=await import('../server/tender-history.mjs');
|
||||
after(()=>rmSync(root,{recursive:true,force:true}));
|
||||
test('source observations persist changes, ignore identical reloads, and retain reversions',()=>{
|
||||
const t={id:'ilan-1',ikn:'2026/100',kurum:'A',tarih:'10.09.2026',saat:'10:00',aciklama:'Tam ilan metni'};
|
||||
observeTenders([t]);observeTenders([{...t,notes:['private'],aciklama:undefined}]);
|
||||
assert.equal(tenderHistory(t).records.length,1);
|
||||
observeTenders([{...t,saat:'11:00'}]);observeTenders([t]);
|
||||
const history=tenderHistory(t,{limit:2});
|
||||
assert.equal(history.records.length,2);assert.ok(history.nextCursor);
|
||||
assert.deepEqual(history.records[0].changes,[{field:'saat',before:'11:00',after:'10:00'}]);
|
||||
assert.equal(tenderHistory(t,{before:history.nextCursor}).records.length,1);
|
||||
});
|
||||
test('different sources and institutional DT identifiers cannot overwrite one another',()=>{
|
||||
const a={id:'dt-1',ikn:'26DT123',kurum:'A',durum:'Açık'};
|
||||
const b={...a,kurum:'B',durum:'İptal'};
|
||||
observeTenders([a,b]);assert.equal(tenderHistory(a).records.length,1);
|
||||
assert.equal(tenderHistory(b).records.length,1);
|
||||
const c={id:'ilan-2',ikn:'2026/200',kurum:'A',durum:'Açık'};
|
||||
observeTenders([c,{...c,id:'history-2',durum:'Sonuçlandı'},c]);
|
||||
assert.equal(tenderHistory(c).records.length,2);
|
||||
assert.ok(tenderHistory(c).records.every(r=>r.changes.length===0));
|
||||
});
|
||||
Reference in New Issue
Block a user