Adds domains directory validation and prettified error messages

This commit is contained in:
Akshay Nair committed 2020-10-04 15:10:05 +05:30
1 parent 2bdbbe18cb
commit e8203c73f5
2 files changed
+26 -9

No files matched your search

+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);
});
});