From 33e1a53ef3776327a26b6948289090b59c263d42 Mon Sep 17 00:00:00 2001 From: Sean Zellmer Date: Mon, 29 Jun 2026 13:08:41 -0400 Subject: [PATCH] Add tests asserting when the group update hook should fire The hook should fire after the `truncate` and `append` events, and after the length / tree info has been updated. --- test/groups.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/groups.js b/test/groups.js index dd400c7f..45d613d1 100644 --- a/test/groups.js +++ b/test/groups.js @@ -230,3 +230,46 @@ test('groups - core hook - ongroupupdate() w/head and fork', async function (t) } ]) }) + +test('groups - ongroupupdate() fires after append event & length updating', async function (t) { + t.plan(2) + const a = await create(t) + const groupKey = b4a.alloc(32, 1) + + let appendFired = false + + a.on('append', function () { + appendFired = true + }) + + a.core.ongroupupdate = (key, head) => { + t.ok(appendFired, 'append event fired before ongroupupdate') + t.is(head.length, a.length, 'ongroupupdate head.length matches core.length') + } + + await a.setGroup(groupKey) + await a.append('beep') +}) + +test('groups - ongroupupdate() fires after truncate event & length updating', async function (t) { + t.plan(3) + const a = await create(t) + const groupKey = b4a.alloc(32, 1) + + await a.setGroup(groupKey) + await a.append('beep') + + let truncateFired = false + + a.on('truncate', function () { + truncateFired = true + }) + + a.core.ongroupupdate = (key, head) => { + t.ok(truncateFired, 'truncate event fired before ongroupupdate') + t.is(head.length, a.length, 'ongroupupdate head.length matches core.length after truncate') + t.is(head.fork, a.fork, 'ongroupupdate head.fork matches core.fork after truncate') + } + + await a.truncate(0, { fork: 3 }) +})