mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-09-04 20:18:19 +00:00
improves a record validation
This commit is contained in:
@@ -31,6 +31,8 @@ describe('validateDomainData', () => {
|
||||
})),
|
||||
{ ...defaultDomain, record: { CNAME: 'sd', A: ['121,3213'] } },
|
||||
{ ...defaultDomain, record: { A: ['121', '12'], FOOBAR: ['sd'] } },
|
||||
{ ...defaultDomain, record: { A: [] } },
|
||||
{ ...defaultDomain, record: { A: ['11122'], URL: 'foobar' } },
|
||||
{ ...defaultDomain, owner: {}, },
|
||||
{ ...defaultDomain, owner: { username: 'hwelo', }, },
|
||||
{ ...defaultDomain, owner: { email: 'hwelo' }, },
|
||||
|
||||
+9
-4
@@ -25,10 +25,15 @@ const validate = pattern => data => R.compose(
|
||||
R.toPairs,
|
||||
)(pattern);
|
||||
|
||||
const validateCnameRecord = type => R.allPass([
|
||||
R.propSatisfies(R.is(String), type),
|
||||
const validateCnameRecord = key => R.allPass([
|
||||
R.propSatisfies(R.is(String), key),
|
||||
R.compose(R.equals(1), R.length, R.reject(R.equals('URL')), R.keys),
|
||||
R.propSatisfies(R.complement(testRegex(/^https?:\/\//ig)), type),
|
||||
R.propSatisfies(R.complement(testRegex(/^https?:\/\//ig)), key),
|
||||
]);
|
||||
|
||||
const validateARecord = key => R.allPass([
|
||||
R.compose(R.equals(1), R.length, R.keys),
|
||||
R.propSatisfies(R.compose(R.gte(R.__, 1), R.length), key),
|
||||
]);
|
||||
|
||||
const validateDomainData = validate({
|
||||
@@ -62,7 +67,7 @@ const validateDomainData = validate({
|
||||
R.compose(R.isEmpty, R.flip(R.difference)(VALID_RECORD_TYPES), R.keys),
|
||||
R.cond([
|
||||
[R.prop('CNAME'), validateCnameRecord('CNAME')],
|
||||
[R.prop('A'), R.propSatisfies(R.is(Array), 'A')],
|
||||
[R.prop('A'), validateARecord('A')],
|
||||
[R.prop('URL'), R.propSatisfies(R.is(String), 'URL')],
|
||||
[R.T, R.T],
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user