Adds more tests for domain name + fixes regex

This commit is contained in:
Akshay Nair
2020-10-04 13:46:05 +05:30
parent e042b69b2a
commit cc5018eea4
3 changed files with 27 additions and 15 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"forceHttps": true,
"record": {
"CNAME": "phenax.github.io"
"CNAME": ["phenax.github.io"]
}
}
+22 -13
View File
@@ -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);
+4 -1
View File
@@ -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',