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:
Camila Belo
2022-06-28 13:16:14 +02:00
parent 197bca1bc0
commit 369a920595
2 changed files with 16 additions and 1 deletions
@@ -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.`,
);