Persist observed tender source revisions and expose paginated history

This commit is contained in:
2026-09-06 10:49:30 +03:00
parent a0f4824c7e
commit 68fe84e9c7
9 changed files with 166 additions and 0 deletions
+8
View File
@@ -172,3 +172,11 @@ test('concurrent API key requests never exceed quota and malformed input creates
assert.equal((await request('/api/me/apikeys','POST',{ad:'replacement'},auth)).status,200);
assert.equal((await request('/api/me/apikeys','PUT',{},auth)).status,405);
});
test('source history requires authentication and distinguishes empty results from invalid pagination',async()=>{
assert.equal((await request('/api/tenders/source-history?ikn=2026/123','GET',null,null)).status,401);
const response=await request('/api/tenders/source-history?ikn=2026/123');
assert.equal(response.status,200);assert.deepEqual(response.data.records,[]);assert.equal(response.data.nextCursor,null);
assert.equal((await request('/api/tenders/source-history?ikn=2026/123&before=bad')).status,400);
assert.equal((await request('/api/tenders/source-history?ikn=2026/123','POST',{})).status,405);
});
+29
View File
@@ -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));
});