fix: reject stale company profile and filter updates

This commit is contained in:
2026-09-06 13:58:25 +03:00
parent ae32382ffa
commit 9d3acac59d
8 changed files with 92 additions and 25 deletions
+15 -1
View File
@@ -43,7 +43,8 @@ test('database write failure propagates instead of pretending success', () => {
const db = store.openDb();
db.exec(`CREATE TRIGGER reject_write BEFORE INSERT ON kullanici_verisi BEGIN SELECT RAISE(FAIL,'test write failure'); END;`);
db.close();
assert.throws(() => store.setData('a@example.test','takip',[]), /test write failure/);
try { assert.throws(() => store.setData('a@example.test','takip',[]), /test write failure/); }
finally { const cleanup=store.openDb();cleanup.exec('DROP TRIGGER reject_write');cleanup.close(); }
});
test('per-tender versions prevent stale updates; five tasks persist', () => {
for (const id of ['1573235','1582991','1523851','1499061','1534665']) {
@@ -97,3 +98,16 @@ test('committed deletion remains inaccessible and pending physical cleanup survi
const reopened=store.openDb();assert.equal(reopened.prepare('SELECT COUNT(*) n FROM document_file_cleanup').get().n,0);reopened.close();
assert.equal(existsSync(file),false);
});
test('data revision snapshots preserve legacy records and reject stale changes atomically',()=>{
const owner='revision@example.test',key='firma_profil';
store.setData(owner,key,{company:'Legacy'});
const first=store.getDataSnapshot(owner);
assert.deepEqual(first.veri[key],{company:'Legacy'});assert.match(first.revisions[key],/^[a-f0-9]{64}$/);
const next=store.setData(owner,key,{company:'Updated'},first.revisions[key]);assert.notEqual(next,first.revisions[key]);
assert.throws(()=>store.setData(owner,key,{company:'Stale'},first.revisions[key]),e=>e.kod==='VERSION_CONFLICT');
assert.equal(store.getAllData(owner)[key].company,'Updated');
const reopened=store.getDataSnapshot(owner);assert.equal(reopened.revisions[key],next);
assert.equal(store.setData(owner,key,{company:'Updated'},next),next);
assert.throws(()=>store.setData(owner,key,{company:'New'},null),e=>e.kod==='VERSION_CONFLICT');
});