diff --git a/controller/search.js b/controller/search.js index 28fa3837..795ad2c6 100644 --- a/controller/search.js +++ b/controller/search.js @@ -36,6 +36,7 @@ function setup( backend, query ){ // set response data else { res.data = docs; + res.meta = meta; } next(); diff --git a/query/text_parser.js b/query/text_parser.js index 63d8b93b..408d00f9 100644 --- a/query/text_parser.js +++ b/query/text_parser.js @@ -1,4 +1,5 @@ +var logger = require('pelias-logger').get('api'); var adminFields = require('../helper/adminFields')(); /** @@ -21,9 +22,9 @@ function addParsedVariablesToQueryVariables( parsed_text, vs ){ // ? else { - console.warn( 'chaos monkey asks: what happens now?' ); - console.log( parsed_text ); - try{ throw new Error(); } catch(e){ console.error( e.stack ); } // print a stack trace + logger.warn( 'chaos monkey asks: what happens now?' ); + logger.warn( parsed_text ); + try{ throw new Error(); } catch(e){ logger.warn( e.stack ); } // print a stack trace } // ==== add parsed matches [address components] ==== diff --git a/test/unit/controller/search.js b/test/unit/controller/search.js index 9a21f4c7..2b412013 100644 --- a/test/unit/controller/search.js +++ b/test/unit/controller/search.js @@ -41,6 +41,35 @@ module.exports.tests.functional_success = function(test, common) { } }]; + var expectedMeta = { + scores: [10, 20] + }; + + var expectedData = [ + { + _id: 'myid1', + _score: 10, + _type: 'mytype1', + admin0: 'country1', + admin1: 'state1', + admin2: 'city1', + center_point: { lat: 100.1, lon: -50.5 }, + name: { default: 'test name1' }, + value: 1 + }, + { + _id: 'myid2', + _score: 20, + _type: 'mytype2', + admin0: 'country2', + admin1: 'state2', + admin2: 'city2', + center_point: { lat: 100.2, lon: -51.5 }, + name: { default: 'test name2' }, + value: 2 + } + ]; + test('functional success', function (t) { var backend = mockBackend('client/search/ok/1', function (cmd) { t.deepEqual(cmd, { @@ -66,6 +95,8 @@ module.exports.tests.functional_success = function(test, common) { var req = { clean: { a: 'b' }, errors: [], warnings: [] }; var next = function next() { t.equal(req.errors.length, 0, 'next was called without error'); + t.deepEqual(res.meta, expectedMeta, 'meta data was set'); + t.deepEqual(res.data, expectedData, 'data was set'); t.end(); }; controller(req, res, next); diff --git a/test/unit/service/search.js b/test/unit/service/search.js index a7212775..e5bf2cff 100644 --- a/test/unit/service/search.js +++ b/test/unit/service/search.js @@ -35,16 +35,21 @@ module.exports.tests.functional_success = function(test, common) { } ]; + var expectedMeta = { + scores: [10, 20] + }; + test('valid ES query', function(t) { var backend = mockBackend( 'client/search/ok/1', function( cmd ){ t.deepEqual(cmd, example_valid_es_query, 'no change to the command'); }); - setup( backend, example_valid_es_query, function(err, data) { + setup( backend, example_valid_es_query, function(err, data, meta) { t.true(Array.isArray(data), 'returns an array'); data.forEach(function(d) { t.true(typeof d === 'object', 'valid object'); }); t.deepEqual(data, expected, 'values correctly mapped'); + t.deepEqual(meta, expectedMeta, 'meta data correctly mapped'); t.end(); }); });