Adds domains directory validation and prettified error messages

This commit is contained in:
Akshay Nair
2020-10-04 15:10:05 +05:30
parent 2bdbbe18cb
commit e8203c73f5
2 changed files with 26 additions and 9 deletions
+11
View File
@@ -0,0 +1,11 @@
{
"description": "Test website by akshay",
"owner": {
"username": "phenax",
"email": "phenax5@gmail.com"
},
"forceHttps": true,
"record": {
"CNAME": ["duckduckgo.com"]
}
}
+15 -9
View File
@@ -2,15 +2,21 @@ const R = require('ramda');
const { getDomains, validateDomainData } = require('../utils/domain');
describe('Domains', () => {
it('should be valid', async () => {
const list = await getDomains();
list.forEach(data => {
const { errors } = validateDomainData(data);
if (errors.length) {
console.log(errors);
}
});
it('should be valid', (done) => {
getDomains()
.then(R.map(data => {
const { errors } = validateDomainData(data);
if (errors.length) {
const message = errors
.map(([key, { reason }]) => `[${data.name}.${key}]: ${reason}`)
.join('\n');
return `\nValidation errors in ${data.name}.json: \n${message}`;
}
return '';
}))
.then(R.filter(R.complement(R.isEmpty)))
.then(messages => messages.length ? done(messages.join('\n')) : done())
.catch(done);
});
});