diff --git a/sanitizer/_synthesize_analysis.js b/sanitizer/_synthesize_analysis.js index 788132ec..04ffeb34 100644 --- a/sanitizer/_synthesize_analysis.js +++ b/sanitizer/_synthesize_analysis.js @@ -1,7 +1,15 @@ const _ = require('lodash'); -const fields = ['address', 'neighbourhood', 'borough', 'city', 'county', - 'state', 'postalcode', 'country']; +const fields = { + 'address': 'address', + 'neighbourhood': 'neighbourhood', + 'borough': 'borough', + 'locality': 'city', + 'county': 'county', + 'region': 'state', + 'postalcode': 'postalcode', + 'country': 'country' +}; function normalizeWhitespaceToSingleSpace(val) { return _.replace(_.trim(val), /\s+/g, ' '); @@ -18,9 +26,9 @@ function sanitize( raw, clean ){ const messages = { errors: [], warnings: [] }; // collect all the valid values into a single object - clean.parsed_text = fields.reduce( (o, f) => { + clean.parsed_text = Object.keys(fields).reduce( (o, f) => { if (_.isString(raw[f]) && !_.isEmpty(_.trim(raw[f]))) { - o[f] = normalizeWhitespaceToSingleSpace(raw[f]); + o[fields[f]] = normalizeWhitespaceToSingleSpace(raw[f]); } return o; @@ -32,7 +40,7 @@ function sanitize( raw, clean ){ } else if (_.isEmpty(Object.keys(clean.parsed_text))) { messages.errors.push( - `at least one of the following fields is required: ${fields.join(', ')}`); + `at least one of the following fields is required: ${Object.keys(fields).join(', ')}`); } return messages; diff --git a/test/unit/sanitizer/_synthesize_analysis.js b/test/unit/sanitizer/_synthesize_analysis.js index d137ad49..20f05fc0 100644 --- a/test/unit/sanitizer/_synthesize_analysis.js +++ b/test/unit/sanitizer/_synthesize_analysis.js @@ -10,9 +10,9 @@ module.exports.tests.text_parser = function(test, common) { address: ' \t address \t value \t ', neighbourhood: ' \t neighbourhood \t value \t ', borough: ' \t borough \t value \t ', - city: ' \t city \t value \t ', + locality: ' \t locality \t value \t ', county: ' \t county \t value \t ', - state: ' \t state \t value \t ', + region: ' \t region \t value \t ', postalcode: ' \t postalcode \t value \t ', country: ' \t country \t value \t ' }; @@ -24,9 +24,9 @@ module.exports.tests.text_parser = function(test, common) { address: 'address value', neighbourhood: 'neighbourhood value', borough: 'borough value', - city: 'city value', + city: 'locality value', county: 'county value', - state: 'state value', + state: 'region value', postalcode: 'postalcode value', country: 'country value' } @@ -51,9 +51,9 @@ module.exports.tests.text_parser = function(test, common) { address: getInvalidValue(), neighbourhood: getInvalidValue(), borough: getInvalidValue(), - city: getInvalidValue(), + locality: getInvalidValue(), county: getInvalidValue(), - state: getInvalidValue(), + region: getInvalidValue(), postalcode: getInvalidValue(), country: getInvalidValue() }; @@ -68,7 +68,7 @@ module.exports.tests.text_parser = function(test, common) { t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, ['at least one of the following fields is required: ' + - 'address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); + 'address, neighbourhood, borough, locality, county, region, postalcode, country'], 'no errors'); t.deepEquals(messages.warnings, [], 'no warnings'); t.end(); @@ -85,7 +85,7 @@ module.exports.tests.text_parser = function(test, common) { t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, ['at least one of the following fields is required: ' + - 'address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); + 'address, neighbourhood, borough, locality, county, region, postalcode, country'], 'no errors'); t.deepEquals(messages.warnings, [], 'no warnings'); t.end();