Test for SearchEngineUtils

@lauren if I want to write a test for SearchEngineUtils.ts, how can I create notes for this?

let searchEngine: any = null;
await setupDatabaseAndSynchronizer(1);
await switchClient(1);
searchEngine = new SearchEngine();
searchEngine.setDb(db());
const note1 = await Note.save({ title: 'abcd', body: 'body 1' });
await searchEngine.syncTables();
await searchEngine.search('abcd'); // works
await SearchEngineUtils.notesForQuery("abcd"); // no results

The searchEngine.search works fine, but for SearchEngineUtils.notesForQuery I get no results.

I wish a good night

SearchEngineUtils uses the global SearchEngine instance, which is different from the local instance you create. I think you'd have to refactor the code so that notesForQuery takes an additional parameter, which would be a search engine instance.

ok, thanks for the hint. Then i will see what i can do.

1 Like