From 39671222b1e22408d7e7cf4b2122e70b5bde4c0a Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 23 Mar 2022 09:15:37 +0700 Subject: [PATCH] feat(jest): 100% coverage for libraries/SatelliteDB/SearchIndex.ts --- libraries/SatelliteDB/SearchIndex.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libraries/SatelliteDB/SearchIndex.test.ts b/libraries/SatelliteDB/SearchIndex.test.ts index 44ee971e94..89bb95941e 100644 --- a/libraries/SatelliteDB/SearchIndex.test.ts +++ b/libraries/SatelliteDB/SearchIndex.test.ts @@ -32,6 +32,22 @@ describe('SatelliteDB/SearchIndex', () => { expect(idx.search('match')?.map((r) => r.id)).toEqual(['3', '2', '1']) }) + test('searchIndex.update()', async () => { + const data = [ + { id: '1', text: 'first match' }, + { id: '2', text: 'second match' }, + { id: '3', text: 'third match' }, + ] + idx.update(data) + expect(idx.autoSuggest('first')).toEqual([ + { + suggestion: 'first', + terms: ['first'], + score: 1.0986122886681096, + }, + ]) + }) + test('searchIndex.update() without an id', async () => { const data = [{ text: 'foo bar' }] expect(() => idx.update(data)).toThrow()