Browse Source

Merge branch 'master' of github.com:pelias/api into pelias-api-218

pull/502/head
Diana Shkolnikov 9 years ago
parent
commit
d6e51eff5c
  1. 5
      bin/units
  2. 3
      middleware/localNamingConventions.js
  3. 4
      package.json
  4. 19
      test/unit/middleware/localNamingConventions.js

5
bin/units

@ -0,0 +1,5 @@
#!/bin/bash
set -euo pipefail
node test/unit/run.js | ./node_modules/.bin/tap-dot

3
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);

4
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;",
@ -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",

19
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();
});
});

Loading…
Cancel
Save