1
2
3
4
5
6
7
8
9
10
11
12
13
|
import assert from 'node:assert/strict';
import { liveReactions } from '../src/live.js';
const one = {kind:7,id:'one',pubkey:'alice',created_at:1,content:'❤️',tags:[['e','parent'],['e','comment']]};
const two = {...one,id:'two',created_at:2,content:'👍'};
const other = {...one,id:'other',pubkey:'bob'};
const del = {kind:5,id:'delete',pubkey:'alice',created_at:3,tags:[['e','one'],['e','two']]};
assert.equal(liveReactions([two, one]).get('comment').get('alice').content,'👍');
assert.equal(liveReactions([one, one, other]).get('comment').size,2);
assert.equal(liveReactions([del, two, one, other]).get('comment').size,1);
assert.equal(liveReactions([{...del,pubkey:'mallory'},two]).get('comment').size,1);
assert.equal(liveReactions([one,two,{...del,tags:[['e','one']]}]).get('comment').get('alice').id,'two');
assert.equal(liveReactions([two,{...two,id:'zzz'}]).get('comment').get('alice').id,'zzz');
console.log('✓ Live reaction deduplication, replacement, out-of-order deletion and author validation');
|