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.

89 lines
3.7 KiB

var sanitize = require('../../../sanitiser/_boundary_country');
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);
t.equals(clean.boundary.country, undefined, 'should be undefined');
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
t.end();
});
test('boundary w/o country in raw should leave boundary.country undefined', function(t) {
var raw = { boundary: {} };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined');
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) {
var raw = { boundary: {country: undefined } };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined');
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) {
var raw = { boundary: {country: ['this isn\'t a string primitive'] } };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined');
t.deepEquals(errorsAndWarnings, { errors: [], warnings: ['boundary.country is not a string'] }, 'non-string country warning');
t.end();
});
test('iso2 boundary.country in raw should set boundary.country to ISO3 uppercased', function(t) {
var raw = { boundary: {country: 'aq'} };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3');
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }, 'no warnings or errors');
t.end();
});
test('iso3 boundary.country in raw should set boundary.country to matching ISO3 uppercased', function(t) {
var raw = { boundary: {country: 'aTa'} };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, 'ATA', 'should be uppercased ISO3');
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) {
var raw = { boundary: {country: 'zq'} };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined');
t.deepEquals(errorsAndWarnings, { errors: [], warnings: ['zq is not a valid ISO2/ISO3 country code'] }, 'country not found warning`');
t.end();
});
test('unknown 3-character boundary.country should set boundary.country to undefined', function(t) {
var raw = { boundary: {country: 'zqx'} };
var clean = {};
var errorsAndWarnings = sanitize(raw, clean);
t.equals(clean.boundary.country, undefined, 'should be undefined');
t.deepEquals(errorsAndWarnings, { errors: [], warnings: ['zqx is not a valid ISO2/ISO3 country code'] }, 'country not found warning`');
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);
}
};