Adds test cases

This commit is contained in:
Akshay Nair
2020-10-04 13:59:32 +05:30
parent cc5018eea4
commit 4cc037b048
2 changed files with 31 additions and 20 deletions
+28 -17
View File
@@ -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
View File
@@ -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),
]),
},
});