Skip to content

Commit

Permalink
test that live fullMentions is silent during reindexing
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Jun 29, 2022
1 parent f31203a commit 9e7136f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/delete-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const generateFixture = require('ssb-fixtures')
const fs = require('fs')
const { where, author, toPromise } = require('../operators')
const { where, live, author, toPromise, toPullStream } = require('../operators')
const mentions = require('../operators/full-mentions')

const dir = '/tmp/ssb-db2-delete-feed-compact'

Expand Down Expand Up @@ -43,6 +44,7 @@ test('delete a feed and then compact', async (t) => {
const keys = ssbKeys.loadOrCreateSync(path.join(dir, 'secret'))
const sbot = SecretStack({ appKey: caps.shs })
.use(require('../'))
.use(require('../full-mentions'))
.call(null, {
keys,
path: dir,
Expand All @@ -61,6 +63,22 @@ test('delete a feed and then compact', async (t) => {
)
})

let gotSpecialMention = false
pull(
sbot.db.query(where(mentions(sbot.id)), live(), toPullStream()),
pull.drain((msg) => {
if (msg.value.content.special) {
if (gotSpecialMention) {
t.fail('got more than one special mention')
} else {
gotSpecialMention = true
}
} else {
t.fail('should not get any live mentions during reindexing')
}
})
)

const badPerson = '@a5URnr0bEtVFmNxQu/JwQ5JsfEl+HAPz5ethL+I1CCA=.ed25519'
t.notEqual(sbot.id, badPerson, 'I am not the bad person')

Expand Down Expand Up @@ -96,6 +114,17 @@ test('delete a feed and then compact', async (t) => {
const msgsBad2 = await sbot.db.query(where(author(badPerson)), toPromise())
t.equals(msgsBad2.length, 0, 'zero messages by bad person')

await pify(sbot.db.publishAs)(ssbKeys.generate(), {
type: 'post',
text: 'Hi',
special: 'yes',
mentions: [{ link: sbot.id }],
})
t.pass('published new mention')

await pify(setTimeout)(1000)
t.true(gotSpecialMention, 'got special mention')

await pify(sbot.close)(true)
t.end()
})

0 comments on commit 9e7136f

Please sign in to comment.