From 96af0070441806f11a78ac1c171f8620a55d59f1 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Tue, 5 Apr 2016 17:30:31 -0700 Subject: [PATCH 1/3] chore(package): update elasticsearch to version 11.0.0 http://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f97df8eb..f54db70c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "async": "^1.5.2", "check-types": "^6.0.0", "cluster2": "git://github.com/missinglink/cluster2.git#node_zero_twelve", - "elasticsearch": "^10.1.3", + "elasticsearch": "^11.0.0", "express": "^4.8.8", "express-http-proxy": "^0.6.0", "extend": "3.0.0", From e6e9c1c574598c4ddddc450c4c8eacd598d7c61d Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 13 Apr 2016 12:07:01 -0400 Subject: [PATCH 2/3] Do not apply local naming conventions to records with no admin info There's no way to decide what to do, and without handling this case the API will return an error. --- middleware/localNamingConventions.js | 3 +++ .../unit/middleware/localNamingConventions.js | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/middleware/localNamingConventions.js b/middleware/localNamingConventions.js index dd026bb3..e2851370 100644 --- a/middleware/localNamingConventions.js +++ b/middleware/localNamingConventions.js @@ -23,6 +23,9 @@ function applyLocalNamingConventions(req, res, next) { // loop through data items and flip relevant number/street res.data.filter(function(place){ + // do nothing for records with no admin info + if (!place.parent || !place.parent.country_a) { return false; } + // relevant for some countries var flip = place.parent.country_a.some(function(country) { return _.includes(flipNumberAndStreetCountries, country); diff --git a/test/unit/middleware/localNamingConventions.js b/test/unit/middleware/localNamingConventions.js index c544abe7..1d4102f0 100644 --- a/test/unit/middleware/localNamingConventions.js +++ b/test/unit/middleware/localNamingConventions.js @@ -77,8 +77,21 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { } }; + var unknownCountryAddress = { + '_id': 'test4', + '_type': 'test', + 'name': { 'default': '123 Main Street' }, + 'center_point': { 'lon': 30.1, 'lat': -50 }, + 'address_parts': { + 'number': '123', + 'street': 'Main Street' + }, + 'parent': { + } + }; + var req = {}, - res = { data: [ ukAddress, deAddress, nlAddress ] }, + res = { data: [ ukAddress, deAddress, nlAddress, unknownCountryAddress ] }, middleware = localNamingConventions(); test('flipNumberAndStreet', function(t) { @@ -96,6 +109,10 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { // this definition comes from pelias configuration t.equal( res.data[2].name.default, 'Keizersgracht 117', 'flipped name' ); + // addresses without a known country (either due to missing data or admin lookup + // being disabled), don't have the name flipped + t.equal( res.data[3].name.default, '123 Main Street', 'standard name'); + t.end(); }); }); From d98973c21f2fb7da55ec22bb4e45e996005c6c86 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 13 Apr 2016 12:14:12 -0400 Subject: [PATCH 3/3] Handle fatal errors in unit tests Due to the way our unit tests are run, a fatal error in the API code that causes the node process to quit with an error will not be picked up by `tap-dot`, and the unit tests will still return a passing status code. This is due to the way status codes from pipes are handled by default. Fortunately, there is an ["unofficial bash strict mode"](http://redsymbol.net/articles/unofficial-bash-strict-mode/) that helps fix this sort of thing, and by running our unit tests with a few tweaks we can ensure that any failure in the unit tests is captured. --- bin/units | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100755 bin/units diff --git a/bin/units b/bin/units new file mode 100755 index 00000000..b011e2ee --- /dev/null +++ b/bin/units @@ -0,0 +1,5 @@ +#!/bin/bash + +set -euo pipefail + +node test/unit/run.js | ./node_modules/.bin/tap-dot diff --git a/package.json b/package.json index f54db70c..0c0cc1f7 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "start": "node index.js", "test": "npm run unit", - "unit": "node test/unit/run.js | tap-dot", + "unit": "./bin/units", "ciao": "node node_modules/ciao/bin/ciao -c test/ciao.json test/ciao", "coverage": "node_modules/.bin/istanbul cover test/unit/run.js", "audit": "npm shrinkwrap; node node_modules/nsp/bin/nspCLI.js audit-shrinkwrap; rm npm-shrinkwrap.json;",