mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-11 18:22:21 +00:00
Refactors domain utils test + adds repo field
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
const { getDomains, validateDomainData } = require('../utils/domain');
|
||||
|
||||
describe('getDomains', () => {
|
||||
it('should resolve with the list of domains', async () => {
|
||||
const list = await getDomains();
|
||||
expect(Array.isArray(list)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
const defaultDomain = {
|
||||
name: 'aaa',
|
||||
forceHttps: false,
|
||||
record: { A: ['121.121.121.121'] },
|
||||
};
|
||||
|
||||
describe('validateDomainData', () => {
|
||||
const invalidCases = [
|
||||
{},
|
||||
{ forceHttps: false },
|
||||
{ forceHttps: 1 },
|
||||
{ name: 'helo' },
|
||||
{ record: { CNAME: ['sd'] } },
|
||||
{ name: 'wwow', record: { A: ['12312'] } },
|
||||
...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')]
|
||||
.map(name => ({
|
||||
...defaultDomain,
|
||||
name,
|
||||
})),
|
||||
{
|
||||
...defaultDomain,
|
||||
description: Array(201).fill('a').join(''),
|
||||
},
|
||||
];
|
||||
|
||||
const validCases = [
|
||||
defaultDomain,
|
||||
...['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'].map(name => ({
|
||||
...defaultDomain,
|
||||
name,
|
||||
})),
|
||||
{
|
||||
...defaultDomain,
|
||||
description: Array(99).fill('a').join(''),
|
||||
},
|
||||
];
|
||||
|
||||
it('should return false for invalid data', () => {
|
||||
invalidCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(false);
|
||||
expect(errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if the name is valid', () => {
|
||||
validCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(true);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+2
-52
@@ -2,59 +2,9 @@ const R = require('ramda');
|
||||
const { getDomains, validateDomainData } = require('../utils/domain');
|
||||
|
||||
describe('Domains', () => {
|
||||
describe('but first... a test for this test', () => {
|
||||
describe('getDomains', () => {
|
||||
it('should resolve with the list of domains', async () => {
|
||||
const list = await getDomains();
|
||||
expect(Array.isArray(list)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateDomainData', () => {
|
||||
const invalidCases = [
|
||||
{},
|
||||
{ forceHttps: false },
|
||||
{ forceHttps: 1 },
|
||||
{ name: 'helo' },
|
||||
{ record: { CNAME: ['sd'] } },
|
||||
{ name: 'wwow', record: { A: ['12312'] } },
|
||||
...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')]
|
||||
.map(name => ({
|
||||
name,
|
||||
forceHttps: true,
|
||||
record: { CNAME: ['hello.com'] },
|
||||
})),
|
||||
];
|
||||
|
||||
const validCases = [
|
||||
{ name: 'asas', forceHttps: false, record: { A: ['111.111.111.111'] } },
|
||||
...['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'].map(name => ({
|
||||
name,
|
||||
forceHttps: true,
|
||||
record: { CNAME: ['hello.com'] },
|
||||
}))
|
||||
];
|
||||
|
||||
it('should return false for invalid data', () => {
|
||||
invalidCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(false);
|
||||
expect(errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if the name is valid', () => {
|
||||
validCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(true);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should have a the correct keys', async () => {
|
||||
it('should be valid', async () => {
|
||||
const list = await getDomains();
|
||||
|
||||
list.forEach(data => {
|
||||
const { errors } = validateDomainData(data);
|
||||
if (errors.length) {
|
||||
|
||||
+8
-3
@@ -28,16 +28,21 @@ const validateDomainData = validate({
|
||||
reason: 'The name of the file is invalid',
|
||||
fn: R.allPass([
|
||||
hasLengthLessThan(100),
|
||||
str => str && str.match(/^[A-Za-z0-9\-]{3,}$/ig),
|
||||
str => str && str.match(/^[A-Za-z0-9\-]{2,}$/ig),
|
||||
]),
|
||||
},
|
||||
description: {
|
||||
reason: '`description` has to be shorter than 100 characters',
|
||||
reason: '`description` has to be shorter than 200 characters',
|
||||
fn: R.anyPass([
|
||||
R.empty,
|
||||
hasLengthLessThan(100),
|
||||
R.is(String),
|
||||
hasLengthLessThan(200),
|
||||
]),
|
||||
},
|
||||
repo: {
|
||||
reason: '',
|
||||
fn: R.T,
|
||||
},
|
||||
forceHttps: {
|
||||
reason: '`forceHttp` is required to be true or false',
|
||||
fn: R.is(Boolean),
|
||||
|
||||
Reference in New Issue
Block a user