5
0
mirror of https://github.com/cwinfo/hyperboria-peers.git synced 2024-11-22 04:50:28 +00:00

more thorough js tests

This commit is contained in:
ansuz 2016-09-29 09:16:25 +02:00
parent bfc3a41fb8
commit deaea22c4d

View File

@ -37,23 +37,40 @@ if (credsWithDns.length) {
*/
var requiredFields = ['password', 'publicKey', 'contact'];
var recommendedFields = ['gpg'];
var insufficientFields = Peers.filter(function (x, p) {
var problem = false;
var comment = false;
var path = '/' + p.join('/');
var requiredMsg = "[%s] => %s is missing the required field '%s'";
var recommendedMsg = "[%s] => '%s' is missing the recommended field '%s'";
Object.keys(x).map(function (k) {
var cred = x[k];
var fields = Object.keys(cred);
requiredFields.forEach(function (field) {
if (fields.indexOf(field) === -1) {
recommendedFields.forEach(function (field) {
if (typeof(cred[field]) !== 'undefined') { return; }
console.log(recommendedMsg, path, k, field);
comment = true;
problem = true;
}
});
requiredFields.forEach(function (field) {
if (typeof(cred[field]) !== 'undefined') { return; }
console.error(requiredMsg, path, k, field);
problem = true;
})
});
//if (comment || problem) { console.log(); }
return problem;
});
if (insufficientFields.length) {
console.log("The following peers did not have all the required fields");
console.log(insufficientFields);
//console.log("The following peers did not have all the required fields");
//console.log(insufficientFields);
}