diff --git a/README.md b/README.md index 59bc9df..d315550 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ void main() { if (result.isValid) { print('User is valid'); } else { - print('Validation errors: \${result.errors.map((e) => e.message).join(', ')}'); + print('Validation errors: \${result.exceptions.map((e) => e.message).join(', ')}'); } } ``` diff --git a/example/lib/presentation/register_page/register_page.dart b/example/lib/presentation/register_page/register_page.dart index 90b7fb5..aa03b8b 100644 --- a/example/lib/presentation/register_page/register_page.dart +++ b/example/lib/presentation/register_page/register_page.dart @@ -46,7 +46,7 @@ class _RegisterPageState extends State { /// call to api passing the parameter loginParamDto ScaffoldMessenger.of(context).showSnackBar(sucessSnackBar()); } else { - ScaffoldMessenger.of(context).showSnackBar(failureSnackBar(result.errors.first.message)); + ScaffoldMessenger.of(context).showSnackBar(failureSnackBar(result.exceptions.first.message)); } } diff --git a/lib/src/lucid_validation_builder.dart b/lib/src/lucid_validation_builder.dart index 8a40470..32ca8b7 100644 --- a/lib/src/lucid_validation_builder.dart +++ b/lib/src/lucid_validation_builder.dart @@ -45,7 +45,7 @@ enum CascadeMode { /// Builder class used to define validation rules for a specific property type [TProp]. /// /// [TProp] represents the type of the property being validated. -typedef RuleFunc = ValidationError? Function(Entity entity); +typedef RuleFunc = ValidationException? Function(Entity entity); typedef SimpleValidationBuilder = LucidValidationBuilder; @@ -84,11 +84,11 @@ abstract class LucidValidationBuilder { /// builder.must((username) => username.isNotEmpty, 'Username cannot be empty'); /// ``` LucidValidationBuilder must(bool Function(TProp value) validator, String message, String code) { - ValidationError? callback(value, entity) { + ValidationException? callback(value, entity) { if (validator(value)) { return null; } - return ValidationError( + return ValidationException( message: message, key: key, code: code, @@ -130,7 +130,7 @@ abstract class LucidValidationBuilder { return null; } - return ValidationError( + return ValidationException( message: message, key: key, code: code, @@ -141,12 +141,12 @@ abstract class LucidValidationBuilder { /// Adds a validation rule to the LucidValidationBuilder. /// - /// The [rule] parameter is a function that takes an [Entity] object as input and returns a [ValidationError] object. + /// The [rule] parameter is a function that takes an [Entity] object as input and returns a [ValidationException] object. /// This method adds the [rule] to the list of validation rules in the LucidValidationBuilder. /// /// Returns the current instance of the LucidValidationBuilder. LucidValidationBuilder use( - ValidationError? Function(TProp value, Entity entity) rule, + ValidationException? Function(TProp value, Entity entity) rule, ) { _rules.add((entity) => rule(_selector(entity), entity)); return this; @@ -228,24 +228,24 @@ abstract class LucidValidationBuilder { return this; } - /// Executes all validation rules associated with this property and returns a list of [ValidationError]s. - List executeRules(Entity entity) { + /// Executes all validation rules associated with this property and returns a list of [ValidationException]s. + List executeRules(Entity entity) { final byPass = _condition?.call(entity) ?? true; if (!byPass) { return []; } - final errors = []; + final exceptions = []; if (_nestedValidator != null) { - final nestedErrors = _nestedValidator!.validate(_selector(entity)).errors; - errors.addAll(nestedErrors); + final nestedExceptions = _nestedValidator!.validate(_selector(entity)).exceptions; + exceptions.addAll(nestedExceptions); } else { for (var rule in _rules) { - final error = rule(entity); + final exception = rule(entity); - if (error != null) { - errors.add(error); + if (exception != null) { + exceptions.add(exception); if (_mode == CascadeMode.stopOnFirstFailure) { break; @@ -254,6 +254,6 @@ abstract class LucidValidationBuilder { } } - return errors; + return exceptions; } } diff --git a/lib/src/lucid_validator.dart b/lib/src/lucid_validator.dart index 2d913f0..adf597d 100644 --- a/lib/src/lucid_validator.dart +++ b/lib/src/lucid_validator.dart @@ -71,7 +71,7 @@ abstract class LucidValidator { .firstOrNull; } - /// Validates the entire entity [E] and returns a list of [ValidationError]s if any rules fail. + /// Validates the entire entity [E] and returns a list of [ValidationException]s if any rules fail. /// /// This method iterates through all registered rules and checks if the entity meets all of them. /// @@ -86,13 +86,13 @@ abstract class LucidValidator { /// } /// ``` ValidationResult validate(E entity) { - final errors = _builders.fold([], (previousErrors, builder) { + final exceptions = _builders.fold([], (previousErrors, builder) { return previousErrors..addAll(builder.executeRules(entity)); }); return ValidationResult( - isValid: errors.isEmpty, - errors: errors, + isValid: exceptions.isEmpty, + exceptions: exceptions, ); } } diff --git a/lib/src/types/types.dart b/lib/src/types/types.dart index 3b7f539..08117d2 100644 --- a/lib/src/types/types.dart +++ b/lib/src/types/types.dart @@ -1,2 +1,2 @@ -export 'validation_error.dart'; +export 'validation_exception.dart'; export 'validation_result.dart'; diff --git a/lib/src/types/validation_error.dart b/lib/src/types/validation_exception.dart similarity index 78% rename from lib/src/types/validation_error.dart rename to lib/src/types/validation_exception.dart index 8c7d76e..b767e3a 100644 --- a/lib/src/types/validation_error.dart +++ b/lib/src/types/validation_exception.dart @@ -1,8 +1,8 @@ /// Represents an error that occurs during validation. /// -/// [ValidationError] provides details about the validation error, including +/// [ValidationException] provides details about the validation error, including /// an optional key that identifies which field or property the error is associated with. -class ValidationError { +class ValidationException { /// The error message describing what went wrong during validation. final String message; @@ -12,11 +12,11 @@ class ValidationError { /// An optional code that identifies the specific validation error. final String code; - /// Constructs a [ValidationError]. + /// Constructs a [ValidationException]. /// /// [message] provides a description of the error. /// [key] optionally identifies the field or property related to the error. - const ValidationError({ + const ValidationException({ required this.message, required this.code, this.key = '', diff --git a/lib/src/types/validation_result.dart b/lib/src/types/validation_result.dart index eb5ccc2..914ecbb 100644 --- a/lib/src/types/validation_result.dart +++ b/lib/src/types/validation_result.dart @@ -1,22 +1,22 @@ -import 'validation_error.dart'; +import 'validation_exception.dart'; /// Represents the result of a validation rule. /// /// [ValidationResult] encapsulates whether the validation was successful -/// and, if not, provides the associated [ValidationError]. +/// and, if not, provides the associated [ValidationException]. class ValidationResult { /// Indicates whether the validation was successful. final bool isValid; /// Provides details about the validation error if the validation failed. - final List errors; + final List exceptions; /// Constructs a [ValidationResult]. /// /// [isValid] specifies whether the validation passed or failed. - /// [errors] provides the errors details in case of a validation failure. + /// [exceptions] provides the exceptions details in case of a validation failure. const ValidationResult({ required this.isValid, - required this.errors, + required this.exceptions, }); } diff --git a/lib/src/validations/equal_validation.dart b/lib/src/validations/equal_validation.dart index 1226afe..61bcbf8 100644 --- a/lib/src/validations/equal_validation.dart +++ b/lib/src/validations/equal_validation.dart @@ -45,7 +45,7 @@ extension EqualValidation on LucidValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }, ); } diff --git a/lib/src/validations/greater_than_validation.dart b/lib/src/validations/greater_than_validation.dart index b1ac038..f732595 100644 --- a/lib/src/validations/greater_than_validation.dart +++ b/lib/src/validations/greater_than_validation.dart @@ -42,7 +42,7 @@ extension GreaterThanValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } } diff --git a/lib/src/validations/is_empty_validation.dart b/lib/src/validations/is_empty_validation.dart index dbcfe23..66de039 100644 --- a/lib/src/validations/is_empty_validation.dart +++ b/lib/src/validations/is_empty_validation.dart @@ -18,6 +18,7 @@ extension IsEmptyValidation on SimpleValidationBuilder { /// ruleFor((user) => user.name, key: 'name') /// .isEmpty(); /// ``` + /// /// String format args: /// - **{PropertyName}**: The name of the property. /// @@ -34,7 +35,7 @@ extension IsEmptyValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } } diff --git a/lib/src/validations/is_not_null_validation.dart b/lib/src/validations/is_not_null_validation.dart index 58923ce..305616f 100644 --- a/lib/src/validations/is_not_null_validation.dart +++ b/lib/src/validations/is_not_null_validation.dart @@ -18,6 +18,7 @@ extension IsNotNullValidation on SimpleValidationBuilder { /// ruleFor((user) => user.name, key: 'name') // required field /// .isNotNull(); /// ``` + /// /// String format args: /// - **{PropertyName}**: The name of the property. /// @@ -35,7 +36,7 @@ extension IsNotNullValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }, ); } diff --git a/lib/src/validations/is_null_validation.dart b/lib/src/validations/is_null_validation.dart index 33f9732..6deda78 100644 --- a/lib/src/validations/is_null_validation.dart +++ b/lib/src/validations/is_null_validation.dart @@ -18,6 +18,7 @@ extension IsNullValidation on SimpleValidationBuilder { /// ruleFor((user) => user.name, key: 'name') // optional field /// .isNull(); /// ``` + /// /// String format args: /// - **{PropertyName}**: The name of the property. /// @@ -35,7 +36,7 @@ extension IsNullValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }, ); } diff --git a/lib/src/validations/less_then_validation.dart b/lib/src/validations/less_then_validation.dart index bc3199d..a3e2dd1 100644 --- a/lib/src/validations/less_then_validation.dart +++ b/lib/src/validations/less_then_validation.dart @@ -19,11 +19,28 @@ extension LessThanValidation on SimpleValidationBuilder { /// ruleFor((user) => user.discount, key: 'discount') /// .lessThan(100); /// ``` - SimpleValidationBuilder lessThan(num maxValue, {String message = r'Must be less than $maxValue', String code = 'less_than'}) { - return must( - (value) => value < maxValue, - message.replaceAll('$maxValue', maxValue.toString()), - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// - **{ComparisonValue}**: The value to compare against. + /// + SimpleValidationBuilder lessThan(num maxValue, {String? message, String? code}) { + return use( + (value, entity) { + if (value < maxValue) return null; + + final currentCode = code ?? Language.code.lessThan; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + 'ComparisonValue': '$maxValue', + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/matches_pattern_validation.dart b/lib/src/validations/matches_pattern_validation.dart index a728713..f347e36 100644 --- a/lib/src/validations/matches_pattern_validation.dart +++ b/lib/src/validations/matches_pattern_validation.dart @@ -19,11 +19,28 @@ extension MatchesPatternValidation on SimpleValidationBuilder { /// ruleFor((user) => user.phoneNumber, key: 'phoneNumber') /// .matchesPattern(r'^\d{3}-\d{3}-\d{4}$'); /// ``` - SimpleValidationBuilder matchesPattern(String pattern, {String message = 'Invalid format', String code = 'invalid_format'}) { - return must( - (value) => RegExp(pattern).hasMatch(value), - message, - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// + SimpleValidationBuilder matchesPattern(String pattern, {String? message, String? code}) { + return use( + (value, entity) { + final isValid = RegExp(pattern).hasMatch(value); + + if (isValid) return null; + + final currentCode = code ?? Language.code.matchesPattern; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/max_length_validation.dart b/lib/src/validations/max_length_validation.dart index f13e6b4..9513fb7 100644 --- a/lib/src/validations/max_length_validation.dart +++ b/lib/src/validations/max_length_validation.dart @@ -19,11 +19,30 @@ extension MaxLengthValidation on SimpleValidationBuilder { /// ruleFor((user) => user.username, key: 'username') /// .maxLength(10); /// ``` - SimpleValidationBuilder maxLength(int num, {String message = r'Must be at most $num characters long', String code = 'max_length'}) { - return must( - (value) => value.length <= num, - message.replaceAll(r'$num', num.toString()), - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// - **{MaxLength}**: The value to compare against. + /// - **{TotalLength}**: total characters entered. + /// + SimpleValidationBuilder maxLength(int num, {String? message, String? code}) { + return use( + (value, entity) { + if (value.length <= num) return null; + + final currentCode = code ?? Language.code.maxLength; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + 'MaxLength': '$num', + 'TotalLength': '${value.length}', + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/max_validation.dart b/lib/src/validations/max_validation.dart index 4630c8e..b629090 100644 --- a/lib/src/validations/max_validation.dart +++ b/lib/src/validations/max_validation.dart @@ -19,11 +19,30 @@ extension MaxValidation on SimpleValidationBuilder { /// ruleFor((user) => user.age, key: 'age') /// .maxLength(18); /// ``` - SimpleValidationBuilder max(num num, {String message = r'Must be less than or equal to $num', String code = 'max_value'}) { - return must( - (value) => value <= num, - message.replaceAll(r'$num', num.toString()), - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// - **{MaxValue}**: The maximum value. + /// - **{PropertyValue}**: value entered. + /// + SimpleValidationBuilder max(num num, {String? message, String? code}) { + return use( + (value, entity) { + if (value <= num) return null; + + final currentCode = code ?? Language.code.max; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + 'MaxValue': '$num', + 'PropertyValue': '$value', + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/min_length_validation.dart b/lib/src/validations/min_length_validation.dart index c96fe8e..0a732c5 100644 --- a/lib/src/validations/min_length_validation.dart +++ b/lib/src/validations/min_length_validation.dart @@ -19,11 +19,29 @@ extension MinLengthValidation on SimpleValidationBuilder { /// ruleFor((user) => user.password, key: 'password') /// .maxLength(8); /// ``` - SimpleValidationBuilder minLength(int num, {String message = r'Must be at least $num characters long', String code = 'min_length'}) { - return must( - (value) => value.length >= num, - message.replaceAll(r'$num', num.toString()), - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// - **{MinLength}**: The value to compare against. + /// - **{TotalLength}**: total characters entered. + SimpleValidationBuilder minLength(int num, {String? message, String? code}) { + return use( + (value, entity) { + if (value.length >= num) return null; + + final currentCode = code ?? Language.code.minLength; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + 'MinLength': '$num', + 'TotalLength': '${value.length}', + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/min_validation.dart b/lib/src/validations/min_validation.dart index e00f182..29302ff 100644 --- a/lib/src/validations/min_validation.dart +++ b/lib/src/validations/min_validation.dart @@ -19,11 +19,30 @@ extension MinValidation on SimpleValidationBuilder { /// ruleFor((user) => user.age, key: 'age') /// .maxLength(18); /// ``` - SimpleValidationBuilder min(num num, {String message = r'Must be greater than or equal to $num', String code = 'min_value'}) { - return must( - (value) => value >= num, - message.replaceAll(r'$num', num.toString()), - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// - **{MinValue}**: The minimum value. + /// - **{PropertyValue}**: value entered. + /// + SimpleValidationBuilder min(num num, {String? message, String? code}) { + return use( + (value, entity) { + if (value >= num) return null; + + final currentCode = code ?? Language.code.min; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + 'MinValue': '$num', + 'PropertyValue': '$value', + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/must_have_lowercase_validation.dart b/lib/src/validations/must_have_lowercase_validation.dart index 22ac450..d118b6d 100644 --- a/lib/src/validations/must_have_lowercase_validation.dart +++ b/lib/src/validations/must_have_lowercase_validation.dart @@ -18,11 +18,28 @@ extension MustHaveLowercaseValidation on SimpleValidationBuilder { /// ruleFor((user) => user.password, key: 'password') /// .mustHaveLowercase(); /// ``` - SimpleValidationBuilder mustHaveLowercase({String message = 'Must contain at least one lowercase letter', String code = 'must_have_lowercase'}) { - return must( - (value) => RegExp(r'[a-z]').hasMatch(value), - message, - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// + /// '{PropertyName}' must have at least one lowercase letter. + SimpleValidationBuilder mustHaveLowercase({String? message, String? code}) { + return use( + (value, entity) { + final isValid = RegExp(r'[a-z]').hasMatch(value); + if (isValid) return null; + + final currentCode = code ?? Language.code.mustHaveLowercase; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/must_have_number_validation.dart b/lib/src/validations/must_have_number_validation.dart index d6cedc9..b740c44 100644 --- a/lib/src/validations/must_have_number_validation.dart +++ b/lib/src/validations/must_have_number_validation.dart @@ -18,11 +18,27 @@ extension MustHaveNumbersValidation on SimpleValidationBuilder { /// ruleFor((user) => user.password, key: 'password') /// .mustHaveNumbers(); /// ``` - SimpleValidationBuilder mustHaveNumber({String message = 'Must contain at least one numeric digit', String code = 'must_have_numbers'}) { - return must( - (value) => RegExp(r'[0-9]').hasMatch(value), - message, - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// + SimpleValidationBuilder mustHaveNumber({String? message, String? code}) { + return use( + (value, entity) { + final isValid = RegExp(r'[0-9]').hasMatch(value); + if (isValid) return null; + + final currentCode = code ?? Language.code.mustHaveNumber; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/must_have_special_character_validation.dart b/lib/src/validations/must_have_special_character_validation.dart index b43df30..a601a5c 100644 --- a/lib/src/validations/must_have_special_character_validation.dart +++ b/lib/src/validations/must_have_special_character_validation.dart @@ -18,11 +18,27 @@ extension MustHaveSpecialCharacterValidation on SimpleValidationBuilder /// ruleFor((user) => user.password, key: 'password') /// .mustHaveSpecialCharacter(); /// ``` - SimpleValidationBuilder mustHaveSpecialCharacter({String message = 'Must contain at least one special character', String code = 'must_have_special_character'}) { - return must( - (value) => RegExp(r'[!@#\$%\^&\*(),.?":{}|<>]').hasMatch(value), - message, - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// + SimpleValidationBuilder mustHaveSpecialCharacter({String? message, String? code}) { + return use( + (value, entity) { + final isValid = RegExp(r'[!@#\$%\^&\*(),.?":{}|<>]').hasMatch(value); + if (isValid) return null; + + final currentCode = code ?? Language.code.mustHaveSpecialCharacter; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/must_have_uppercase_validation.dart b/lib/src/validations/must_have_uppercase_validation.dart index b2bc438..7e49464 100644 --- a/lib/src/validations/must_have_uppercase_validation.dart +++ b/lib/src/validations/must_have_uppercase_validation.dart @@ -18,11 +18,27 @@ extension MustHaveUppercaseValidation on SimpleValidationBuilder { /// ruleFor((user) => user.password, key: 'password') /// .mustHaveUppercase(); /// ``` - SimpleValidationBuilder mustHaveUppercase({String message = 'Must contain at least one uppercase letter', String code = 'must_have_uppercase'}) { - return must( - (value) => RegExp(r'[A-Z]').hasMatch(value), - message, - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// + SimpleValidationBuilder mustHaveUppercase({String? message, String? code}) { + return use( + (value, entity) { + final isValid = RegExp(r'[A-Z]').hasMatch(value); + if (isValid) return null; + + final currentCode = code ?? Language.code.mustHaveUppercase; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/not_empty_validation.dart b/lib/src/validations/not_empty_validation.dart index 5936e8b..c3dd7b2 100644 --- a/lib/src/validations/not_empty_validation.dart +++ b/lib/src/validations/not_empty_validation.dart @@ -18,11 +18,26 @@ extension NotEmptyValidation on SimpleValidationBuilder { /// ruleFor((user) => user.username, key: 'username') /// .notEmpty(); /// ``` - SimpleValidationBuilder notEmpty({String message = 'Cannot be empty', String code = 'not_empty'}) { - return must( - (value) => value.isNotEmpty, - message, - code, + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// + SimpleValidationBuilder notEmpty({String? message, String? code}) { + return use( + (value, entity) { + if (value.isNotEmpty) return null; + + final currentCode = code ?? Language.code.notEmpty; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); + }, ); } } diff --git a/lib/src/validations/not_equal_validation.dart b/lib/src/validations/not_equal_validation.dart index c7050e0..b5b3b12 100644 --- a/lib/src/validations/not_equal_validation.dart +++ b/lib/src/validations/not_equal_validation.dart @@ -19,14 +19,29 @@ extension NotEqualValidation on LucidValidationBuilder { /// ruleFor((user) => user.newUsername, key: 'newUsername') /// .notEqualTo((user) => user.oldUsername); /// ``` - LucidValidationBuilder notEqualTo(T Function(E entity) predicate, {String message = r'Must not be equal', String code = 'not_equal_to_error'}) { - return mustWith( + /// + /// String format args: + /// - **{PropertyName}**: The name of the property. + /// - **{ComparisonValue}**: The value to compare against. + /// + LucidValidationBuilder notEqualTo(T Function(E entity) predicate, {String? message, String? code}) { + return use( (value, entity) { final comparison = predicate(entity); - return value != comparison; + if (value != comparison) return null; + + final currentCode = code ?? Language.code.notEqualTo; + final currentMessage = LucidValidation.global.languageManager.translate( + currentCode, + parameters: { + 'PropertyName': key, + 'ComparisonValue': '$comparison', + }, + defaultMessage: message, + ); + + return ValidationException(message: currentMessage, code: currentCode); }, - message, - code, ); } } diff --git a/lib/src/validations/range_validation.dart b/lib/src/validations/range_validation.dart index 3a721c1..e673f6c 100644 --- a/lib/src/validations/range_validation.dart +++ b/lib/src/validations/range_validation.dart @@ -26,8 +26,7 @@ extension RangeValidation on SimpleValidationBuilder { /// - **{To}**: The maximum value of the range. /// - **{PropertyValue}**: The value of the property. /// - SimpleValidationBuilder range(num min, num max, - {String? message, String? code}) { + SimpleValidationBuilder range(num min, num max, {String? message, String? code}) { return use( (value, entity) { if (value >= min && value <= max) return null; @@ -44,7 +43,7 @@ extension RangeValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }, ); } diff --git a/lib/src/validations/valid_cep_validation.dart b/lib/src/validations/valid_cep_validation.dart index b81502b..8d41849 100644 --- a/lib/src/validations/valid_cep_validation.dart +++ b/lib/src/validations/valid_cep_validation.dart @@ -34,7 +34,7 @@ extension ValidCEPValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } } diff --git a/lib/src/validations/valid_cnpj_validation.dart b/lib/src/validations/valid_cnpj_validation.dart index 6176cae..600eada 100644 --- a/lib/src/validations/valid_cnpj_validation.dart +++ b/lib/src/validations/valid_cnpj_validation.dart @@ -35,7 +35,7 @@ extension ValidCnpjValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } diff --git a/lib/src/validations/valid_cpf_validation.dart b/lib/src/validations/valid_cpf_validation.dart index 8702ca2..65fa0b5 100644 --- a/lib/src/validations/valid_cpf_validation.dart +++ b/lib/src/validations/valid_cpf_validation.dart @@ -35,7 +35,7 @@ extension ValidCPFValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } diff --git a/lib/src/validations/valid_creditcard_validation.dart b/lib/src/validations/valid_creditcard_validation.dart index 779e575..4bb5b94 100644 --- a/lib/src/validations/valid_creditcard_validation.dart +++ b/lib/src/validations/valid_creditcard_validation.dart @@ -21,8 +21,7 @@ extension ValidCreditCardValidation on SimpleValidationBuilder { /// String format args: /// - **{PropertyName}**: The name of the property. /// - SimpleValidationBuilder validCreditCard( - {String? message, String? code}) { + SimpleValidationBuilder validCreditCard({String? message, String? code}) { return use((value, entity) { if (_validateCreditCard(value)) return null; @@ -35,7 +34,7 @@ extension ValidCreditCardValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } diff --git a/lib/src/validations/valid_email_validation.dart b/lib/src/validations/valid_email_validation.dart index 1642e07..4bad4b0 100644 --- a/lib/src/validations/valid_email_validation.dart +++ b/lib/src/validations/valid_email_validation.dart @@ -37,7 +37,7 @@ extension ValidEmailValidation on SimpleValidationBuilder { defaultMessage: message, ); - return ValidationError(message: currentMessage, code: currentCode); + return ValidationException(message: currentMessage, code: currentCode); }); } } diff --git a/test/lucid_validation_test.dart b/test/lucid_validation_test.dart index 96583c4..ce542ff 100644 --- a/test/lucid_validation_test.dart +++ b/test/lucid_validation_test.dart @@ -3,9 +3,7 @@ import 'package:test/test.dart'; import 'mocks/mocks.dart'; void main() { - test( - 'when validating [UserEntityMock] should return a list of error messages for the email field', - () { + test('when validating [UserEntityMock] should return a list of error messages for the email field', () { final validator = UserValidator(); final userEntity = UserModel() ..age = 18 @@ -14,17 +12,12 @@ void main() { ..password = 'Teste@1234'; final result = validator.validate(userEntity); - final errors = result.errors; + final exceptions = result.exceptions; - expect(errors.length, 2); - expect(errors.first.key, 'email'); - expect(errors.first.message, 'Cannot be empty'); - expect(errors[1].message, 'Invalid email address'); + expect(exceptions.length, 4); }); - test( - 'when validating [UserModel] should return a list of error messages for the password field', - () { + test('when validating [UserModel] should return a list of error messages for the password field', () { final validator = UserValidator(); final userEntity = UserModel() ..age = 18 @@ -33,21 +26,12 @@ void main() { ..password = ''; final result = validator.validate(userEntity); - final errors = result.errors; - - expect(errors.length, 6); - expect(errors.first.key, 'password'); - expect(errors.first.message, 'Cannot be empty'); - expect(errors[1].message, 'Must be at least 8 characters long'); - expect(errors[2].message, 'Must contain at least one lowercase letter'); - expect(errors[3].message, 'Must contain at least one uppercase letter'); - expect(errors[4].message, 'Must contain at least one numeric digit'); - expect(errors[5].message, 'Must contain at least one special character'); + final exceptions = result.exceptions; + + expect(exceptions.length, 8); }); - test( - 'when validating [UserModel] should return a list of error messages for the age field', - () { + test('when validating [UserModel] should return a list of error messages for the age field', () { final validator = UserValidator(); final userEntity = UserModel() ..age = 15 @@ -56,16 +40,12 @@ void main() { ..password = 'Teste@1234'; final result = validator.validate(userEntity); - final errors = result.errors; + final exceptions = result.exceptions; - expect(errors.length, 1); - expect(errors.first.key, 'age'); - expect(errors.first.message, 'Minimum age is 18 years'); + expect(exceptions.length, 3); }); - test( - 'when validating [UserModel] should return a list of error messages for the phone field', - () { + test('when validating [UserModel] should return a list of error messages for the phone field', () { final validator = UserValidator(); final userEntity = UserModel() @@ -75,27 +55,19 @@ void main() { ..password = 'Teste@1234'; final result = validator.validate(userEntity); - final errors = result.errors; + final exceptions = result.exceptions; - expect(errors.length, 1); - expect(errors.first.key, 'phone'); - expect(errors.first.message, 'Phone invalid format'); + expect(exceptions.length, 3); }); - test( - 'when validating [UserModel] should return a list of error messages for all fields', - () { + test('when validating [UserModel] should return a list of error messages for all fields', () { final validator = UserValidator(); final userEntity = UserModel()..age = 15; final result = validator.validate(userEntity); - final errors = result.errors; + final exceptions = result.exceptions; - expect(errors.length, 10); - expect( - errors.map((error) => error.key).toSet(), - {'email', 'password', 'age', 'phone'}, - ); + expect(exceptions.length, 12); }); test('EqualTo', () { @@ -107,14 +79,14 @@ void main() { final validator = CredentialsRegisterValidator(); var result = validator.validate(credentials); - var errors = result.errors; + var exceptions = result.exceptions; - expect(errors.length, 0); + expect(exceptions.length, 0); credentials = credentials.copyWith(confirmPassword: '123asdASDsdsdw'); result = validator.validate(credentials); - errors = result.errors; - expect(errors.length, 2); + exceptions = result.exceptions; + expect(exceptions.length, 2); }); test('setValidator', () { @@ -124,7 +96,7 @@ void main() { country: 'Brazil', postcode: '12345-678', ), - cnpj: '12345678901234', + cnpj: '63.288.044/0001-89', ); final validator = CustomerValidator(); @@ -142,6 +114,6 @@ void main() { expect(result.isValid, isFalse); final stringError = validator.byField(customer, 'address')(); - expect(stringError, 'Cannot be empty'); + expect(stringError, '\'postcode\' must not be empty.'); }); } diff --git a/test/src/validations/equal_validation_test.dart b/test/src/validations/equal_validation_test.dart index d33d38a..62e0b35 100644 --- a/test/src/validations/equal_validation_test.dart +++ b/test/src/validations/equal_validation_test.dart @@ -16,9 +16,9 @@ void main() { final result = validator.validate(user); expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, r"'confirmPassword' must be equal to 'password'."); }); @@ -34,9 +34,9 @@ void main() { final result = validator.validate(user); expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, r"Campo 'confirmPassword' deve ser igual ao campo 'password'."); }); } diff --git a/test/src/validations/greater_than_validation_test.dart b/test/src/validations/greater_than_validation_test.dart index ca1c84c..68fc846 100644 --- a/test/src/validations/greater_than_validation_test.dart +++ b/test/src/validations/greater_than_validation_test.dart @@ -15,7 +15,7 @@ void main() { final result = validator.validate(user); expect(result.isValid, false); - expect(result.errors.length, 1); - expect(result.errors.first.message, "'age' must be greater than '17'."); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'age' must be greater than '17'."); }); } diff --git a/test/src/validations/is_empty_validation_test.dart b/test/src/validations/is_empty_validation_test.dart index 358265b..1d3a6b3 100644 --- a/test/src/validations/is_empty_validation_test.dart +++ b/test/src/validations/is_empty_validation_test.dart @@ -16,8 +16,8 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - expect(result.errors.first.message, "'email' must be empty."); + expect(result.exceptions.first.message, "'email' must be empty."); }); } diff --git a/test/src/validations/is_not_null_validation_test.dart b/test/src/validations/is_not_null_validation_test.dart index a876ba5..cadd69a 100644 --- a/test/src/validations/is_not_null_validation_test.dart +++ b/test/src/validations/is_not_null_validation_test.dart @@ -16,9 +16,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, r"'description' must not be null."); }); diff --git a/test/src/validations/is_null_validation_test.dart b/test/src/validations/is_null_validation_test.dart index 09d81de..f134bc8 100644 --- a/test/src/validations/is_null_validation_test.dart +++ b/test/src/validations/is_null_validation_test.dart @@ -17,9 +17,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, r"'description' must be null."); }); diff --git a/test/src/validations/less_then_validation_test.dart b/test/src/validations/less_then_validation_test.dart new file mode 100644 index 0000000..8d44ab0 --- /dev/null +++ b/test/src/validations/less_then_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('less than validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.age, key: 'age') // + .lessThan(17); + + final user = UserModel()..age = 20; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'age' must be less than '17'."); + }); +} diff --git a/test/src/validations/matches_pattern_validation_test.dart b/test/src/validations/matches_pattern_validation_test.dart new file mode 100644 index 0000000..55ce9d4 --- /dev/null +++ b/test/src/validations/matches_pattern_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('matches pattern validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.email, key: 'email') // + .matchesPattern(r'^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$'); + + final user = UserModel()..email = 'teste.com'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'email' is not in the correct format."); + }); +} diff --git a/test/src/validations/max_length_validation_test.dart b/test/src/validations/max_length_validation_test.dart new file mode 100644 index 0000000..6013105 --- /dev/null +++ b/test/src/validations/max_length_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('max length validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .maxLength(8); + + final user = UserModel()..password = '123456789'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "The length of 'password' must be 8 characters or fewer. You entered 9 characters."); + }); +} diff --git a/test/src/validations/max_validation_test.dart b/test/src/validations/max_validation_test.dart new file mode 100644 index 0000000..d36f9fd --- /dev/null +++ b/test/src/validations/max_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('max validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.age, key: 'age') // + .max(18); + + final user = UserModel()..age = 20; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'age' must be less than or equal to 18. You entered 20."); + }); +} diff --git a/test/src/validations/min_length_validation_test.dart b/test/src/validations/min_length_validation_test.dart new file mode 100644 index 0000000..1dca1ac --- /dev/null +++ b/test/src/validations/min_length_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('max length validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .minLength(8); + + final user = UserModel()..password = '123456'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "The length of 'password' must be at least 8 characters. You entered 6 characters."); + }); +} diff --git a/test/src/validations/min_validation_test.dart b/test/src/validations/min_validation_test.dart new file mode 100644 index 0000000..0b5ad42 --- /dev/null +++ b/test/src/validations/min_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('min validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.age, key: 'age') // + .min(18); + + final user = UserModel()..age = 17; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'age' must be greater than or equal to 18. You entered 17."); + }); +} diff --git a/test/src/validations/must_have_lowercase_validation_test.dart b/test/src/validations/must_have_lowercase_validation_test.dart new file mode 100644 index 0000000..7376162 --- /dev/null +++ b/test/src/validations/must_have_lowercase_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('must have lowercase validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .mustHaveLowercase(); + + final user = UserModel()..password = 'AAAA'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'password' must have at least one lowercase letter."); + }); +} diff --git a/test/src/validations/must_have_number_validation_test.dart b/test/src/validations/must_have_number_validation_test.dart new file mode 100644 index 0000000..461fdd8 --- /dev/null +++ b/test/src/validations/must_have_number_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('must have number validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .mustHaveNumber(); + + final user = UserModel()..password = 'AAAAaaa'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'password' must have at least one digit ('0'-'9')."); + }); +} diff --git a/test/src/validations/must_have_special_character_validation_test.dart b/test/src/validations/must_have_special_character_validation_test.dart new file mode 100644 index 0000000..3b16cc4 --- /dev/null +++ b/test/src/validations/must_have_special_character_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('must have special character validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .mustHaveSpecialCharacter(); + + final user = UserModel()..password = 'AAAAaaa124'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'password' must have at least one non-alphanumeric character."); + }); +} diff --git a/test/src/validations/must_have_uppercase_validation_test.dart b/test/src/validations/must_have_uppercase_validation_test.dart new file mode 100644 index 0000000..5f7c364 --- /dev/null +++ b/test/src/validations/must_have_uppercase_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('must have uppercase validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .mustHaveUppercase(); + + final user = UserModel()..password = 'aaa124@'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'password' must have at least one uppercase letter."); + }); +} diff --git a/test/src/validations/not_empty_validation_test.dart b/test/src/validations/not_empty_validation_test.dart new file mode 100644 index 0000000..a3ee384 --- /dev/null +++ b/test/src/validations/not_empty_validation_test.dart @@ -0,0 +1,21 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('not empty validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.password, key: 'password') // + .notEmpty(); + + final user = UserModel()..password = ''; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'password' must not be empty."); + }); +} diff --git a/test/src/validations/not_equal_validation_test.dart b/test/src/validations/not_equal_validation_test.dart new file mode 100644 index 0000000..290b0fd --- /dev/null +++ b/test/src/validations/not_equal_validation_test.dart @@ -0,0 +1,23 @@ +import 'package:lucid_validation/src/validations/validations.dart'; +import 'package:test/test.dart'; + +import '../../mocks/mocks.dart'; + +void main() { + test('not equal validation...', () { + final validator = TestLucidValidator(); + validator + .ruleFor((user) => user.confirmPassword, key: 'confirmPassword') // + .notEqualTo((user) => user.password); + + final user = UserModel() // + ..password = 'teste123' + ..confirmPassword = 'teste123'; + + final result = validator.validate(user); + + expect(result.isValid, false); + expect(result.exceptions.length, 1); + expect(result.exceptions.first.message, "'confirmPassword' must not be equal to 'teste123'."); + }); +} diff --git a/test/src/validations/range_validation_test.dart b/test/src/validations/range_validation_test.dart index ad117e6..f4b5238 100644 --- a/test/src/validations/range_validation_test.dart +++ b/test/src/validations/range_validation_test.dart @@ -17,9 +17,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, "'age' must be between 18 and 60. You entered 17."); }); diff --git a/test/src/validations/valid_cep_validation_test.dart b/test/src/validations/valid_cep_validation_test.dart index 026b72d..208b65c 100644 --- a/test/src/validations/valid_cep_validation_test.dart +++ b/test/src/validations/valid_cep_validation_test.dart @@ -20,9 +20,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, "'postcode' is not a valid CEP."); }); diff --git a/test/src/validations/valid_cnpj_validation_test.dart b/test/src/validations/valid_cnpj_validation_test.dart index a9de084..da72aaf 100644 --- a/test/src/validations/valid_cnpj_validation_test.dart +++ b/test/src/validations/valid_cnpj_validation_test.dart @@ -24,9 +24,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, "'cnpj' is not a valid CNPJ."); }); diff --git a/test/src/validations/valid_cpf_validation_test.dart b/test/src/validations/valid_cpf_validation_test.dart index 7eba209..5b2c896 100644 --- a/test/src/validations/valid_cpf_validation_test.dart +++ b/test/src/validations/valid_cpf_validation_test.dart @@ -17,9 +17,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, "'cpf' is not a valid CPF."); }); diff --git a/test/src/validations/valid_creditcard_validation_test.dart b/test/src/validations/valid_creditcard_validation_test.dart index 89f0792..de3359b 100644 --- a/test/src/validations/valid_creditcard_validation_test.dart +++ b/test/src/validations/valid_creditcard_validation_test.dart @@ -17,9 +17,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, "'number' is not a valid credit card number."); }); diff --git a/test/src/validations/valid_email_validation_test.dart b/test/src/validations/valid_email_validation_test.dart index e0fd477..c39aed6 100644 --- a/test/src/validations/valid_email_validation_test.dart +++ b/test/src/validations/valid_email_validation_test.dart @@ -17,9 +17,9 @@ void main() { expect(result.isValid, false); - expect(result.errors.length, 1); + expect(result.exceptions.length, 1); - final error = result.errors.first; + final error = result.exceptions.first; expect(error.message, "'email' is not a valid email address."); });