mirror of https://codeberg.org/pzp/pzp-gc.git
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const test = require('node:test')
|
|
const assert = require('node:assert')
|
|
const p = require('node:util').promisify
|
|
const { createPeer } = require('./util')
|
|
|
|
function getTexts(msgs) {
|
|
return msgs.filter((msg) => msg.data?.text).map((msg) => msg.data.text)
|
|
}
|
|
|
|
test('Feed decay', async (t) => {
|
|
const alice = createPeer({ name: 'alice' })
|
|
|
|
await alice.db.loaded()
|
|
|
|
// Alice creates her own account
|
|
const aliceID = await p(alice.db.account.create)({
|
|
subdomain: 'account',
|
|
_nonce: 'alice',
|
|
})
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
await p(alice.db.feed.publish)({
|
|
account: aliceID,
|
|
domain: 'post',
|
|
data: { text: 'A' + i },
|
|
})
|
|
}
|
|
|
|
let msgs = []
|
|
for await (const msg of alice.db.msgs()) {
|
|
msgs.push(msg)
|
|
}
|
|
assert.deepEqual(
|
|
getTexts(msgs),
|
|
['A0', 'A1', 'A2', 'A3', 'A4'],
|
|
'alice has the whole feed'
|
|
)
|
|
|
|
alice.goals.set(aliceID, 'all') // alice wants her account tangle
|
|
const postFeedID = alice.db.feed.getID(aliceID, 'post')
|
|
alice.goals.set(postFeedID, 'newest-3')
|
|
assert('alice set a goal for newest-3 of post feed')
|
|
|
|
await p(alice.gc.forceImmediately)()
|
|
|
|
msgs = []
|
|
for await (const msg of alice.db.msgs()) {
|
|
msgs.push(msg)
|
|
}
|
|
assert.deepEqual(
|
|
getTexts(msgs),
|
|
['A2', 'A3', 'A4'],
|
|
'alice has only latest 3 msgs in the feed'
|
|
)
|
|
|
|
await p(alice.close)(true)
|
|
})
|