Enum validation tests

This commit is contained in:
Tobe O 2018-08-03 18:06:02 -04:00
parent ceced6726d
commit 0ddecbc44e

View file

@ -2,8 +2,21 @@ import 'package:graphql_schema/graphql_schema.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {
var typeType = new GraphQLEnumType('Type', [
'FIRE',
'WATER',
'GRASS',
]);
var pokemonType = objectType('Pokémon', fields: [ var pokemonType = objectType('Pokémon', fields: [
field('name', type: graphQLString.nonNullable()), field(
'name',
type: graphQLString.nonNullable(),
),
field(
'type',
type: typeType,
),
]); ]);
var isValidPokemon = predicate( var isValidPokemon = predicate(
@ -29,4 +42,12 @@ void main() {
test('rejects extraneous fields', () { test('rejects extraneous fields', () {
expect({'name': 'Vulpix', 'foo': 'bar'}, isNot(isValidPokemon)); expect({'name': 'Vulpix', 'foo': 'bar'}, isNot(isValidPokemon));
}); });
test('enum accepts valid value', () {
expect(typeType.validate('@root', 'FIRE').successful, true);
});
test('enum rejects invalid value', () {
expect(typeType.validate('@root', 'POISON').successful, false);
});
} }