mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-09-03 02:20:03 +00:00
Fixes Alias and A record validation
This commit is contained in:
@@ -10,13 +10,17 @@ describe('getDomains', () => {
|
||||
const defaultDomain = {
|
||||
name: 'aaa',
|
||||
forceHttps: false,
|
||||
record: { A: ['121.121.121.121'] },
|
||||
record: {
|
||||
A: ['121.121.121.121']
|
||||
},
|
||||
owner: {
|
||||
username: 'betsy',
|
||||
email: 'betsyfuckyoassup@foobar.com',
|
||||
},
|
||||
};
|
||||
|
||||
const getstroflen = len => Array(len).fill('a').join('');
|
||||
|
||||
describe('validateDomainData', () => {
|
||||
const invalidCases = [
|
||||
{},
|
||||
@@ -24,8 +28,7 @@ describe('validateDomainData', () => {
|
||||
{ forceHttps: 1 },
|
||||
{ name: 'helo' },
|
||||
{ name: 'wwow', record: { A: ['12312'] } },
|
||||
...['', ' ', undefined, 'hello world', 'good12312++123', 'ajsdjasdaSD_123yuqehq', 'khsda%', '12112**dsd', Array(101).fill('a').join('')]
|
||||
.map(name => ({
|
||||
...['', ' ', undefined, 'hlo wld', 'g32++13', 'ajsdD_123yq', 'khsda%', '122*dsd', getstroflen(101)].map(name => ({
|
||||
...defaultDomain,
|
||||
name,
|
||||
})),
|
||||
@@ -44,7 +47,7 @@ describe('validateDomainData', () => {
|
||||
})),
|
||||
{
|
||||
...defaultDomain,
|
||||
description: Array(99).fill('a').join(''),
|
||||
description: getstroflen(99),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -59,6 +62,7 @@ describe('validateDomainData', () => {
|
||||
it('should return true if the name is valid', () => {
|
||||
validCases.forEach(data => {
|
||||
const { valid, errors } = validateDomainData(data);
|
||||
if (!valid) console.log(errors);
|
||||
expect(valid).toBe(true);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
|
||||
+5
-3
@@ -25,9 +25,9 @@ const validate = pattern => data => R.compose(
|
||||
R.toPairs,
|
||||
)(pattern);
|
||||
|
||||
const validateCNAME = R.allPass([
|
||||
const validateNameRecord = type => R.allPass([
|
||||
R.compose(R.equals(1), R.length, R.keys),
|
||||
R.propSatisfies(R.is(Array), 'CNAME'),
|
||||
R.propSatisfies(R.is(Array), type),
|
||||
]);
|
||||
|
||||
const validateDomainData = validate({
|
||||
@@ -60,7 +60,9 @@ const validateDomainData = validate({
|
||||
fn: R.allPass([
|
||||
R.is(Object),
|
||||
R.cond([
|
||||
[R.prop('CNAME'), validateCNAME],
|
||||
[R.prop('CNAME'), validateNameRecord('CNAME')],
|
||||
[R.prop('ALIAS'), validateNameRecord('ALIAS')],
|
||||
[R.prop('A'), R.propSatisfies(R.is(Array), 'A')],
|
||||
[R.T, R.T],
|
||||
]),
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user