Browse Source

treat undefined text-analyzer response as no house number available

pull/977/head
Stephen Hess 7 years ago
parent
commit
42097fafb2
  1. 8
      sanitizer/_synthesize_analysis.js
  2. 30
      test/unit/sanitizer/_synthesize_analysis.js

8
sanitizer/_synthesize_analysis.js

@ -27,12 +27,8 @@ function isPostalCodeOnly(parsed_text) {
// so because we're treating the entire field as a street address, it's safe
// to assume that an identified postcode is actually a house number.
function getHouseNumberField(analyzed_address) {
for (var field of ['number', 'postalcode']) {
if (analyzed_address.hasOwnProperty(field)) {
return field;
}
}
// return the first field available in the libpostal response, undefined if none
return _.find(['number', 'postalcode'], _.partial(_.has, analyzed_address));
}
function _sanitize( raw, clean ){

30
test/unit/sanitizer/_synthesize_analysis.js

@ -233,6 +233,36 @@ module.exports.tests.text_parser = function(test, common) {
});
test('text_analyzer returning undefined on address resolution should treat as if no house number field was found', t => {
var sanitizer = proxyquire('../../../sanitizer/_synthesize_analysis', {
'pelias-text-analyzer': { parse: function(query) {
t.equals(query, 'Street Value');
return undefined;
}
}});
const raw = {
address: 'Street Value'
};
const clean = {};
const expected_clean = {
parsed_text: {
street: 'Street Value'
}
};
const messages = sanitizer().sanitize(raw, clean);
t.deepEquals(clean, expected_clean);
t.deepEquals(messages.errors, [], 'no errors');
t.deepEquals(messages.warnings, [], 'no warnings');
t.end();
});
test('return an array of expected parameters in object form for validation', function (t) {
const sanitizer = require('../../../sanitizer/_synthesize_analysis');
const expected = [

Loading…
Cancel
Save