From 2363e9d7399d7161686a0a8dd1da0a31aee224d5 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 27 Jun 2017 16:10:09 -0400 Subject: [PATCH] added concatenation query building for placeholder --- service/configurations/PlaceHolder.js | 14 +++-- .../service/configurations/PlaceHolder.js | 53 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/service/configurations/PlaceHolder.js b/service/configurations/PlaceHolder.js index 8d27c4c0..c25f8abc 100644 --- a/service/configurations/PlaceHolder.js +++ b/service/configurations/PlaceHolder.js @@ -12,9 +12,17 @@ class PlaceHolder extends ServiceConfiguration { } getParameters(req) { - const parameters = { - text: req.clean.text - }; + const parameters = {}; + + if (_.has(req.clean.parsed_text, 'street')) { + // assemble all these fields into a space-delimited string + parameters.text = _.values(_.pick(req.clean.parsed_text, + ['neighbourhood', 'borough', 'city', 'county', 'state', 'country'])).join(' '); + + } else { + parameters.text = req.clean.text; + + } if (_.has(req.clean, 'lang.iso6393')) { parameters.lang = req.clean.lang.iso6393; diff --git a/test/unit/service/configurations/PlaceHolder.js b/test/unit/service/configurations/PlaceHolder.js index 02cedfa7..9391d413 100644 --- a/test/unit/service/configurations/PlaceHolder.js +++ b/test/unit/service/configurations/PlaceHolder.js @@ -126,6 +126,59 @@ module.exports.tests.all = (test, common) => { }); + test('existence of street in req.clean.parsed_text should assemble text parameter from admin fields', (t) => { + const configBlob = { + url: 'http://localhost:1234', + }; + + const placeholder = new PlaceHolder(configBlob); + + const req = { + clean: { + text: 'text value', + parsed_text: { + street: 'street value', + neighbourhood: 'neighbourhood value', + borough: 'borough value', + city: 'city value', + county: 'county value', + state: 'state value', + country: 'country value' + } + } + }; + + t.deepEquals(placeholder.getParameters(req), { + text: 'neighbourhood value borough value city value county value state value country value' + }); + t.end(); + + }); + + test('existence of street in req.clean.parsed_text should assemble text parameter from defined admin fields', (t) => { + const configBlob = { + url: 'http://localhost:1234', + }; + + const placeholder = new PlaceHolder(configBlob); + + const req = { + clean: { + text: 'text value', + parsed_text: { + street: 'street value', + country: 'country value' + } + } + }; + + t.deepEquals(placeholder.getParameters(req), { + text: 'country value' + }); + t.end(); + + }); + }; module.exports.all = (tape, common) => {