From 9ff383cc2b4a690fa05a88e70c598bfdc28751f4 Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 22 Sep 2016 11:27:20 -0400 Subject: [PATCH] change the query module interfaces back to simple functions --- controller/search.js | 13 +++----- query/autocomplete.js | 10 +++--- query/reverse.js | 10 +++--- query/search.js | 11 +++---- query/search_original.js | 10 +++--- test/unit/controller/search.js | 17 ++++------ test/unit/mock/query.js | 5 ++- test/unit/mock/search_query.js | 8 ----- test/unit/query/autocomplete.js | 48 +++++++++++++-------------- test/unit/query/reverse.js | 41 ++++++++++------------- test/unit/query/search.js | 51 ++++++++++++++-------------- test/unit/query/search_original.js | 53 ++++++++++++++---------------- 12 files changed, 123 insertions(+), 154 deletions(-) delete mode 100644 test/unit/mock/search_query.js diff --git a/controller/search.js b/controller/search.js index 5294eac9..39183fdf 100644 --- a/controller/search.js +++ b/controller/search.js @@ -10,11 +10,6 @@ function setup( config, backend, query ){ backend = backend || require('../src/backend'); query = query || require('../query/search'); - // verify that we don't let an old style query object slip through the cracks here - if (typeof query !== 'object' || !query.hasOwnProperty('query_type')) { - throw new Error('Search queries must return an object with query and query_type'); - } - function controller( req, res, next ){ // do not run controller when a request // validation error has occurred. @@ -36,10 +31,10 @@ function setup( config, backend, query ){ // log clean parameters for stats logger.info('[req]', 'endpoint=' + req.path, cleanOutput); - var query_body = query.query(req.clean); + var renderedQuery = query(req.clean); // if there's no query to call ES with, skip the service - if (_.isUndefined(query_body)) { + if (_.isUndefined(renderedQuery)) { return next(); } @@ -47,7 +42,7 @@ function setup( config, backend, query ){ var cmd = { index: config.indexName, searchType: 'dfs_query_then_fetch', - body: query_body + body: renderedQuery.body }; logger.debug( '[ES req]', cmd ); @@ -68,7 +63,7 @@ function setup( config, backend, query ){ res.data = docs; res.meta = meta || {}; // store the query_type for subsequent middleware - res.meta.query_type = query.query_type; + res.meta.query_type = renderedQuery.type; } logger.debug('[ES response]', docs); next(); diff --git a/query/autocomplete.js b/query/autocomplete.js index 44d3ca21..d0e766f3 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -114,10 +114,10 @@ function generateQuery( clean ){ textParser( clean.parsed_text, vs ); } - return query.render( vs ); + return { + type: 'autocomplete', + body: query.render(vs) + }; } -module.exports = { - query: generateQuery, - query_type: 'autocomplete' -}; +module.exports = generateQuery; \ No newline at end of file diff --git a/query/reverse.js b/query/reverse.js index e8f8612e..8cb2fa44 100644 --- a/query/reverse.js +++ b/query/reverse.js @@ -71,10 +71,10 @@ function generateQuery( clean ){ vs.var('input:categories', clean.categories); } - return query.render( vs ); + return { + type: 'reverse', + body: query.render(vs) + }; } -module.exports = { - query: generateQuery, - query_type: 'reverse' -}; +module.exports = generateQuery; diff --git a/query/search.js b/query/search.js index 300a26dc..5f7f3e34 100644 --- a/query/search.js +++ b/query/search.js @@ -121,7 +121,10 @@ function generateQuery( clean ){ function getQuery(vs) { if (hasStreet(vs)) { - return fallbackQuery.render(vs); + return { + type: 'fallback', + body: fallbackQuery.render(vs) + }; } // returning undefined is a signal to a later step that the addressit-parsed @@ -134,8 +137,4 @@ function hasStreet(vs) { return vs.isset('input:street'); } -module.exports = { - query: generateQuery, - // this could later be set to disambiguation when appropriate - query_type: 'fallback' -}; +module.exports = generateQuery; \ No newline at end of file diff --git a/query/search_original.js b/query/search_original.js index cc9e5180..e4a0dc66 100644 --- a/query/search_original.js +++ b/query/search_original.js @@ -125,11 +125,11 @@ function generateQuery( clean ){ textParser( clean.parsed_text, vs ); } - return query.render( vs ); + return { + type: 'original', + body: query.render(vs) + }; } -module.exports = { - query: generateQuery, - query_type: 'original' -}; +module.exports = generateQuery; diff --git a/test/unit/controller/search.js b/test/unit/controller/search.js index e501518f..86f07b97 100644 --- a/test/unit/controller/search.js +++ b/test/unit/controller/search.js @@ -1,6 +1,6 @@ var setup = require('../../../controller/search'), mockBackend = require('../mock/backend'), - mockQuery = require('../mock/search_query'); + mockQuery = require('../mock/query'); var proxyquire = require('proxyquire').noCallThru(); module.exports.tests = {}; @@ -90,7 +90,7 @@ module.exports.tests.functional_success = function(test, common) { searchType: 'dfs_query_then_fetch' }, 'correct backend command'); }); - var controller = setup(fakeDefaultConfig, backend, mockQuery); + var controller = setup(fakeDefaultConfig, backend, mockQuery()); var res = { status: function (code) { t.equal(code, 200, 'status set'); @@ -126,7 +126,7 @@ module.exports.tests.functional_success = function(test, common) { searchType: 'dfs_query_then_fetch' }, 'correct backend command'); }); - var controller = setup(fakeCustomizedConfig, backend, mockQuery); + var controller = setup(fakeCustomizedConfig, backend, mockQuery()); var res = { status: function (code) { t.equal(code, 200, 'status set'); @@ -148,7 +148,7 @@ module.exports.tests.functional_failure = function(test, common) { var backend = mockBackend( 'client/search/fail/1', function( cmd ){ t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command'); }); - var controller = setup( fakeDefaultConfig, backend, mockQuery ); + var controller = setup( fakeDefaultConfig, backend, mockQuery() ); var req = { clean: { a: 'b' }, errors: [], warnings: [] }; var next = function(){ t.equal(req.errors[0],'a backend error occurred'); @@ -163,7 +163,7 @@ module.exports.tests.timeout = function(test, common) { var backend = mockBackend( 'client/search/timeout/1', function( cmd ){ t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command'); }); - var controller = setup( fakeDefaultConfig, backend, mockQuery ); + var controller = setup( fakeDefaultConfig, backend, mockQuery() ); var req = { clean: { a: 'b' }, errors: [], warnings: [] }; var next = function(){ t.equal(req.errors[0],'Request Timeout after 5000ms'); @@ -178,7 +178,7 @@ module.exports.tests.existing_results = function(test, common) { var backend = function() { throw new Error('backend should not have been called'); }; - var controller = setup( fakeDefaultConfig, backend, mockQuery ); + var controller = setup( fakeDefaultConfig, backend, mockQuery() ); var req = { }; // the existence of `data` means that there are already results so @@ -198,10 +198,7 @@ module.exports.tests.existing_results = function(test, common) { module.exports.tests.undefined_query = function(test, common) { test('query returning undefined should not call service', function(t) { // a function that returns undefined - var query = { - query: function () { return; }, - query_type: 'empty' - }; + var query = function () { return; }; var search_service_was_called = false; diff --git a/test/unit/mock/query.js b/test/unit/mock/query.js index 2a5f21fd..a3209a4d 100644 --- a/test/unit/mock/query.js +++ b/test/unit/mock/query.js @@ -4,7 +4,10 @@ function setup(){ } function query( clean ){ - return clean; + return { + type: 'mock', + body: clean + }; } module.exports = setup; \ No newline at end of file diff --git a/test/unit/mock/search_query.js b/test/unit/mock/search_query.js deleted file mode 100644 index 9bd43cba..00000000 --- a/test/unit/mock/search_query.js +++ /dev/null @@ -1,8 +0,0 @@ -function query( clean ){ - return clean; -} - -module.exports = { - query: query, - query_type: 'mock' -}; \ No newline at end of file diff --git a/test/unit/query/autocomplete.js b/test/unit/query/autocomplete.js index 09ce34ad..64b6c447 100644 --- a/test/unit/query/autocomplete.js +++ b/test/unit/query/autocomplete.js @@ -1,24 +1,10 @@ -var query = require('../../../query/autocomplete'); -var generate = query.query; +var generate = require('../../../query/autocomplete'); module.exports.tests = {}; module.exports.tests.interface = function(test, common) { test('valid interface', function(t) { - t.equal(typeof query, 'object', 'valid query object'); - t.end(); - }); - test('valid interface', function(t) { - t.true(query.hasOwnProperty('query'), 'query is valid function'); - t.true(query.hasOwnProperty('query_type'), 'query is valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query, 'function', 'valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query_type, 'string', 'valid query_type'); + t.equal(typeof generate, 'function', 'valid function'); t.end(); }); }; @@ -35,7 +21,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_linguistic_only'); - t.deepEqual(compiled, expected, 'autocomplete_linguistic_only'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_only'); t.end(); }); @@ -50,7 +37,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_linguistic_multiple_tokens'); - t.deepEqual(compiled, expected, 'autocomplete_linguistic_multiple_tokens'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_multiple_tokens'); t.end(); }); @@ -70,7 +58,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_linguistic_with_admin'); - t.deepEqual(compiled, expected, 'autocomplete_linguistic_with_admin'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_with_admin'); t.end(); }); @@ -88,7 +77,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_linguistic_final_token'); - t.deepEqual(compiled, expected, 'autocomplete_linguistic_final_token'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_final_token'); t.end(); }); @@ -105,7 +95,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_linguistic_focus'); - t.deepEqual(compiled, expected, 'autocomplete_linguistic_focus'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_focus'); t.end(); }); @@ -122,7 +113,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_linguistic_focus_null_island'); - t.deepEqual(compiled, expected, 'autocomplete_linguistic_focus_null_island'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_linguistic_focus_null_island'); t.end(); }); @@ -138,7 +130,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_with_source_filtering'); - t.deepEqual(compiled, expected, 'valid autocomplete query with source filtering'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid autocomplete query with source filtering'); t.end(); }); @@ -154,7 +147,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_with_layer_filtering'); - t.deepEqual(compiled, expected, 'valid autocomplete query with layer filtering'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid autocomplete query with layer filtering'); t.end(); }); @@ -174,7 +168,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_single_character_street'); - t.deepEqual(compiled, expected, 'autocomplete_single_character_street'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete_single_character_street'); t.end(); }); @@ -190,7 +185,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/autocomplete_boundary_country'); - t.deepEqual(compiled, expected, 'autocomplete: valid boundary.country query'); + t.deepEqual(compiled.type, 'autocomplete', 'query type set'); + t.deepEqual(compiled.body, expected, 'autocomplete: valid boundary.country query'); t.end(); }); }; diff --git a/test/unit/query/reverse.js b/test/unit/query/reverse.js index 398eb731..24ada46a 100644 --- a/test/unit/query/reverse.js +++ b/test/unit/query/reverse.js @@ -1,24 +1,10 @@ -var query = require('../../../query/reverse'); -var generate = query.query; +var generate = require('../../../query/reverse'); module.exports.tests = {}; module.exports.tests.interface = function(test, common) { test('valid interface', function(t) { - t.equal(typeof query, 'object', 'valid query object'); - t.end(); - }); - test('valid interface', function(t) { - t.true(query.hasOwnProperty('query'), 'query is valid function'); - t.true(query.hasOwnProperty('query_type'), 'query is valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query, 'function', 'valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query_type, 'string', 'valid query_type'); + t.equal(typeof generate, 'function', 'valid function'); t.end(); }); }; @@ -36,7 +22,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/reverse_standard'); - t.deepEqual(compiled, expected, 'reverse_standard'); + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body, expected, 'reverse_standard'); t.end(); }); @@ -52,7 +39,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/reverse_null_island'); - t.deepEqual(compiled, expected, 'reverse_null_island'); + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body, expected, 'reverse_null_island'); t.end(); }); @@ -68,7 +56,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = '123km'; - t.deepEqual(compiled.query.bool.filter[0].geo_distance.distance, expected, 'distance set to boundary circle radius'); + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body.query.bool.filter[0].geo_distance.distance, expected, 'distance set to boundary circle radius'); t.end(); }); @@ -85,8 +74,9 @@ module.exports.tests.query = function(test, common) { // this should not equal `point.lat` and `point.lon` as it was explitely specified var expected = { lat: clean['boundary.circle.lat'], lon: clean['boundary.circle.lon'] }; - var centroid = compiled.query.bool.filter[0].geo_distance.center_point; + var centroid = compiled.body.query.bool.filter[0].geo_distance.center_point; + t.deepEqual(compiled.type, 'reverse', 'query type set'); t.deepEqual(centroid, expected, 'reverse: boundary.circle/lon overrides point.lat/lon'); t.end(); }); @@ -101,7 +91,7 @@ module.exports.tests.query = function(test, common) { }); var compiled = JSON.parse( JSON.stringify( query ) ); - t.equal( compiled.size, expected[index], 'valid reverse query for size: '+ size); + t.equal( compiled.body.size, expected[index], 'valid reverse query for size: '+ size); }); t.end(); }); @@ -119,7 +109,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/reverse_with_boundary_country'); - t.deepEqual(compiled, expected, 'valid reverse query with boundary.country'); + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid reverse query with boundary.country'); t.end(); }); @@ -136,7 +127,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/reverse_with_source_filtering'); - t.deepEqual(compiled, expected, 'valid reverse query with source filtering'); + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering'); t.end(); }); @@ -153,7 +145,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/reverse_with_layer_filtering'); - t.deepEqual(compiled, expected, 'valid reverse query with source filtering'); + t.deepEqual(compiled.type, 'reverse', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering'); t.end(); }); }; diff --git a/test/unit/query/search.js b/test/unit/query/search.js index b4a11972..36fbd17d 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -1,25 +1,11 @@ -var query = require('../../../query/search'); -var generate = query.query; +var generate = require('../../../query/search'); var fs = require('fs'); module.exports.tests = {}; module.exports.tests.interface = function(test, common) { test('valid interface', function(t) { - t.equal(typeof query, 'object', 'valid query object'); - t.end(); - }); - test('valid interface', function(t) { - t.true(query.hasOwnProperty('query'), 'query is valid function'); - t.true(query.hasOwnProperty('query_type'), 'query is valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query, 'function', 'valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query_type, 'string', 'valid query_type'); + t.equal(typeof generate, 'function', 'valid function'); t.end(); }); }; @@ -45,7 +31,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_bbox'); - t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_focus_bbox'); t.end(); }); @@ -68,7 +55,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_bbox'); - t.deepEqual(compiled, expected, 'search_linguistic_bbox'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_bbox'); t.end(); }); @@ -86,7 +74,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_only'); - t.deepEqual(compiled, expected, 'search_linguistic_only'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_only'); t.end(); }); @@ -105,7 +94,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus'); - t.deepEqual(compiled, expected, 'search_linguistic_focus'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_focus'); t.end(); }); @@ -127,7 +117,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_viewport'); - t.deepEqual(compiled, expected, 'search_linguistic_viewport'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_viewport'); t.end(); }); @@ -151,7 +142,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_viewport_min_diagonal'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid search query'); t.end(); }); @@ -170,7 +162,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_null_island'); - t.deepEqual(compiled, expected, 'search_linguistic_focus_null_island'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_focus_null_island'); t.end(); }); @@ -196,7 +189,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse(JSON.stringify(query)); var expected = require('../fixture/search_fallback'); - t.deepEqual(compiled, expected, 'fallbackQuery'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'fallbackQuery'); t.end(); }); @@ -234,7 +228,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_boundary_country'); - t.deepEqual(compiled, expected, 'search: valid boundary.country query'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search: valid boundary.country query'); t.end(); }); @@ -252,7 +247,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_with_source_filtering'); - t.deepEqual(compiled, expected, 'search: valid search query with source filtering'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'search: valid search query with source filtering'); t.end(); }); @@ -270,7 +266,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_with_category_filtering'); - t.deepEqual(compiled, expected, 'valid search query with category filtering'); + t.deepEqual(compiled.type, 'fallback', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid search query with category filtering'); t.end(); }); }; diff --git a/test/unit/query/search_original.js b/test/unit/query/search_original.js index 159200b1..5e035679 100644 --- a/test/unit/query/search_original.js +++ b/test/unit/query/search_original.js @@ -1,24 +1,10 @@ -var query = require('../../../query/search_original'); -var generate = query.query; +var generate = require('../../../query/search_original'); module.exports.tests = {}; module.exports.tests.interface = function(test, common) { test('valid interface', function(t) { - t.equal(typeof query, 'object', 'valid query object'); - t.end(); - }); - test('valid interface', function(t) { - t.true(query.hasOwnProperty('query'), 'query is valid function'); - t.true(query.hasOwnProperty('query_type'), 'query is valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query, 'function', 'valid function'); - t.end(); - }); - test('valid interface', function(t) { - t.equal(typeof query.query_type, 'string', 'valid query_type'); + t.equal(typeof generate, 'function', 'valid function'); t.end(); }); }; @@ -38,7 +24,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_bbox_original'); - t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_focus_bbox'); t.end(); }); @@ -55,7 +42,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_bbox_original'); - t.deepEqual(compiled, expected, 'search_linguistic_bbox'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_bbox'); t.end(); }); @@ -68,7 +56,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_only_original'); - t.deepEqual(compiled, expected, 'search_linguistic_only'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_only'); t.end(); }); @@ -82,7 +71,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_original'); - t.deepEqual(compiled, expected, 'search_linguistic_focus'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_focus'); t.end(); }); @@ -96,7 +86,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_null_island_original'); - t.deepEqual(compiled, expected, 'search_linguistic_focus_null_island'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_linguistic_focus_null_island'); t.end(); }); @@ -117,7 +108,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_full_address_original'); - t.deepEqual(compiled, expected, 'search_full_address'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_full_address'); t.end(); }); @@ -135,7 +127,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_partial_address_original'); - t.deepEqual(compiled, expected, 'search_partial_address'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_partial_address'); t.end(); }); @@ -147,13 +140,14 @@ module.exports.tests.query = function(test, common) { street: 'water st', state: 'NY', regions: [ 'manhattan' ] - }, + } }); var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_regions_address_original'); - t.deepEqual(compiled, expected, 'search_regions_address'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search_regions_address'); t.end(); }); @@ -167,7 +161,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_boundary_country_original'); - t.deepEqual(compiled, expected, 'search: valid boundary.country query'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search: valid boundary.country query'); t.end(); }); @@ -180,7 +175,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_with_source_filtering_original'); - t.deepEqual(compiled, expected, 'search: valid search query with source filtering'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'search: valid search query with source filtering'); t.end(); }); @@ -193,7 +189,8 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_with_category_filtering_original'); - t.deepEqual(compiled, expected, 'valid search query with category filtering'); + t.deepEqual(compiled.type, 'original', 'query type set'); + t.deepEqual(compiled.body, expected, 'valid search query with category filtering'); t.end(); }); };