Skip to content

Commit

Permalink
test(luthor): Add tests for map validator
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Dec 24, 2024
1 parent fbd3103 commit 05a3d63
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/luthor/test/validations/map_validation_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:luthor/luthor.dart';
import 'package:test/test.dart';

void main() {
test('should return true when value is a map', () {
final result = l.map().validateValue({});

switch (result) {
case SingleValidationSuccess(data: _):
expect(result.data, {});
case SingleValidationError(data: _, errors: _):
fail('should not have errors');
}
});

test('should return false when value is not a map', () {
final result = l.map().validateValue('a');

switch (result) {
case SingleValidationSuccess(data: _):
fail('should not be a success');
case SingleValidationError(data: _, errors: final errors):
expect(errors, ['value must be a Map']);
}
});

test('should return true when value is null', () {
final result = l.map().validateValue(null);

switch (result) {
case SingleValidationSuccess(data: _):
expect(result.data, isNull);
case SingleValidationError(data: _, errors: _):
fail('should not have errors');
}
});

test('should return false if the value is null with required()', () {
final result = l.required().map().validateValue(null);

switch (result) {
case SingleValidationSuccess(data: _):
fail('should not be a success');
case SingleValidationError(data: _, errors: final errors):
expect(errors, ['value is required']);
}
});
}

0 comments on commit 05a3d63

Please sign in to comment.