Browse Source

test queryMixer.json

fuzzy
Harish Krishna 10 years ago
parent
commit
e9f7e6ccb8
  1. 76
      test/unit/helper/queryMixer.js
  2. 3
      test/unit/run.js

76
test/unit/helper/queryMixer.js

@ -0,0 +1,76 @@
var query_mixer = require('../../../helper/queryMixer.json');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof query_mixer, 'object', 'valid object');
t.equal(query_mixer.hasOwnProperty('suggest'), true, 'has suggest defined');
t.equal(query_mixer.hasOwnProperty('suggest_nearby'), true, 'has suggest_nearby defined');
t.end();
});
};
module.exports.tests.valid = function(test, common) {
var valid_keys = ['layers', 'precision', 'fuzzy'];
var valid_fuzzy_vals = ['AUTO', 0, 1, 2];
var valid_layer_vals = ['all', 'admin'];
var default_suggest = {
local: ['local_admin', 'locality', 'neighborhood', 'admin2'],
regional: ['admin1_abbr', 'admin1', 'admin0']
};
var isValidPrecision = function(t, precisionArr) {
precisionArr.forEach(function(precision) {
t.notEqual(isNaN(precision), true, precision + ' is a valid precision value');
});
};
var isValid = function(key, mix) {
test('valid mix (' + key + ')' , function(t) {
t.equal(keys.length > 0, true, 'valid key');
t.equal(Array.isArray( mix ), true, 'is an array');
t.equal(mix.length > 0, true, 'is not an empty array');
mix.forEach( function(this_mix) {
t.notEqual(Object.getOwnPropertyNames(this_mix).length, 0, 'object not empty');
for (var keys in this_mix) {
t.notEqual(valid_keys.indexOf(keys), -1, keys + ' is valid');
switch(keys) {
case 'fuzzy':
t.notEqual(valid_fuzzy_vals.indexOf(this_mix[keys]), -1, 'fuzzy value ' + this_mix[keys] + ' is valid');
break;
case 'layers':
t.notEqual(valid_layer_vals.indexOf(this_mix[keys]), -1, 'layer value ' + this_mix[keys] + ' is valid');
break;
case 'precision':
t.equal(Array.isArray( this_mix[keys] ), true, keys + ' is an array');
if (this_mix[keys].length > 0) {
isValidPrecision(t, this_mix[keys]);
}
break;
default:
break;
}
}
});
t.end();
});
};
for (var keys in query_mixer) {
isValid(keys, query_mixer[keys]);
}
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('query_mixer: ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

3
test/unit/run.js

@ -17,7 +17,8 @@ var tests = [
require('./query/search'),
require('./query/reverse'),
require('./helper/geojsonify'),
require('./helper/outputSchema')
require('./helper/outputSchema'),
require('./helper/queryMixer')
];
tests.map(function(t) {

Loading…
Cancel
Save