From cc7a873186669be360ba8c580a2b0d928640eed6 Mon Sep 17 00:00:00 2001 From: Rob Gietema Date: Tue, 3 Dec 2024 18:03:59 -0500 Subject: [PATCH] Fix tests. --- docs/examples/vocabularies/list.res | 4 ++++ src/models/_model/_model.js | 3 --- src/routes/form/form.test.js | 6 ++++++ src/routes/search/search.js | 23 ++++++++++++++++------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/docs/examples/vocabularies/list.res b/docs/examples/vocabularies/list.res index f461078..d00311d 100644 --- a/docs/examples/vocabularies/list.res +++ b/docs/examples/vocabularies/list.res @@ -18,6 +18,10 @@ Content-Type: application/json "@id": "http://localhost:8080/@vocabularies/boolean", "title": "boolean" }, + { + "@id": "http://localhost:8080/@vocabularies/captchaProviders", + "title": "captchaProviders" + }, { "@id": "http://localhost:8080/@vocabularies/groups", "title": "groups" diff --git a/src/models/_model/_model.js b/src/models/_model/_model.js index 464b636..bc84101 100644 --- a/src/models/_model/_model.js +++ b/src/models/_model/_model.js @@ -67,9 +67,6 @@ export class Model extends mixin(ObjectionModel, [ operator = '='; valueWrapper = 'all(?)'; } - if (operator === 'like') { - valueWrapper = '%?%'; - } if (operator === '@@') { valueWrapper = 'to_tsquery(?)'; } diff --git a/src/routes/form/form.test.js b/src/routes/form/form.test.js index e69de29..4619d7b 100644 --- a/src/routes/form/form.test.js +++ b/src/routes/form/form.test.js @@ -0,0 +1,6 @@ +import app from '../../app'; +import { testRequest } from '../../helpers'; + +describe('Form', () => { + it('should submit a form', () => testRequest(app, 'search/post')); +}); diff --git a/src/routes/search/search.js b/src/routes/search/search.js index de900aa..408d598 100644 --- a/src/routes/search/search.js +++ b/src/routes/search/search.js @@ -22,9 +22,13 @@ import { Catalog, Index } from '../../models'; const querystringToQuery = async (querystring, path = '/', req, trx) => { // Get root url const root = endsWith(path, '/') ? path : `${path}/`; - const indexes = ( - await Index.fetchAll({ enabled: true, metadata: false }, {}, trx) - ).toJSON(req); + + // Get indexes + let indexes = {}; + (await Index.fetchAll({ metadata: false }, {}, trx)).map((index) => { + indexes[index.name] = index; + }); + const where = {}; // Default options @@ -129,7 +133,7 @@ const querystringToQuery = async (querystring, path = '/', req, trx) => { where[query.i] = req.user.id; break; case 'string.contains': - where[query.i] = ['like', query.v]; + where[query.i] = ['like', `%${query.v}%`]; break; default: break; @@ -151,9 +155,12 @@ const querystringToQuery = async (querystring, path = '/', req, trx) => { const queryparamToQuery = async (queryparam, path = '/', req, trx) => { // Get root url const root = endsWith(path, '/') ? path : `${path}/`; - const indexes = ( - await Index.fetchAll({ enabled: true, metadata: false }, {}, trx) - ).toJSON(req); + + // Get indexes + let indexes = {}; + (await Index.fetchAll({ metadata: false }, {}, trx)).map((index) => { + indexes[index.name] = index; + }); // Set path search const where = { @@ -169,6 +176,8 @@ const queryparamToQuery = async (queryparam, path = '/', req, trx) => { reverse: false, }, }; + + // Loop through query params mapKeys(queryparam, (value, key) => { switch (key) { case 'sort_on':