diff --git a/domains/akshay.json b/domains/akshay.json index 60de04369..13a98f7e3 100644 --- a/domains/akshay.json +++ b/domains/akshay.json @@ -1,6 +1,6 @@ { "forceHttps": true, "record": { - "CNAME": "phenax.github.io" + "CNAME": ["phenax.github.io"] } } diff --git a/tests/domains.test.js b/tests/domains.test.js index 58051a5b4..f1d123695 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -12,30 +12,39 @@ describe('Domains', () => { describe('validateDomainData', () => { it('should return true if the name is invalid', () => { - const { valid, errors } = validateDomainData({ - name: 'hello world', - forceHttps: true, - record: { CNAME: ['hello.com'] }, + const names = ['hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '', undefined, '12112**dsd', Array(101).fill('a').join('')]; + + names.forEach(name => { + const { valid, errors } = validateDomainData({ + name, + forceHttps: true, + record: { CNAME: ['hello.com'] }, + }); + expect(valid).toBe(false); + expect(errors.length).toBe(1); + expect(errors[0][0]).toBe('name'); }); - expect(valid).toBe(false); - expect(errors[0][0]).toBe('name'); }); it('should return true for a valid object', () => { - const { valid, errors } = validateDomainData({ - name: 'something', - forceHttps: true, - record: { CNAME: ['hello.com'] }, + const names = ['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow']; + names.forEach(name => { + const { valid, errors } = validateDomainData({ + name, + forceHttps: true, + record: { CNAME: ['hello.com'] }, + }); + expect(valid).toBe(true); + expect(errors).toEqual([]); }); - expect(valid).toBe(true); - expect(errors).toEqual([]); }); }); }); - xit('should have a the correct keys', async () => { + it('should have a the correct keys', async () => { const list = await getDomains(); list.forEach(data => { + console.log(data); const { errors } = validateDomainData(data); if (errors.length) { console.log(errors); diff --git a/utils/domain.js b/utils/domain.js index 590472dcf..d3b5e0a78 100644 --- a/utils/domain.js +++ b/utils/domain.js @@ -26,7 +26,10 @@ const validate = pattern => data => R.compose( const validateDomainData = validate({ name: { reason: 'The name of the file is invalid', - fn: str => str.match(/^[A-Za-z0-9]{3,}$/ig), + fn: R.allPass([ + hasLengthLessThan(100), + str => str && str.match(/^[A-Za-z0-9\-]{3,}$/ig), + ]), }, description: { reason: 'Description has to be shorter than 100 characters',