diff --git a/app/api/search/routes.ts b/app/api/search/routes.ts index 1f6e034701..d4e71c5e82 100644 --- a/app/api/search/routes.ts +++ b/app/api/search/routes.ts @@ -25,6 +25,10 @@ export default (app: Application) => { res: Response, next: NextFunction ) => { + if (!req.query.query) throw new Error("The 'query' property can not be undefined"); + if (!req.query.property) throw new Error("The 'property' key can not be undefined"); + if (!req.query.searchTerm) throw new Error("The 'searchTerm' property can not be undefined"); + const query = JSON.parse(req.query.query); search .autocompleteAggregations( diff --git a/app/api/search/specs/routes.spec.ts b/app/api/search/specs/routes.spec.ts index 5e04e038e2..f25be4a251 100644 --- a/app/api/search/specs/routes.spec.ts +++ b/app/api/search/specs/routes.spec.ts @@ -135,4 +135,43 @@ describe('Search routes', () => { expect(options[0].results).toBeDefined(); }); }); + + it('should return status code 500 if query is not provided', async () => { + const res = await request(app) + .get('/api/search/lookupaggregation') + .query({ property: 'relationship', searchTerm: 'Bat' }); + + expect(res.statusCode).toBe(500); + expect(res.body.error).toBe("The 'query' property can not be undefined"); + }); + + it('should return status code 500 if property is not provided', async () => { + const res = await request(app) + .get('/api/search/lookupaggregation') + .query({ + query: { + types: [ids.template1], + filters: {}, + }, + searchTerm: 'Bat', + }); + + expect(res.statusCode).toBe(500); + expect(res.body.error).toBe("The 'property' key can not be undefined"); + }); + + it('should return status code 500 if searchTerm is not provided', async () => { + const res = await request(app) + .get('/api/search/lookupaggregation') + .query({ + query: { + types: [ids.template1], + filters: {}, + }, + property: 'relationship', + }); + + expect(res.statusCode).toBe(500); + expect(res.body.error).toBe("The 'searchTerm' property can not be undefined"); + }); });