Adds more tests for domain name + fixes regex

This commit is contained in:
Akshay Nair committed 2020-10-04 13:46:05 +05:30
1 parent e042b69b2a
commit cc5018eea4
3 files changed
+27 -15

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"forceHttps": true, "forceHttps": true,
"record": { "record": {
"CNAME": "phenax.github.io" "CNAME": ["phenax.github.io"]
} }
} }
+22 -13
View File
@@ -12,30 +12,39 @@ describe('Domains', () => {
describe('validateDomainData', () => { describe('validateDomainData', () => {
it('should return true if the name is invalid', () => { it('should return true if the name is invalid', () => {
const { valid, errors } = validateDomainData({ const names = ['hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '', undefined, '12112**dsd', Array(101).fill('a').join('')];
name: 'hello world',
forceHttps: true, names.forEach(name => {
record: { CNAME: ['hello.com'] }, 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', () => { it('should return true for a valid object', () => {
const { valid, errors } = validateDomainData({ const names = ['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'];
name: 'something', names.forEach(name => {
forceHttps: true, const { valid, errors } = validateDomainData({
record: { CNAME: ['hello.com'] }, 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(); const list = await getDomains();
list.forEach(data => { list.forEach(data => {
console.log(data);
const { errors } = validateDomainData(data); const { errors } = validateDomainData(data);
if (errors.length) { if (errors.length) {
console.log(errors); console.log(errors);
+4 -1
View File
@@ -26,7 +26,10 @@ const validate = pattern => data => R.compose(
const validateDomainData = validate({ const validateDomainData = validate({
name: { name: {
reason: 'The name of the file is invalid', 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: { description: {
reason: 'Description has to be shorter than 100 characters', reason: 'Description has to be shorter than 100 characters',