From c7a5355ce3aaaf7bdc07feba1c01b96d569c287c Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 12 Aug 2017 10:35:42 +0000 Subject: [PATCH 01/16] chore(package): update tmp to version 0.0.33 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb4e2b19..cdfd16c6 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "source-map": "^0.5.6", "tap-dot": "1.0.5", "tape": "^4.5.1", - "tmp": "0.0.31", + "tmp": "0.0.33", "uglify-js": "^3.0.4" }, "pre-commit": [ From 98440bbc6fbd49165bdd7c8ea7035124c46557f0 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 16 Aug 2017 06:24:22 +0000 Subject: [PATCH 02/16] chore(package): update semantic-release to version 7.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb4e2b19..2e2aa699 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "pelias-mock-logger": "1.1.1", "precommit-hook": "^3.0.0", "proxyquire": "^1.7.10", - "semantic-release": "^6.3.2", + "semantic-release": "^7.0.1", "source-map": "^0.5.6", "tap-dot": "1.0.5", "tape": "^4.5.1", From 875dd0730799f801cfcfe073dbfc176e1f4ef742 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 23 Aug 2017 16:44:06 +0000 Subject: [PATCH 03/16] fix(package): update pelias-text-analyzer to version 1.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index acf904c3..695cd935 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "pelias-model": "5.0.0", "pelias-query": "9.0.0", "pelias-sorting": "1.0.1", - "pelias-text-analyzer": "1.9.0", + "pelias-text-analyzer": "1.9.1", "predicates": "^1.0.1", "retry": "^0.10.1", "stats-lite": "^2.0.4", From 48d94c636eb69b4a3c58169dd768cf39cf3d0f66 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Wed, 23 Aug 2017 16:50:34 +0000 Subject: [PATCH 04/16] fix(package): update pelias-model to version 5.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index acf904c3..8a4ae2dc 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "pelias-labels": "1.6.0", "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.2.0", - "pelias-model": "5.0.0", + "pelias-model": "5.0.1", "pelias-query": "9.0.0", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.9.0", From 9f817ae4289cbc1238df7758f6c2e065c8a8bc7c Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 28 Aug 2017 14:06:03 -0400 Subject: [PATCH 05/16] Inherit from libpostal_baseimage --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f696320e..8bef0415 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM node:4.6.0 +# base image +FROM pelias/libpostal_baseimage MAINTAINER Pelias EXPOSE 3100 From 4f7b041f721775c746c2c3a8781a1994fbfdf46a Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 28 Aug 2017 14:10:50 -0400 Subject: [PATCH 06/16] Use best practices for CMD parameters See the section at https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/ --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8bef0415..f5abd602 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,4 +26,5 @@ ADD pelias.json.docker pelias.json RUN chown -R 9999:9999 ${WORK} USER 9999 -CMD npm start +# start service +CMD [ "npm", "start" ] From a658c34dd4d9011aa0773be5796720f7c4da69f4 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 28 Aug 2017 14:11:56 -0400 Subject: [PATCH 07/16] Add CircleCI configuration Connects https://github.com/pelias/dockerfiles/issues/21 --- .circleci/config.yml | 12 ++++++++++++ .circleci/docker.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .circleci/docker.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..8aeea9df --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,12 @@ +version: 2 +jobs: + build: + working_directory: /app + docker: + - image: docker:17.05.0-ce-git + steps: + - checkout + - setup_remote_docker + - run: + name: Build and push image to Docker Hub + command: sh .circleci/docker.sh diff --git a/.circleci/docker.sh b/.circleci/docker.sh new file mode 100644 index 00000000..562de3db --- /dev/null +++ b/.circleci/docker.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -u + +# collect params from ENV vars +DATE=`date +%Y-%m-%d` +DOCKER_REPOSITORY="pelias" +DOCKER_PROJECT="${DOCKER_REPOSITORY}/${CIRCLE_PROJECT_REPONAME}" + +# the name of the image that represents the "branch", that is an image that will be updated over time with the git branch +# the production branch is changed to "latest", otherwise the git branch becomes the name of the version +if [[ "${CIRCLE_BRANCH}" == "production" ]]; then + DOCKER_BRANCH_IMAGE_VERSION="latest" +else + DOCKER_BRANCH_IMAGE_VERSION="${CIRCLE_BRANCH}" +fi +DOCKER_BRANCH_IMAGE_NAME="${DOCKER_PROJECT}:${DOCKER_BRANCH_IMAGE_VERSION}" + +# the name of the image that represents the "tag", that is an image that is named with the date and git commit and will never be changed +DOCKER_TAG_IMAGE_VERSION="${CIRCLE_BRANCH}-${DATE}-${CIRCLE_SHA1}" +DOCKER_TAG_IMAGE_NAME="${DOCKER_PROJECT}:${DOCKER_TAG_IMAGE_VERSION}" + +# build image and login to docker hub +docker build -t $DOCKER_PROJECT . +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" + +# copy the image to each of the two tags, and push +docker tag $DOCKER_PROJECT $DOCKER_BRANCH_IMAGE_NAME +docker tag $DOCKER_PROJECT $DOCKER_TAG_IMAGE_NAME +docker push $DOCKER_BRANCH_IMAGE_NAME +docker push $DOCKER_TAG_IMAGE_NAME From d06077a17392ab3ca21a1413ce2a3d8b15726a5f Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 28 Aug 2017 14:17:22 -0400 Subject: [PATCH 08/16] Add dockerignore file For now, only exclude .git directory, which weighs in at 27MB. --- .dockerignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..6b8710a7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git From fba8c5c41718d353dde5677327be3617b1275565 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 28 Aug 2017 14:28:30 -0400 Subject: [PATCH 09/16] Remove Docker specific pelias.json There is a default file managed by the pelias baseimage. --- Dockerfile | 2 -- pelias.json.docker | 18 ------------------ 2 files changed, 20 deletions(-) delete mode 100644 pelias.json.docker diff --git a/Dockerfile b/Dockerfile index f5abd602..063c2c92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,6 @@ RUN npm install && \ npm test && \ chmod -R a+rwX . -ADD pelias.json.docker pelias.json - # Don't run as root, because there's no reason to (https://docs.docker.com/engine/articles/dockerfile_best-practices/#user). # This also reveals permission problems on local Docker. RUN chown -R 9999:9999 ${WORK} diff --git a/pelias.json.docker b/pelias.json.docker deleted file mode 100644 index 7d012f02..00000000 --- a/pelias.json.docker +++ /dev/null @@ -1,18 +0,0 @@ -{ - "esclient": { - "hosts": [ - { - "env": "production", - "protocol": "http", - "host": "pelias-data-container", - "port": 9200 - }, - { - "env": "production", - "protocol": "http", - "host": "pelias-data-container", - "port": 9300 - } - ] - } -} From 171b529b81690760db3620b76aab4311accd470d Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 29 Aug 2017 11:20:10 -0400 Subject: [PATCH 10/16] Use new maintainer label format --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 063c2c92..0a3d601f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ # base image FROM pelias/libpostal_baseimage -MAINTAINER Pelias + +# maintainer information +LABEL maintainer="pelias@mapzen.com" EXPOSE 3100 -LABEL io.openshift.expose-services 3100:http # Where the app is built and run inside the docker fs ENV WORK=/opt/pelias From 4a48bf54e9922327083c24d4626354e05bb73e87 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 29 Aug 2017 11:20:22 -0400 Subject: [PATCH 11/16] Use COPY instead of ADD It has more predictable behavior: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#add-or-copy --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0a3d601f..041f00dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV WORK=/opt/pelias ENV HOME=/opt/pelias WORKDIR ${WORK} -ADD . ${WORK} +COPY . ${WORK} # Build and set permissions for arbitrary non-root user RUN npm install && \ From a61a3f7e6ce6978596f7bba23171ffd6ca7ba56d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 29 Aug 2017 18:24:15 +0000 Subject: [PATCH 12/16] fix(package): update pelias-query to version 9.1.0 Closes #844 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89682a7e..43a4f7e3 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "pelias-logger": "0.2.0", "pelias-microservice-wrapper": "1.2.0", "pelias-model": "5.0.1", - "pelias-query": "9.0.0", + "pelias-query": "9.1.0", "pelias-sorting": "1.0.1", "pelias-text-analyzer": "1.9.1", "predicates": "^1.0.1", From fb9b76ef6fce38f7af1c2ace35ff05669042b517 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 30 Aug 2017 13:21:30 -0400 Subject: [PATCH 13/16] Add default route redirecting to /v1 This makes the root URL of the API a bit more friendly Fixes https://github.com/pelias/api/issues/961 --- app.js | 5 ++++- routes/default.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 routes/default.js diff --git a/app.js b/app.js index 342f00eb..b6355b95 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,3 @@ - var app = require('express')(); var peliasConfig = require( 'pelias-config' ).generate(require('./schema')); @@ -16,6 +15,10 @@ app.use( require('./middleware/jsonp') ); /** ----------------------- routes ----------------------- **/ + +var defaultRoutes = require('./routes/default'); +defaultRoutes.addRoutes(app); + var v1 = require('./routes/v1'); v1.addRoutes(app, peliasConfig); diff --git a/routes/default.js b/routes/default.js new file mode 100644 index 00000000..e82f7a0f --- /dev/null +++ b/routes/default.js @@ -0,0 +1,12 @@ +// set up routes that are outside any particular API version +function addRoutes(app) { + function redirectToV1(req, res, next) { + res.redirect(301, '/v1'); + } + + // default root URL traffic to V1 root + // which has a link to the readme and other helpful info + app.get('/', redirectToV1); +} + +module.exports.addRoutes = addRoutes; From d3ff5a57de06d3ce3bb464d837b98ce53f401b74 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Thu, 31 Aug 2017 12:33:23 +0200 Subject: [PATCH 14/16] Make .dockerignore node-specific Add to dockerignore some node-specific things (like node_modules). --- .dockerignore | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/.dockerignore b/.dockerignore index 6b8710a7..f095254f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,51 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# Git .git From 30b7290990e3381d717fb0622f860f41d9947703 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Thu, 31 Aug 2017 14:38:48 -0400 Subject: [PATCH 15/16] added stub request_language sanitizer that just allows lang param --- sanitizer/_request_language.js | 15 +++++++++ sanitizer/autocomplete.js | 3 +- sanitizer/nearby.js | 3 +- sanitizer/place.js | 3 +- sanitizer/reverse.js | 3 +- sanitizer/search.js | 3 +- sanitizer/structured_geocoding.js | 3 +- test/unit/run.js | 1 + test/unit/sanitizer/_request_language.js | 35 +++++++++++++++++++++ test/unit/sanitizer/autocomplete.js | 11 ++++++- test/unit/sanitizer/nearby.js | 11 ++++++- test/unit/sanitizer/place.js | 11 ++++++- test/unit/sanitizer/reverse.js | 11 ++++++- test/unit/sanitizer/search.js | 11 ++++++- test/unit/sanitizer/structured_geocoding.js | 11 ++++++- 15 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 sanitizer/_request_language.js create mode 100644 test/unit/sanitizer/_request_language.js diff --git a/sanitizer/_request_language.js b/sanitizer/_request_language.js new file mode 100644 index 00000000..bbc346c1 --- /dev/null +++ b/sanitizer/_request_language.js @@ -0,0 +1,15 @@ +// this sanitizer exists solely to allow `lang` as a request parameter +function _sanitize( raw, clean ){ + // error & warning messages + return { errors: [], warnings: [] }; +} + +function _expected(){ + return [{ 'name': 'lang' }]; +} + +// export function +module.exports = () => ({ + sanitize: _sanitize, + expected: _expected +}); diff --git a/sanitizer/autocomplete.js b/sanitizer/autocomplete.js index c26a3b44..26c5d0ac 100644 --- a/sanitizer/autocomplete.js +++ b/sanitizer/autocomplete.js @@ -17,7 +17,8 @@ module.exports.middleware = (_api_pelias_config) => { location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), geo_autocomplete: require('../sanitizer/_geo_autocomplete')(), boundary_country: require('../sanitizer/_boundary_country')(), - categories: require('../sanitizer/_categories')() + categories: require('../sanitizer/_categories')(), + request_language: require('../sanitizer/_request_language')() }; return ( req, res, next ) => { diff --git a/sanitizer/nearby.js b/sanitizer/nearby.js index 8aa727bd..1cd3b276 100644 --- a/sanitizer/nearby.js +++ b/sanitizer/nearby.js @@ -15,7 +15,8 @@ var sanitizers = { private: require('../sanitizer/_flag_bool')('private', false), geo_reverse: require('../sanitizer/_geo_reverse')(), boundary_country: require('../sanitizer/_boundary_country')(), - categories: require('../sanitizer/_categories')() + categories: require('../sanitizer/_categories')(), + request_language: require('../sanitizer/_request_language')() }; // middleware diff --git a/sanitizer/place.js b/sanitizer/place.js index ce220d64..4d158dc3 100644 --- a/sanitizer/place.js +++ b/sanitizer/place.js @@ -4,7 +4,8 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), debug: require('../sanitizer/_debug')(), ids: require('../sanitizer/_ids')(), - private: require('../sanitizer/_flag_bool')('private', false) + private: require('../sanitizer/_flag_bool')('private', false), + request_language: require('../sanitizer/_request_language')() }; // middleware diff --git a/sanitizer/reverse.js b/sanitizer/reverse.js index f43d0845..457e81a5 100644 --- a/sanitizer/reverse.js +++ b/sanitizer/reverse.js @@ -13,7 +13,8 @@ var sanitizeAll = require('../sanitizer/sanitizeAll'), size: require('../sanitizer/_size')(/* use defaults*/), private: require('../sanitizer/_flag_bool')('private', false), geo_reverse: require('../sanitizer/_geo_reverse')(), - boundary_country: require('../sanitizer/_boundary_country')() + boundary_country: require('../sanitizer/_boundary_country')(), + request_language: require('../sanitizer/_request_language')() }; // middleware diff --git a/sanitizer/search.js b/sanitizer/search.js index c8e7282f..008ae693 100644 --- a/sanitizer/search.js +++ b/sanitizer/search.js @@ -18,7 +18,8 @@ module.exports.middleware = (_api_pelias_config) => { boundary_country: require('../sanitizer/_boundary_country')(), categories: require('../sanitizer/_categories')(), // this can go away once geonames has been abrogated - geonames_warnings: require('../sanitizer/_geonames_warnings')() + geonames_warnings: require('../sanitizer/_geonames_warnings')(), + request_language: require('../sanitizer/_request_language')() }; return ( req, res, next ) => { diff --git a/sanitizer/structured_geocoding.js b/sanitizer/structured_geocoding.js index 388949ea..670a26aa 100644 --- a/sanitizer/structured_geocoding.js +++ b/sanitizer/structured_geocoding.js @@ -19,7 +19,8 @@ module.exports.middleware = (_api_pelias_config) => { location_bias: require('../sanitizer/_location_bias')(_api_pelias_config.defaultParameters), geo_search: require('../sanitizer/_geo_search')(), boundary_country: require('../sanitizer/_boundary_country')(), - categories: require('../sanitizer/_categories')() + categories: require('../sanitizer/_categories')(), + request_language: require('../sanitizer/_request_language')() }; return ( req, res, next ) => { diff --git a/test/unit/run.js b/test/unit/run.js index 8299672d..e09bc037 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -76,6 +76,7 @@ var tests = [ require('./sanitizer/_layers'), require('./sanitizer/_location_bias'), require('./sanitizer/_city_name_standardizer'), + require('./sanitizer/_request_language'), require('./sanitizer/_single_scalar_parameters'), require('./sanitizer/_size'), require('./sanitizer/_sources'), diff --git a/test/unit/sanitizer/_request_language.js b/test/unit/sanitizer/_request_language.js new file mode 100644 index 00000000..0261859a --- /dev/null +++ b/test/unit/sanitizer/_request_language.js @@ -0,0 +1,35 @@ +const sanitizer = require('../../../sanitizer/_request_language')(); + +module.exports.tests = {}; + +module.exports.tests.do_nothing = (test, common) => { + test('sanitize should return empty warnings/erros', t => { + const messages = sanitizer.sanitize(); + + t.deepEquals(messages.errors, [], 'no errors'); + t.deepEquals(messages.warnings, [], 'no warnings'); + t.end(); + + }); + +}; + +module.exports.tests.expected = (test, common) => { + test('expected should contain only \'lang\'', t => { + const expected = sanitizer.expected(); + + t.deepEquals(expected, [{'name': 'lang'}]); + t.end(); + + }); +}; + +module.exports.all = (tape, common) => { + function test(name, testFunction) { + return tape(`SANITIZE _request_language: ${name}`, testFunction); + } + + for( const testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; diff --git a/test/unit/sanitizer/autocomplete.js b/test/unit/sanitizer/autocomplete.js index dadb546e..4ca62b97 100644 --- a/test/unit/sanitizer/autocomplete.js +++ b/test/unit/sanitizer/autocomplete.js @@ -120,6 +120,14 @@ module.exports.tests.sanitizers = function(test, common) { return { errors: [], warnings: [] }; } }; + }, + '../sanitizer/_request_language': () => { + return { + sanitize: () => { + called_sanitizers.push('_request_language'); + return { errors: [], warnings: [] }; + } + }; } }); @@ -136,7 +144,8 @@ module.exports.tests.sanitizers = function(test, common) { '_location_bias', '_geo_autocomplete', '_boundary_country', - '_categories' + '_categories', + '_request_language' ]; const req = {}; diff --git a/test/unit/sanitizer/nearby.js b/test/unit/sanitizer/nearby.js index a9ea6db6..cff81b71 100644 --- a/test/unit/sanitizer/nearby.js +++ b/test/unit/sanitizer/nearby.js @@ -109,6 +109,14 @@ module.exports.tests.sanitize = function(test, common) { return { errors: [], warnings: [] }; } }; + }, + '../sanitizer/_request_language': () => { + return { + sanitize: () => { + called_sanitizers.push('_request_language'); + return { errors: [], warnings: [] }; + } + }; } }); @@ -124,7 +132,8 @@ module.exports.tests.sanitize = function(test, common) { '_flag_bool', '_geo_reverse', '_boundary_country', - '_categories' + '_categories', + '_request_language' ]; const req = {}; diff --git a/test/unit/sanitizer/place.js b/test/unit/sanitizer/place.js index 2a47e391..7e0f9c8d 100644 --- a/test/unit/sanitizer/place.js +++ b/test/unit/sanitizer/place.js @@ -45,6 +45,14 @@ module.exports.tests.sanitize = function(test, common) { } else { throw new Error('incorrect parameters passed to _flag_bool'); } + }, + '../sanitizer/_request_language': () => { + return { + sanitize: () => { + called_sanitizers.push('_request_language'); + return { errors: [], warnings: [] }; + } + }; } }); @@ -52,7 +60,8 @@ module.exports.tests.sanitize = function(test, common) { '_single_scalar_parameters', '_debug', '_ids', - '_flag_bool' + '_flag_bool', + '_request_language' ]; const req = {}; diff --git a/test/unit/sanitizer/reverse.js b/test/unit/sanitizer/reverse.js index aafaa6e9..c979ec67 100644 --- a/test/unit/sanitizer/reverse.js +++ b/test/unit/sanitizer/reverse.js @@ -101,6 +101,14 @@ module.exports.tests.sanitize = function(test, common) { return { errors: [], warnings: [] }; } }; + }, + '../sanitizer/_request_language': () => { + return { + sanitize: () => { + called_sanitizers.push('_request_language'); + return { errors: [], warnings: [] }; + } + }; } }); @@ -115,7 +123,8 @@ module.exports.tests.sanitize = function(test, common) { '_size', '_flag_bool', '_geo_reverse', - '_boundary_country' + '_boundary_country', + '_request_language' ]; const req = {}; diff --git a/test/unit/sanitizer/search.js b/test/unit/sanitizer/search.js index e4192029..9ac585ad 100644 --- a/test/unit/sanitizer/search.js +++ b/test/unit/sanitizer/search.js @@ -133,6 +133,14 @@ module.exports.tests.sanitize = (test, common) => { } } }; + }, + '../sanitizer/_request_language': () => { + return { + sanitize: () => { + called_sanitizers.push('_request_language'); + return { errors: [], warnings: [] }; + } + }; } }); @@ -151,7 +159,8 @@ module.exports.tests.sanitize = (test, common) => { '_geo_search', '_boundary_country', '_categories', - '_geonames_warnings' + '_geonames_warnings', + '_request_language' ]; const req = {}; diff --git a/test/unit/sanitizer/structured_geocoding.js b/test/unit/sanitizer/structured_geocoding.js index a50ff3ef..963aa21d 100644 --- a/test/unit/sanitizer/structured_geocoding.js +++ b/test/unit/sanitizer/structured_geocoding.js @@ -137,6 +137,14 @@ module.exports.tests.sanitize = function(test, common) { } } }; + }, + '../sanitizer/_request_language': () => { + return { + sanitize: () => { + called_sanitizers.push('_request_language'); + return { errors: [], warnings: [] }; + } + }; } }); @@ -155,7 +163,8 @@ module.exports.tests.sanitize = function(test, common) { '_location_bias', '_geo_search', '_boundary_country', - '_categories' + '_categories', + '_request_language' ]; var req = {}; From 42097fafb2a2e1c61a38fc936ffa921d9367684c Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Tue, 5 Sep 2017 14:52:57 -0400 Subject: [PATCH 16/16] treat undefined text-analyzer response as no house number available --- sanitizer/_synthesize_analysis.js | 8 ++---- test/unit/sanitizer/_synthesize_analysis.js | 30 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/sanitizer/_synthesize_analysis.js b/sanitizer/_synthesize_analysis.js index a4764549..3822d9d4 100644 --- a/sanitizer/_synthesize_analysis.js +++ b/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 ){ diff --git a/test/unit/sanitizer/_synthesize_analysis.js b/test/unit/sanitizer/_synthesize_analysis.js index 287b0e0d..64243dc9 100644 --- a/test/unit/sanitizer/_synthesize_analysis.js +++ b/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 = [