Skip to content

Commit

Permalink
Merge pull request #3448 from huridocs/3437-snippets-search-id
Browse files Browse the repository at this point in the history
Adds ID validation when searching snippets
  • Loading branch information
fnocetti authored Jan 29, 2021
2 parents 3b3c1b8 + b670661 commit ea61bac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
17 changes: 13 additions & 4 deletions app/api/search/deprecatedRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ export default app => {
app.get(
'/api/search_snippets',
validation.validateRequest(
Joi.object().keys({
searchTerm: Joi.string().allow(''),
id: Joi.string(),
}),
{
required: ['query'],
properties: {
query: {
type: 'object',
required: ['id'],
properties: {
searchTerm: { type: 'string', default: '' },
id: { type: 'string' },
},
},
},
},
'query'
),
(req, res, next) =>
Expand Down
20 changes: 0 additions & 20 deletions app/api/search/specs/__snapshots__/routes.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,3 @@ Object {
"type": "object",
}
`;

exports[`search routes /api/search_snippets should have a validation schema 1`] = `
Object {
"children": Object {
"id": Object {
"invalids": Array [
"",
],
"type": "string",
},
"searchTerm": Object {
"type": "string",
"valids": Array [
"",
],
},
},
"type": "object",
}
`;
19 changes: 17 additions & 2 deletions app/api/search/specs/routes.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import request from 'supertest';
import entities from 'api/entities';
import { catchErrors } from 'api/utils/jasmineHelpers';
import { setUpApp } from 'api/utils/testingRoutes';
import { testingDB } from 'api/utils/testing_db';
import searchRoutes from '../deprecatedRoutes.js';
import instrumentRoutes from '../../utils/instrumentRoutes';
import { search } from '../search';
Expand Down Expand Up @@ -87,8 +90,20 @@ describe('search routes', () => {
});

describe('/api/search_snippets', () => {
it('should have a validation schema', () => {
expect(routes.get.validation('/api/search_snippets')).toMatchSnapshot();
const app = setUpApp(searchRoutes);

it('should have a validation schema', async () => {
await testingDB.clearAllAndLoad({
settings: [
{
languages: [{ key: 'es', default: true }, { key: 'pt' }, { key: 'en' }],
},
],
});
const response = await request(app)
.get('/api/search_snippets?searchTerm=test')
.send({});
expect(response.text).toMatch(/should have required property 'id'/);
});

it('should search', done => {
Expand Down

0 comments on commit ea61bac

Please sign in to comment.