feat(search-backend-module-pg): test error handling
Co-authored-by: Emma Indal <emma.indahl@gmail.com> Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -271,6 +271,21 @@ describe('PgSearchEngine', () => {
|
||||
limit: 26,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throws missing index error', async () => {
|
||||
database.transaction.mockImplementation(fn => fn(tx));
|
||||
database.query.mockResolvedValue([]);
|
||||
await expect(
|
||||
async () =>
|
||||
await searchEngine.query({
|
||||
term: 'testTerm',
|
||||
types: ['unknown'],
|
||||
filters: {},
|
||||
}),
|
||||
).rejects.toThrow(
|
||||
'Missing index for unknown. This means there are no documents to search through',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ export class PgSearchEngine implements SearchEngine {
|
||||
this.databaseStore.query(tx, pgQuery),
|
||||
);
|
||||
|
||||
if (!rows.length) {
|
||||
if (pgQuery?.types && !rows.length) {
|
||||
throw new MissingIndexError(
|
||||
`Missing index for ${pgQuery.types}. This means there are no documents to search through.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user