mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo-db.git
synced 2026-09-21 16:52:02 -07:00
Adding reply count to post metadata
This commit is contained in:
@@ -6,13 +6,25 @@ describe('#PostQuery', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
let postsDb
|
||||
let postParentsDb
|
||||
let postChildrenDb
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
postsDb = {
|
||||
iterator: sandbox.stub()
|
||||
}
|
||||
uut = new PostQuery({ postsDb })
|
||||
postParentsDb = {
|
||||
iterator: sandbox.stub()
|
||||
}
|
||||
postChildrenDb = {
|
||||
iterator: sandbox.stub()
|
||||
}
|
||||
async function * emptyParents () {}
|
||||
async function * emptyChildren () {}
|
||||
postParentsDb.iterator.returns(emptyParents())
|
||||
postChildrenDb.iterator.returns(emptyChildren())
|
||||
uut = new PostQuery({ postsDb, postParentsDb, postChildrenDb })
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
@@ -29,8 +41,10 @@ describe('#PostQuery', () => {
|
||||
assert.equal(result.length, 2)
|
||||
assert.equal(result[0].txid, 'tx1')
|
||||
assert.equal(result[0].blockHeight, 600100)
|
||||
assert.equal(result[0].replyCount, 0)
|
||||
assert.equal(result[1].txid, 'tx2')
|
||||
assert.equal(result[1].blockHeight, 600200)
|
||||
assert.equal(result[1].replyCount, 0)
|
||||
})
|
||||
|
||||
it('should use block height 0 when field is missing', async () => {
|
||||
@@ -42,6 +56,7 @@ describe('#PostQuery', () => {
|
||||
const result = await uut.scanPostsWithBlockHeight()
|
||||
|
||||
assert.equal(result[0].blockHeight, 0)
|
||||
assert.equal(result[0].replyCount, 0)
|
||||
})
|
||||
|
||||
it('should scan posts for a single address', async () => {
|
||||
@@ -58,4 +73,72 @@ describe('#PostQuery', () => {
|
||||
assert.equal(result[0].txid, 'tx1')
|
||||
assert.equal(result[1].txid, 'tx3')
|
||||
})
|
||||
|
||||
it('should exclude reply posts from recent scan', async () => {
|
||||
async function * mockParents () {
|
||||
yield ['tx-reply', { parentTxid: 'tx1', childTxid: 'tx-reply', blockHeight: 600150 }]
|
||||
}
|
||||
async function * mockPosts () {
|
||||
yield ['tx1', { addr: 'addr1', text: 'top', seen: 1000, blockHeight: 600100 }]
|
||||
yield ['tx-reply', { addr: 'addr1', text: 'reply', seen: 1500, blockHeight: 600150 }]
|
||||
yield ['tx2', { addr: 'addr2', text: 'other', seen: 2000, blockHeight: 600200 }]
|
||||
}
|
||||
postParentsDb.iterator.returns(mockParents())
|
||||
postsDb.iterator.returns(mockPosts())
|
||||
|
||||
const result = await uut.scanPostsWithBlockHeight()
|
||||
|
||||
assert.equal(result.length, 2)
|
||||
assert.equal(result[0].txid, 'tx1')
|
||||
assert.equal(result[1].txid, 'tx2')
|
||||
})
|
||||
|
||||
it('should exclude reply posts from address scan', async () => {
|
||||
async function * mockParents () {
|
||||
yield ['tx-reply', { parentTxid: 'tx1', childTxid: 'tx-reply', blockHeight: 600150 }]
|
||||
}
|
||||
async function * mockPosts () {
|
||||
yield ['tx1', { addr: 'addr-a', text: 'top', seen: 1000, blockHeight: 600100 }]
|
||||
yield ['tx-reply', { addr: 'addr-a', text: 'reply', seen: 1500, blockHeight: 600150 }]
|
||||
}
|
||||
postParentsDb.iterator.returns(mockParents())
|
||||
postsDb.iterator.returns(mockPosts())
|
||||
|
||||
const result = await uut.scanPostsByAddr('addr-a')
|
||||
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].txid, 'tx1')
|
||||
})
|
||||
|
||||
it('should include replyCount from postChildren scan', async () => {
|
||||
async function * mockChildren () {
|
||||
yield ['tx1:reply-a', { parentTxid: 'tx1', childTxid: 'reply-a', blockHeight: 600150 }]
|
||||
yield ['tx1:reply-b', { parentTxid: 'tx1', childTxid: 'reply-b', blockHeight: 600160 }]
|
||||
yield ['tx2:reply-c', { parentTxid: 'tx2', childTxid: 'reply-c', blockHeight: 600170 }]
|
||||
}
|
||||
async function * mockPosts () {
|
||||
yield ['tx1', { addr: 'addr1', text: 'top', seen: 1000, blockHeight: 600100 }]
|
||||
yield ['tx2', { addr: 'addr2', text: 'other', seen: 2000, blockHeight: 600200 }]
|
||||
}
|
||||
postChildrenDb.iterator.returns(mockChildren())
|
||||
postsDb.iterator.returns(mockPosts())
|
||||
|
||||
const result = await uut.scanPostsWithBlockHeight()
|
||||
|
||||
assert.equal(result.length, 2)
|
||||
assert.equal(result.find((p) => p.txid === 'tx1').replyCount, 2)
|
||||
assert.equal(result.find((p) => p.txid === 'tx2').replyCount, 1)
|
||||
})
|
||||
|
||||
it('should default replyCount to 0 when post has no replies', async () => {
|
||||
async function * mockPosts () {
|
||||
yield ['tx1', { addr: 'addr1', text: 'solo', seen: 1000, blockHeight: 600100 }]
|
||||
}
|
||||
postsDb.iterator.returns(mockPosts())
|
||||
|
||||
const result = await uut.scanPostsByAddr('addr1')
|
||||
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].replyCount, 0)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user