Browse Source

Merge pull request #1204 from pelias/proxyquire-config

Use default pelias-config values for type mapping tests
pull/1208/head
Julian Simioni 6 years ago committed by GitHub
parent
commit
75b32123d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      helper/type_mapping.js
  2. 39
      test/unit/helper/type_mapping.js
  3. 14
      test/unit/sanitizer/_sources.js

2
helper/type_mapping.js

@ -5,4 +5,4 @@ var tm = new TypeMapping();
tm.load(); tm.load();
// export singleton // export singleton
module.exports = tm; module.exports = tm;

39
test/unit/helper/type_mapping.js

@ -1,19 +1,34 @@
var check = require('check-types'); const proxyquire = require('proxyquire').noCallThru();
var type_mapping = require('../../../helper/type_mapping');
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 = {}; module.exports.tests = {};
module.exports.tests.interfaces = function(test, common) { module.exports.tests.interfaces = function(test, common) {
test('complete sources', function(t) { test('complete sources', function(t) {
t.deepEquals(type_mapping.sources, [ 'openstreetmap', 'openaddresses', 'geonames', 'whosonfirst' ]); t.deepEquals(type_mapping.sources, [ 'openstreetmap', 'openaddresses', 'geonames', 'whosonfirst' ]);
t.end(); t.end();
}); });
test('complete layers', function(t) { test('complete layers', function(t) {
t.deepEquals(type_mapping.layers, [ 'address', 'venue', 'street', 'country', 'macroregion', t.deepEquals(type_mapping.layers, [ 'address', 'venue', 'street', 'country', 'macroregion',
'region', 'county', 'localadmin', 'locality', 'borough', 'neighbourhood', 'continent', 'region', 'county', 'localadmin', 'locality', 'borough', 'neighbourhood', 'continent',
'empire', 'dependency', 'macrocounty', 'macrohood', 'microhood', 'disputed', 'empire', 'dependency', 'macrocounty', 'macrohood', 'microhood', 'disputed',
'postalcode', 'ocean', 'marinearea' ]); 'postalcode', 'ocean', 'marinearea' ]);
t.end(); t.end();
}); });
@ -46,8 +61,8 @@ module.exports.tests.interfaces = function(test, common) {
test('complete layer mapping', function(t) { test('complete layer mapping', function(t) {
t.deepEquals(type_mapping.layer_mapping, { t.deepEquals(type_mapping.layer_mapping, {
coarse: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region', coarse: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', 'region',
'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough', 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'borough',
'neighbourhood', 'microhood', 'disputed', 'postalcode', 'continent', 'ocean', 'marinearea' 'neighbourhood', 'microhood', 'disputed', 'postalcode', 'continent', 'ocean', 'marinearea'
], ],
address: [ 'address' ], address: [ 'address' ],
@ -94,11 +109,11 @@ module.exports.tests.interfaces = function(test, common) {
t.deepEquals(type_mapping.layers_by_source, { t.deepEquals(type_mapping.layers_by_source, {
openstreetmap: [ 'address', 'venue', 'street' ], openstreetmap: [ 'address', 'venue', 'street' ],
openaddresses: [ 'address' ], openaddresses: [ 'address' ],
geonames: [ 'country', 'macroregion', 'region', 'county', 'localadmin', geonames: [ 'country', 'macroregion', 'region', 'county', 'localadmin',
'locality', 'borough', 'neighbourhood', 'venue' ], 'locality', 'borough', 'neighbourhood', 'venue' ],
whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion', whosonfirst: [ 'continent', 'empire', 'country', 'dependency', 'macroregion',
'region', 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood', 'region', 'locality', 'localadmin', 'macrocounty', 'county', 'macrohood',
'borough', 'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode', 'borough', 'neighbourhood', 'microhood', 'disputed', 'venue', 'postalcode',
'continent', 'ocean', 'marinearea' ] 'continent', 'ocean', 'marinearea' ]
}); });
t.end(); t.end();

14
test/unit/sanitizer/_sources.js

@ -1,5 +1,15 @@
var type_mapping = require('../../../helper/type_mapping'); const fake_type_mapping = {
var sanitizer = require( '../../../sanitizer/_targets' )('sources', type_mapping.source_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 }; var success_messages = { error: false };

Loading…
Cancel
Save