mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo-db.git
synced 2026-09-21 16:52:02 -07:00
Adding block height to all db models
This commit is contained in:
@@ -6,29 +6,23 @@ describe('#PostQuery', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
let postsDb
|
||||
let ptxsDb
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
postsDb = {
|
||||
iterator: sandbox.stub()
|
||||
}
|
||||
ptxsDb = {
|
||||
get: sandbox.stub()
|
||||
}
|
||||
uut = new PostQuery({ postsDb, ptxsDb })
|
||||
uut = new PostQuery({ postsDb })
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
it('should scan posts and attach block height from ptx', async () => {
|
||||
it('should scan posts and read block height from stored document', async () => {
|
||||
async function * mockIterator () {
|
||||
yield ['tx1', { addr: 'addr1', text: 'hello', seen: 1000 }]
|
||||
yield ['tx2', { addr: 'addr2', text: 'world', seen: 2000 }]
|
||||
yield ['tx1', { addr: 'addr1', text: 'hello', seen: 1000, blockHeight: 600100 }]
|
||||
yield ['tx2', { addr: 'addr2', text: 'world', seen: 2000, blockHeight: 600200 }]
|
||||
}
|
||||
postsDb.iterator.returns(mockIterator())
|
||||
ptxsDb.get.withArgs('tx1').resolves({ blockHeight: 600100 })
|
||||
ptxsDb.get.withArgs('tx2').resolves({ blockHeight: 600200 })
|
||||
|
||||
const result = await uut.scanPostsWithBlockHeight()
|
||||
|
||||
@@ -39,12 +33,11 @@ describe('#PostQuery', () => {
|
||||
assert.equal(result[1].blockHeight, 600200)
|
||||
})
|
||||
|
||||
it('should use block height 0 when ptx is missing', async () => {
|
||||
it('should use block height 0 when field is missing', async () => {
|
||||
async function * mockIterator () {
|
||||
yield ['tx-missing', { addr: 'addr1', text: 'hi', seen: 1000 }]
|
||||
}
|
||||
postsDb.iterator.returns(mockIterator())
|
||||
ptxsDb.get.rejects(new Error('not found'))
|
||||
|
||||
const result = await uut.scanPostsWithBlockHeight()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user