Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions test/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})
Loading