From 76d88b62b46cf77764544115726d1d0532828403 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 11 Oct 2018 12:22:05 -0400 Subject: [PATCH 1/4] fix(tests): Sanitizer tests should use faked config Otherwise a user's own pelias.json settings can cause tests to fail --- test/unit/sanitizer/_sources.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/unit/sanitizer/_sources.js b/test/unit/sanitizer/_sources.js index e14f88dc..07f894ad 100644 --- a/test/unit/sanitizer/_sources.js +++ b/test/unit/sanitizer/_sources.js @@ -1,5 +1,15 @@ -var type_mapping = require('../../../helper/type_mapping'); -var sanitizer = require( '../../../sanitizer/_targets' )('sources', type_mapping.source_mapping); +const fake_type_mapping = { + osm:['openstreetmap'], + oa: ['openaddresses'], + gn: ['geonames'], + wof: ['whosonfirst'], + openstreetmap:['openstreetmap'], + openaddresses: ['openaddresses'], + geonames: ['geonames'], + whosonfirst: ['whosonfirst'] +}; + +var sanitizer = require( '../../../sanitizer/_targets' )('sources', fake_type_mapping); var success_messages = { error: false }; From c9f89fee3d26154a4e021484da28a597d5b369ee Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 11 Oct 2018 12:23:17 -0400 Subject: [PATCH 2/4] Whitespace --- test/unit/helper/type_mapping.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index 25b06d0f..5432e1e7 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -4,16 +4,16 @@ var type_mapping = require('../../../helper/type_mapping'); module.exports.tests = {}; module.exports.tests.interfaces = function(test, common) { - + test('complete sources', function(t) { t.deepEquals(type_mapping.sources, [ 'openstreetmap', 'openaddresses', 'geonames', 'whosonfirst' ]); t.end(); }); test('complete layers', function(t) { - t.deepEquals(type_mapping.layers, [ 'address', 'venue', 'street', 'country', 'macroregion', - 'region', 'county', 'localadmin', 'locality', 'borough', 'neighbourhood', 'continent', - 'empire', 'dependency', 'macrocounty', 'macrohood', 'microhood', 'disputed', + t.deepEquals(type_mapping.layers, [ 'address', 'venue', 'street', 'country', 'macroregion', + 'region', 'county', 'localadmin', 'locality', 'borough', 'neighbourhood', 'continent', + 'empire', 'dependency', 'macrocounty', 'macrohood', 'microhood', 'disputed', 'postalcode', 'ocean', 'marinearea' ]); t.end(); }); @@ -46,8 +46,8 @@ module.exports.tests.interfaces = function(test, common) { test('complete layer mapping', function(t) { t.deepEquals(type_mapping.layer_mapping, { - coarse: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region', - 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', + coarse: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region', + 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', 'neighbourhood', 'microhood', 'disputed', 'postalcode', 'continent', 'ocean', 'marinearea' ], address: [ 'address' ], @@ -94,11 +94,11 @@ module.exports.tests.interfaces = function(test, common) { t.deepEquals(type_mapping.layers_by_source, { openstreetmap: [ 'address', 'venue', 'street' ], openaddresses: [ 'address' ], - geonames: [ 'country', 'macroregion', 'region', 'county', 'localadmin', + geonames: [ 'country', 'macroregion', 'region', 'county', 'localadmin', 'locality', 'borough', 'neighbourhood', 'venue' ], - whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', - 'region', 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', - 'borough', 'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode', + whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', + 'region', 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', + 'borough', 'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode', 'continent', 'ocean', 'marinearea' ] }); t.end(); From d5a0b9fc8659e8e1d23d9df472d3af91eb029e61 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 11 Oct 2018 12:23:53 -0400 Subject: [PATCH 3/4] Remove unused library --- test/unit/helper/type_mapping.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index 5432e1e7..f66cef88 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -1,4 +1,3 @@ -var check = require('check-types'); var type_mapping = require('../../../helper/type_mapping'); module.exports.tests = {}; From ff5c66a269bd37f32e779e1fde5672f4b099c9cc Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Thu, 11 Oct 2018 12:35:55 -0400 Subject: [PATCH 4/4] fix(test): Use default pelias-config for type tests Without this change, a user's own `pelias.json` customizations can cause the unit tests to fail. --- helper/type_mapping.js | 2 +- test/unit/helper/type_mapping.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/helper/type_mapping.js b/helper/type_mapping.js index 987aa26a..2e97231c 100644 --- a/helper/type_mapping.js +++ b/helper/type_mapping.js @@ -5,4 +5,4 @@ var tm = new TypeMapping(); tm.load(); // export singleton -module.exports = tm; \ No newline at end of file +module.exports = tm; diff --git a/test/unit/helper/type_mapping.js b/test/unit/helper/type_mapping.js index f66cef88..cc984ec5 100644 --- a/test/unit/helper/type_mapping.js +++ b/test/unit/helper/type_mapping.js @@ -1,4 +1,20 @@ -var type_mapping = require('../../../helper/type_mapping'); +const proxyquire = require('proxyquire').noCallThru(); + +const realPeliasConfig = require('pelias-config'); + +const defaultPeliasConfig = { + generate: function() { + return realPeliasConfig.defaults; + } +}; + +// test the actual module, rather than the singleton wrapper +var TypeMapping = proxyquire('../../../helper/TypeMapping', { + 'pelias-config': defaultPeliasConfig +}); + +const type_mapping = new TypeMapping(); +type_mapping.load(); module.exports.tests = {};