mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-08-09 20:22:14 +00:00
Adds test cases
This commit is contained in:
+28
-17
@@ -11,29 +11,41 @@ describe('Domains', () => {
|
||||
});
|
||||
|
||||
describe('validateDomainData', () => {
|
||||
it('should return true if the name is invalid', () => {
|
||||
const names = ['hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '', undefined, '12112**dsd', Array(101).fill('a').join('')];
|
||||
|
||||
names.forEach(name => {
|
||||
const { valid, errors } = 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).toBe(1);
|
||||
expect(errors[0][0]).toBe('name');
|
||||
expect(errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true for a valid object', () => {
|
||||
const names = ['hello', 'hello-world', '11111111111', '--wow--', 'wow--', '--wow'];
|
||||
names.forEach(name => {
|
||||
const { valid, errors } = validateDomainData({
|
||||
name,
|
||||
forceHttps: true,
|
||||
record: { CNAME: ['hello.com'] },
|
||||
});
|
||||
it('should return true if the name is valid', () => {
|
||||
validCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
expect(valid).toBe(true);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
@@ -44,7 +56,6 @@ describe('Domains', () => {
|
||||
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);
|
||||
|
||||
+3
-3
@@ -32,25 +32,25 @@ const validateDomainData = validate({
|
||||
]),
|
||||
},
|
||||
description: {
|
||||
reason: 'Description has to be shorter than 100 characters',
|
||||
reason: '`description` has to be shorter than 100 characters',
|
||||
fn: R.anyPass([
|
||||
R.empty,
|
||||
hasLengthLessThan(100),
|
||||
]),
|
||||
},
|
||||
forceHttps: {
|
||||
reason: 'forceHttp is required to be true or false',
|
||||
reason: '`forceHttp` is required to be true or false',
|
||||
fn: R.is(Boolean),
|
||||
},
|
||||
record: {
|
||||
reason: 'Invalid record',
|
||||
fn: R.allPass([
|
||||
R.is(Object),
|
||||
R.compose(hasLengthLessThan(1), R.keys),
|
||||
R.anyPass([
|
||||
R.propSatisfies(R.is(Array), 'CNAME'),
|
||||
R.propSatisfies(R.is(Array), 'A'),
|
||||
]),
|
||||
R.compose(hasLengthLessThan(1), R.keys),
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user