Files
is-a-dev/tests/domains.test.js
T
2020-10-11 23:57:46 +05:30

30 lines
955 B
JavaScript

const R = require('ramda');
const fs = require('fs');
const { getDomains, validateDomainData } = require('../utils/domain');
const { DOMAINS_PATH } = require('../utils/constants');
describe('Domains', () => {
it('should all be json', async () => {
const files = await fs.promises.readdir(DOMAINS_PATH, {});
expect(files.filter(f => !/\.json$/g.test(f)).length).toBe(0);
});
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);
});
});