diff --git a/tests/domains.test.js b/tests/domains.test.js index 82fbfb99f..58051a5b4 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -10,9 +10,20 @@ describe('Domains', () => { }); }); - describe('isValidDomainData', () => { + describe('validateDomainData', () => { + it('should return true if the name is invalid', () => { + const { valid, errors } = validateDomainData({ + name: 'hello world', + forceHttps: true, + record: { CNAME: ['hello.com'] }, + }); + 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'] }, }); diff --git a/utils/domain.js b/utils/domain.js index 85e9fef82..590472dcf 100644 --- a/utils/domain.js +++ b/utils/domain.js @@ -24,10 +24,10 @@ const validate = pattern => data => R.compose( )(pattern); const validateDomainData = validate({ - //name: { - //reason: 'The name of the file is invalid', - //fn: R.match(/[A-Za-z0-9]{3,}/g), - //}, + name: { + reason: 'The name of the file is invalid', + fn: str => str.match(/^[A-Za-z0-9]{3,}$/ig), + }, description: { reason: 'Description has to be shorter than 100 characters', fn: R.anyPass([