Browse Source

added concatenation query building for placeholder

pull/912/head
Stephen Hess 8 years ago
parent
commit
2363e9d739
  1. 14
      service/configurations/PlaceHolder.js
  2. 53
      test/unit/service/configurations/PlaceHolder.js

14
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;

53
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) => {

Loading…
Cancel
Save