diff --git a/sanitizer/_synthesize_analysis.js b/sanitizer/_synthesize_analysis.js index 1717fd74..194fc14d 100644 --- a/sanitizer/_synthesize_analysis.js +++ b/sanitizer/_synthesize_analysis.js @@ -1,7 +1,7 @@ const _ = require('lodash'); -const fields = ['query', 'address', 'neighbourhood', 'borough', 'city', - 'county', 'state', 'postalcode', 'country']; +const fields = ['address', 'neighbourhood', 'borough', 'city', 'county', + 'state', 'postalcode', 'country']; function normalizeWhitespaceToSingleSpace(val) { return _.replace(_.trim(val), /\s+/g, ' '); @@ -23,8 +23,8 @@ function sanitize( raw, clean ){ }, {}); if (_.isEmpty(Object.keys(clean.parsed_text))) { - messages.errors.push('at least one of the following fields is required: ' + - 'query, address, neighbourhood, borough, city, county, state, postalcode, country'); + messages.errors.push( + `at least one of the following fields is required: ${fields.join(', ')}`); } return messages; diff --git a/test/unit/sanitizer/_synthesize_analysis.js b/test/unit/sanitizer/_synthesize_analysis.js index b2e5915b..f30f35cc 100644 --- a/test/unit/sanitizer/_synthesize_analysis.js +++ b/test/unit/sanitizer/_synthesize_analysis.js @@ -1,11 +1,11 @@ -var sanitizer = require('../../../sanitizer/_synthesize_analysis'); -var _ = require('lodash'); +const sanitizer = require('../../../sanitizer/_synthesize_analysis'); +const _ = require('lodash'); module.exports.tests = {}; module.exports.tests.text_parser = function(test, common) { test('all variables should be parsed', function(t) { - var raw = { + const raw = { query: ' \t query \t value \t ', address: ' \t address \t value \t ', neighbourhood: ' \t neighbourhood \t value \t ', @@ -17,11 +17,10 @@ module.exports.tests.text_parser = function(test, common) { country: ' \t country \t value \t ' }; - var clean = {}; + const clean = {}; - var expected_clean = { + const expected_clean = { parsed_text: { - query: 'query value', address: 'address value', neighbourhood: 'neighbourhood value', borough: 'borough value', @@ -33,7 +32,7 @@ module.exports.tests.text_parser = function(test, common) { } }; - var messages = sanitizer(raw, clean); + const messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, [], 'no errors'); @@ -48,8 +47,7 @@ module.exports.tests.text_parser = function(test, common) { return _.sample([{}, [], false, '', ' \t ', 17, undefined]); } - var raw = { - query: getInvalidValue(), + const raw = { address: getInvalidValue(), neighbourhood: getInvalidValue(), borough: getInvalidValue(), @@ -60,34 +58,34 @@ module.exports.tests.text_parser = function(test, common) { country: getInvalidValue() }; - var clean = {}; + const clean = {}; - var expected_clean = { + const expected_clean = { parsed_text: {} }; - var messages = sanitizer(raw, clean); + const messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, ['at least one of the following fields is required: ' + - 'query, address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); + 'address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); t.deepEquals(messages.warnings, [], 'no warnings'); t.end(); }); test('no supplied fields should return error', function(t) { - var raw = {}; + const raw = {}; - var clean = {}; + const clean = {}; - var expected_clean = { parsed_text: {} }; + const expected_clean = { parsed_text: {} }; - var messages = sanitizer(raw, clean); + const messages = sanitizer(raw, clean); t.deepEquals(clean, expected_clean); t.deepEquals(messages.errors, ['at least one of the following fields is required: ' + - 'query, address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); + 'address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); t.deepEquals(messages.warnings, [], 'no warnings'); t.end(); @@ -100,7 +98,7 @@ module.exports.all = function (tape, common) { return tape('sanitizer _synthesize_analysis: ' + name, testFunction); } - for( var testCase in module.exports.tests ){ + for( const testCase in module.exports.tests ){ module.exports.tests[testCase](test, common); } };