Require explicit persisted acknowledgement of notifications
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {mergeServerNotifications,acknowledgeNotifications} from '../src/services/notifications.js';
|
||||
const rows=[{id:'one',baslik:'Tarih değişti',metin:'Yeni tarih',okundu:0,zaman:'2026-09-06T10:00:00Z'}];
|
||||
test('refresh keeps stable notification identities and server unread state without acknowledging delivery',()=>{
|
||||
const once=mergeServerNotifications([{id:'local',title:'Yerel',read:false}],rows);
|
||||
const twice=mergeServerNotifications(once,rows);
|
||||
assert.deepEqual(twice,once);assert.equal(twice[0].read,false);assert.equal(twice.length,2);
|
||||
assert.equal(mergeServerNotifications(twice,[{...rows[0],okundu:1}])[0].read,true);
|
||||
assert.throws(()=>mergeServerNotifications([],{}),/geçersiz/);
|
||||
});
|
||||
test('read acknowledgement requires server success and only covers the captured unread snapshot',async()=>{
|
||||
const current=mergeServerNotifications([{id:'local',read:false}],rows);
|
||||
await assert.rejects(acknowledgeNotifications(current,async()=>{throw new Error('depo kapalı');}),/depo kapalı/);
|
||||
assert.equal(current[0].read,false);
|
||||
await assert.rejects(acknowledgeNotifications(current,async()=>({success:true,okundu:0})),/kaydedilemedi/);
|
||||
const acknowledged=await acknowledgeNotifications(current,async ids=>{assert.deepEqual(ids,['one']);return {success:true,okundu:1};});
|
||||
assert.deepEqual([...acknowledged],['server:one','local']);assert.equal(acknowledged.has('arrived-later'),false);
|
||||
});
|
||||
Reference in New Issue
Block a user