diff --git a/tests/domain-utils.test.js b/tests/domain-utils.test.js new file mode 100644 index 000000000..c3ac16598 --- /dev/null +++ b/tests/domain-utils.test.js @@ -0,0 +1,63 @@ +const { getDomains, validateDomainData } = require('../utils/domain'); + +describe('getDomains', () => { + it('should resolve with the list of domains', async () => { + const list = await getDomains(); + expect(Array.isArray(list)).toBe(true); + }); +}); + +const defaultDomain = { + name: 'aaa', + forceHttps: false, + record: { A: ['121.121.121.121'] }, +}; + +describe('validateDomainData', () => { + const invalidCases = [ + {}, + { forceHttps: false }, + { forceHttps: 1 }, + { name: 'helo' }, + { record: { CNAME: ['sd'] } }, + { name: 'wwow', record: { A: ['12312'] } }, + ...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')] + .map(name => ({ + ...defaultDomain, + name, + })), + { + ...defaultDomain, + description: Array(201).fill('a').join(''), + }, + ]; + + const validCases = [ + defaultDomain, + ...['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'].map(name => ({ + ...defaultDomain, + name, + })), + { + ...defaultDomain, + description: Array(99).fill('a').join(''), + }, + ]; + + it('should return false for invalid data', () => { + invalidCases.forEach(data => { + const { valid, errors } = validateDomainData(data); + expect(valid).toBe(false); + expect(errors.length).toBeGreaterThan(0); + }); + }); + + it('should return true if the name is valid', () => { + validCases.forEach(data => { + const { valid, errors } = validateDomainData(data); + expect(valid).toBe(true); + expect(errors).toEqual([]); + }); + }); +}); + diff --git a/tests/domains.test.js b/tests/domains.test.js index a55b9b04f..28d73d895 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -2,59 +2,9 @@ const R = require('ramda'); const { getDomains, validateDomainData } = require('../utils/domain'); describe('Domains', () => { - describe('but first... a test for this test', () => { - describe('getDomains', () => { - it('should resolve with the list of domains', async () => { - const list = await getDomains(); - expect(Array.isArray(list)).toBe(true); - }); - }); - - describe('validateDomainData', () => { - const invalidCases = [ - {}, - { forceHttps: false }, - { forceHttps: 1 }, - { name: 'helo' }, - { record: { CNAME: ['sd'] } }, - { name: 'wwow', record: { A: ['12312'] } }, - ...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')] - .map(name => ({ - name, - forceHttps: true, - record: { CNAME: ['hello.com'] }, - })), - ]; - - const validCases = [ - { name: 'asas', forceHttps: false, record: { A: ['111.111.111.111'] } }, - ...['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'].map(name => ({ - name, - forceHttps: true, - record: { CNAME: ['hello.com'] }, - })) - ]; - - it('should return false for invalid data', () => { - invalidCases.forEach(data => { - const { valid, errors } = validateDomainData(data); - expect(valid).toBe(false); - expect(errors.length).toBeGreaterThan(0); - }); - }); - - it('should return true if the name is valid', () => { - validCases.forEach(data => { - const { valid, errors } = validateDomainData(data); - expect(valid).toBe(true); - expect(errors).toEqual([]); - }); - }); - }); - }); - - it('should have a the correct keys', async () => { + it('should be valid', async () => { const list = await getDomains(); + list.forEach(data => { const { errors } = validateDomainData(data); if (errors.length) { diff --git a/utils/domain.js b/utils/domain.js index 85c2de5a3..ee294e231 100644 --- a/utils/domain.js +++ b/utils/domain.js @@ -28,16 +28,21 @@ const validateDomainData = validate({ reason: 'The name of the file is invalid', fn: R.allPass([ hasLengthLessThan(100), - str => str && str.match(/^[A-Za-z0-9\-]{3,}$/ig), + str => str && str.match(/^[A-Za-z0-9\-]{2,}$/ig), ]), }, description: { - reason: '`description` has to be shorter than 100 characters', + reason: '`description` has to be shorter than 200 characters', fn: R.anyPass([ R.empty, - hasLengthLessThan(100), + R.is(String), + hasLengthLessThan(200), ]), }, + repo: { + reason: '', + fn: R.T, + }, forceHttps: { reason: '`forceHttp` is required to be true or false', fn: R.is(Boolean),