mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-05-26 23:58:16 +00:00
Adds more tests for domain name + fixes regex
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"forceHttps": true,
|
||||
"record": {
|
||||
"CNAME": "phenax.github.io"
|
||||
"CNAME": ["phenax.github.io"]
|
||||
}
|
||||
}
|
||||
|
||||
+22
-13
@@ -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
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user