From 369a9205957601c7326fd8c26befbf74c0001ced Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Tue, 28 Jun 2022 13:16:14 +0200 Subject: [PATCH] feat(search-backend-module-pg): test error handling Co-authored-by: Emma Indal Signed-off-by: Camila Belo --- .../src/PgSearchEngine/PgSearchEngine.test.ts | 15 +++++++++++++++ .../src/PgSearchEngine/PgSearchEngine.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts index 3ed002567e..e106cd6f06 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts @@ -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', + ); + }); }); }); diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts index d8128f8568..065f25878c 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts @@ -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.`, );