mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.5 KiB
119 lines
3.5 KiB
8 years ago
|
var proxyquire = require('proxyquire').noCallThru();
|
||
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.sanitize = function(test, common) {
|
||
|
test('verify that all sanitizers were called as expected', function(t) {
|
||
|
var called_sanitizers = [];
|
||
|
|
||
|
// rather than re-verify the functionality of all the sanitizers, this test just verifies that they
|
||
|
// were all called correctly
|
||
8 years ago
|
var search = proxyquire('../../../sanitizer/structured_geocoding', {
|
||
8 years ago
|
'../sanitizer/_deprecate_quattroshapes': function() {
|
||
|
called_sanitizers.push('_deprecate_quattroshapes');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
'../sanitizer/_single_scalar_parameters': function() {
|
||
|
called_sanitizers.push('_single_scalar_parameters');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
'../sanitizer/_synthesize_analysis': function() {
|
||
|
called_sanitizers.push('_synthesize_analysis');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_iso2_to_iso3': function() {
|
||
|
called_sanitizers.push('_iso2_to_iso3');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
8 years ago
|
'../sanitizer/_size': function() {
|
||
|
if (arguments.length === 0) {
|
||
|
return function() {
|
||
|
called_sanitizers.push('_size');
|
||
|
return { errors: [], warnings: [] };
|
||
|
};
|
||
|
|
||
|
} else {
|
||
|
throw new Error('should not have passed any parameters to _size');
|
||
|
}
|
||
|
|
||
|
},
|
||
|
'../sanitizer/_targets': function(type) {
|
||
|
if (['layers', 'sources'].indexOf(type) !== -1) {
|
||
|
return function() {
|
||
|
called_sanitizers.push('_targets/' + type);
|
||
|
return { errors: [], warnings: [] };
|
||
|
};
|
||
|
|
||
|
}
|
||
|
else {
|
||
|
throw new Error('incorrect parameters passed to _targets');
|
||
|
}
|
||
|
|
||
|
},
|
||
|
'../sanitizer/_sources_and_layers': function() {
|
||
|
called_sanitizers.push('_sources_and_layers');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
'../sanitizer/_flag_bool': function() {
|
||
|
if (arguments[0] === 'private' && arguments[1] === false) {
|
||
|
return function() {
|
||
|
called_sanitizers.push('_flag_bool');
|
||
|
return { errors: [], warnings: [] };
|
||
|
};
|
||
|
|
||
|
}
|
||
|
else {
|
||
|
throw new Error('incorrect parameters passed to _flag_bool');
|
||
|
}
|
||
|
|
||
|
},
|
||
|
'../sanitizer/_geo_search': function() {
|
||
|
called_sanitizers.push('_geo_search');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
'../sanitizer/_boundary_country': function() {
|
||
|
called_sanitizers.push('_boundary_country');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
'../sanitizer/_categories': function() {
|
||
|
called_sanitizers.push('_categories');
|
||
|
return { errors: [], warnings: [] };
|
||
|
},
|
||
|
});
|
||
|
|
||
|
var expected_sanitizers = [
|
||
|
'_deprecate_quattroshapes',
|
||
|
'_single_scalar_parameters',
|
||
|
'_synthesize_analysis',
|
||
8 years ago
|
'_iso2_to_iso3',
|
||
8 years ago
|
'_size',
|
||
|
'_targets/layers',
|
||
|
'_targets/sources',
|
||
|
'_sources_and_layers',
|
||
|
'_flag_bool',
|
||
|
'_geo_search',
|
||
|
'_boundary_country',
|
||
|
'_categories'
|
||
|
];
|
||
|
|
||
|
var req = {};
|
||
|
var res = {};
|
||
|
|
||
|
search.middleware(req, res, function(){
|
||
|
t.deepEquals(called_sanitizers, expected_sanitizers);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
|
||
|
function test(name, testFunction) {
|
||
8 years ago
|
return tape('SANTIZE /structured ' + name, testFunction);
|
||
8 years ago
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|