diff --git a/src/rules/__tests__/ageByDate_tests.js b/src/rules/__tests__/ageByDate_tests.js index b5a9fb4..c26d540 100644 --- a/src/rules/__tests__/ageByDate_tests.js +++ b/src/rules/__tests__/ageByDate_tests.js @@ -11,24 +11,24 @@ test('rules.ageByDate should return null for valid values', t => { t.is(ageByDate('field', two, { exact: 2 }), null); }); -test('rules.ageByDate should return "ageByDate/min" when age is below min', t => { - t.is(ageByDate('field', moment().format('YYYY-MM-DD'), { min: 18 }), 'ageByDate/min'); +test('rules.ageByDate should return "ageByDate.min" when age is below min', t => { + t.is(ageByDate('field', moment().format('YYYY-MM-DD'), { min: 18 }), 'ageByDate.min'); }); -test('rules.ageByDate should return "ageByDate/max" when age is above max', t => { +test('rules.ageByDate should return "ageByDate.max" when age is above max', t => { t.is( ageByDate('field', moment().subtract(5, 'years').format('YYYY-MM-DD'), { max: 2 }), - 'ageByDate/max' + 'ageByDate.max' ); }); -test('rules.ageByDate should return "ageByDate/min" when age is below exact', t => { - t.is(ageByDate('field', moment().format('YYYY-MM-DD'), { exact: 18 }), 'ageByDate/min'); +test('rules.ageByDate should return "ageByDate.min" when age is below exact', t => { + t.is(ageByDate('field', moment().format('YYYY-MM-DD'), { exact: 18 }), 'ageByDate.min'); }); -test('rules.ageByDate should return "ageByDate/max" when age is above exact', t => { +test('rules.ageByDate should return "ageByDate.max" when age is above exact', t => { t.is( ageByDate('field', moment().subtract(5, 'years').format('YYYY-MM-DD'), { exact: 2 }), - 'ageByDate/max' + 'ageByDate.max' ); }); diff --git a/src/rules/__tests__/date_tests.js b/src/rules/__tests__/date_tests.js index 8cb17df..caa099b 100644 --- a/src/rules/__tests__/date_tests.js +++ b/src/rules/__tests__/date_tests.js @@ -14,24 +14,24 @@ test('rules.date should return null for valid formats when format is specified', t.is(date('field', '2015', { format: 'YYYY' }), null); }); -test('rules.date should return "date/format" for invalid formats', t => { - t.is(date('field', '2015-r05-05'), 'date/format'); - t.is(date('field', '2015-02-29'), 'date/format'); - t.is(date('field', '2016-02-31'), 'date/format'); +test('rules.date should return "date.format" for invalid formats', t => { + t.is(date('field', '2015-r05-05'), 'date.format'); + t.is(date('field', '2015-02-29'), 'date.format'); + t.is(date('field', '2016-02-31'), 'date.format'); }); -test('rules.date should return "date/format" for invalid formats when format is specified', t => { - t.is(date('field', '2015-05-05T10:00', { format: 'YYYY-MM-DD' }), 'date/format'); +test('rules.date should return "date.format" for invalid formats when format is specified', t => { + t.is(date('field', '2015-05-05T10:00', { format: 'YYYY-MM-DD' }), 'date.format'); }); -test('rules.date should return "date/past" when date is not in past', t => { +test('rules.date should return "date.past" when date is not in past', t => { const inFuture = moment(new Date()).add(1, 'days'); - t.is(date('field', inFuture, { past: true }), 'date/past'); - t.is(date('field', moment(), { past: true }), 'date/past'); + t.is(date('field', inFuture, { past: true }), 'date.past'); + t.is(date('field', moment(), { past: true }), 'date.past'); }); -test('rules.date should return "date/future" when date is not in future', t => { +test('rules.date should return "date.future" when date is not in future', t => { const inPast = moment(new Date()).subtract(1, 'days'); - t.is(date('field', inPast, { future: true }), 'date/future'); - t.is(date('field', moment(), { future: true }), 'date/future'); + t.is(date('field', inPast, { future: true }), 'date.future'); + t.is(date('field', moment(), { future: true }), 'date.future'); }); diff --git a/src/rules/__tests__/length_tests.js b/src/rules/__tests__/length_tests.js index 9badfab..66c888d 100644 --- a/src/rules/__tests__/length_tests.js +++ b/src/rules/__tests__/length_tests.js @@ -8,19 +8,19 @@ test('rules.length should return null accepted values', t => { t.is(length('field', undefined, { min: 1, max: 1 }), null); }); -test('rules.length should return "length/min" when value is to short', t => { - t.is(length('field', '00', { min: 3 }), 'length/min'); +test('rules.length should return "length.min" when value is to short', t => { + t.is(length('field', '00', { min: 3 }), 'length.min'); }); -test('rules.length should return "length/max" when value is to long', t => { - t.is(length('field', '00', { max: 1 }), 'length/max'); +test('rules.length should return "length.max" when value is to long', t => { + t.is(length('field', '00', { max: 1 }), 'length.max'); }); -test('rules.length should return "length/max" when value is longer than exact', t => { - t.is(length('field', '00', { exact: 1 }), 'length/max'); +test('rules.length should return "length.max" when value is longer than exact', t => { + t.is(length('field', '00', { exact: 1 }), 'length.max'); }); -test('rules.length should return "length/min" when value is longer than exact', t => { - t.is(length('field', '', { exact: 1 }), 'length/min'); +test('rules.length should return "length.min" when value is longer than exact', t => { + t.is(length('field', '', { exact: 1 }), 'length.min'); }); diff --git a/src/rules/__tests__/numeric_tests.js b/src/rules/__tests__/numeric_tests.js index af79faf..d53d748 100644 --- a/src/rules/__tests__/numeric_tests.js +++ b/src/rules/__tests__/numeric_tests.js @@ -20,10 +20,10 @@ test('numeric should return null for integer values when integerOnly is true', t }); test( - 'numeric should return "numeric/integerOnly" for non-integer values when integerOnly is true', + 'numeric should return "numeric.integerOnly" for non-integer values when integerOnly is true', t => { - t.is(numeric('field', 42.2, { integerOnly: true }), 'numeric/integerOnly'); - t.is(numeric('field', '42.3', { integerOnly: true }), 'numeric/integerOnly'); + t.is(numeric('field', 42.2, { integerOnly: true }), 'numeric.integerOnly'); + t.is(numeric('field', '42.3', { integerOnly: true }), 'numeric.integerOnly'); } ); @@ -56,9 +56,9 @@ test('numeric should validate max value', t => { t.is(numeric('field', 41, { max: 42 }), null); t.is(numeric('field', 42, { max: 42 }), null); t.is(numeric('field', 41.9, { max: 42 }), null); - t.is(numeric('field', 43, { max: 42 }), 'numeric/max'); - t.is(numeric('field', 42.1, { max: 42 }), 'numeric/max'); - t.is(numeric('field', '43', { max: 42 }), 'numeric/max'); + t.is(numeric('field', 43, { max: 42 }), 'numeric.max'); + t.is(numeric('field', 42.1, { max: 42 }), 'numeric.max'); + t.is(numeric('field', '43', { max: 42 }), 'numeric.max'); }); test('numeric should validate min value', t => { @@ -66,18 +66,18 @@ test('numeric should validate min value', t => { t.is(numeric('field', 43, { min: 42 }), null); t.is(numeric('field', 42, { min: 42 }), null); t.is(numeric('field', 42.1, { min: 42 }), null); - t.is(numeric('field', 41.9, { min: 42 }), 'numeric/min'); - t.is(numeric('field', 41, { min: 42 }), 'numeric/min'); - t.is(numeric('field', '41', { min: 42 }), 'numeric/min'); + t.is(numeric('field', 41.9, { min: 42 }), 'numeric.min'); + t.is(numeric('field', 41, { min: 42 }), 'numeric.min'); + t.is(numeric('field', '41', { min: 42 }), 'numeric.min'); }); test('numeric should validate max value when set by other field', t => { t.is(numeric('field', 0, { max: { field: 'a' }, values: { a: 1 } }), null); - t.is(numeric('field', 2, { max: { field: 'a' }, values: { a: 1 } }), 'numeric/max/field/a'); + t.is(numeric('field', 2, { max: { field: 'a' }, values: { a: 1 } }), 'numeric.max.field'); }); test('numeric should validate min value when set by other field', t => { t.is(numeric('field', 2, { min: { field: 'a' }, values: { a: 1 } }), null); - t.is(numeric('field', 0, { min: { field: 'a' }, values: { a: 1 } }), 'numeric/min/field/a'); + t.is(numeric('field', 0, { min: { field: 'a' }, values: { a: 1 } }), 'numeric.min.field'); }); diff --git a/src/rules/ageByDate.js b/src/rules/ageByDate.js index 5458ee7..7c96c42 100644 --- a/src/rules/ageByDate.js +++ b/src/rules/ageByDate.js @@ -11,11 +11,11 @@ export function ageByDate(field, value, options) { } if (!isNil(min) && Math.abs(moment(value).diff(moment(), 'years')) < min) { - return 'ageByDate/min'; + return 'ageByDate.min'; } if (!isNil(max) && Math.abs(moment(value).diff(moment(), 'years')) > max) { - return 'ageByDate/max'; + return 'ageByDate.max'; } return null; diff --git a/src/rules/date.js b/src/rules/date.js index a24138b..527484b 100644 --- a/src/rules/date.js +++ b/src/rules/date.js @@ -3,15 +3,15 @@ import moment from 'moment'; export function date(field, value, options) { if (!moment(value, get(options, 'format'), true).isValid()) { - return 'date/format'; + return 'date.format'; } if (get(options, 'past') && moment(value).diff(moment(), 'days') >= 0) { - return 'date/past'; + return 'date.past'; } if (get(options, 'future') && moment(value).diff(moment(), 'days') <= 0) { - return 'date/future'; + return 'date.future'; } return null; diff --git a/src/rules/length.js b/src/rules/length.js index d5f7d4b..84ba3f2 100644 --- a/src/rules/length.js +++ b/src/rules/length.js @@ -14,11 +14,11 @@ export function length(field, value, options) { } if (!isNil(min) && value.length < min) { - return 'length/min'; + return 'length.min'; } if (!isNil(max) && value.length > max) { - return 'length/max'; + return 'length.max'; } return null; diff --git a/src/rules/numeric.js b/src/rules/numeric.js index 75ed472..8ac2d62 100644 --- a/src/rules/numeric.js +++ b/src/rules/numeric.js @@ -22,28 +22,28 @@ export function numeric(field, value, options) { } if (get(options, 'integerOnly') && !isInt(number.toString())) { - return 'numeric/integerOnly'; + return 'numeric.integerOnly'; } const min = get(options, 'min'); if (isObject(min)) { if (min.field && evaluateMin(number, get(options, `values.${min.field}`))) { - return `numeric/min/field/${min.field}`; + return 'numeric.min.field'; } } else { if (evaluateMin(number, min)) { - return 'numeric/min'; + return 'numeric.min'; } } const max = get(options, 'max'); if (isObject(max)) { if (max.field && evaluateMax(number, get(options, `values.${max.field}`))) { - return `numeric/max/field/${max.field}`; + return 'numeric.max.field'; } } else { if (evaluateMax(number, max)) { - return 'numeric/max'; + return 'numeric.max'; } }