mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-05-17 16:59:47 +00:00
30 lines
955 B
JavaScript
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);
|
|
});
|
|
});
|
|
|