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.
80 lines
3.3 KiB
80 lines
3.3 KiB
8 years ago
|
var sanitize = require('../../../sanitizer/_boundary_country');
|
||
9 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.sanitize_boundary_country = function(test, common) {
|
||
|
test('raw w/o boundary should set boundary.country undefined', function(t) {
|
||
|
var raw = { };
|
||
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], undefined, 'should be undefined');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
|
test('boundary.country explicitly undefined in raw should leave boundary.country undefined', function(t) {
|
||
9 years ago
|
var raw = { 'boundary.country': undefined };
|
||
9 years ago
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], undefined, 'should be undefined');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
|
test('non-string boundary.country should set boundary.country to undefined and return warning', function(t) {
|
||
9 years ago
|
var raw = { 'boundary.country': ['this isn\'t a string primitive'] };
|
||
9 years ago
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], undefined, 'should be undefined');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: ['boundary.country is not a string'], warnings: [] }, 'non-string country warning');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
9 years ago
|
test('iso2 boundary.country in raw should set boundary.country to ISO3 uppercased', function(t) {
|
||
9 years ago
|
var raw = { 'boundary.country': 'aq' };
|
||
9 years ago
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], 'ATA', 'should be uppercased ISO3');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
9 years ago
|
test('iso3 boundary.country in raw should set boundary.country to matching ISO3 uppercased', function(t) {
|
||
9 years ago
|
var raw = { 'boundary.country': 'aTa' };
|
||
9 years ago
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], 'ATA', 'should be uppercased ISO3');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
|
test('unknown 2-character boundary.country should set boundary.country to undefined', function(t) {
|
||
9 years ago
|
var raw = { 'boundary.country': 'zq' };
|
||
9 years ago
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], undefined, 'should be undefined');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: ['zq is not a valid ISO2/ISO3 country code'], warnings: [] }, 'country not found warning`');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
|
test('unknown 3-character boundary.country should set boundary.country to undefined', function(t) {
|
||
9 years ago
|
var raw = { 'boundary.country': 'zqx' };
|
||
9 years ago
|
var clean = {};
|
||
|
var errorsAndWarnings = sanitize(raw, clean);
|
||
9 years ago
|
t.equals(clean['boundary.country'], undefined, 'should be undefined');
|
||
9 years ago
|
t.deepEquals(errorsAndWarnings, { errors: ['zqx is not a valid ISO2/ISO3 country code'], warnings: [] }, 'country not found warning`');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
function test(name, testFunction) {
|
||
|
return tape('SANTIZE _boundary_country ' + name, testFunction);
|
||
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|