Skip to content

Commit

Permalink
feat(jest): 100% coverage for libraries/SatelliteDB/SatelliteDB (#2468)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram authored Mar 23, 2022
1 parent 867fbd7 commit 9d27565
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libraries/SatelliteDB/SatelliteDB.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ describe('SatelliteDB', () => {
expect(db.search.conversationMessages).toBeInstanceOf(SearchIndex)
})

test('reinitializing schema', async () => {
db.version = jest.fn()
await db.initializeSchema()
expect(db.version).not.toHaveBeenCalled()
})

test('restoring search indexes', async () => {
const where = { address: 'foo' }
const data = { name: 'bar', textilePubkey: 'baz' }
Expand All @@ -47,6 +53,24 @@ describe('SatelliteDB', () => {
)
})

test('reinitializing search indexes', async () => {
const where = { address: 'foo' }
const data = { name: 'bar', textilePubkey: 'baz' }
await db.initializeSearchIndexes()
await db.upsert('friends', where, data)
await db.saveSearchIndexes()
await db.close()

db = new SatelliteDB()
await db.initializeSearchIndexes()
expect(await db.search.friends.search('bar')?.[0]?.address).toEqual(
where.address,
)
db.keyValue = jest.fn()
await db.initializeSearchIndexes()
expect(db.keyValue).not.toHaveBeenCalled()
})

test('upserting records', async () => {
const where = { address: '1' }
const original = {
Expand Down

0 comments on commit 9d27565

Please sign in to comment.