Enum validation tests
This commit is contained in:
parent
ceced6726d
commit
0ddecbc44e
1 changed files with 22 additions and 1 deletions
|
@ -2,8 +2,21 @@ import 'package:graphql_schema/graphql_schema.dart';
|
|||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
var typeType = new GraphQLEnumType('Type', [
|
||||
'FIRE',
|
||||
'WATER',
|
||||
'GRASS',
|
||||
]);
|
||||
|
||||
var pokemonType = objectType('Pokémon', fields: [
|
||||
field('name', type: graphQLString.nonNullable()),
|
||||
field(
|
||||
'name',
|
||||
type: graphQLString.nonNullable(),
|
||||
),
|
||||
field(
|
||||
'type',
|
||||
type: typeType,
|
||||
),
|
||||
]);
|
||||
|
||||
var isValidPokemon = predicate(
|
||||
|
@ -29,4 +42,12 @@ void main() {
|
|||
test('rejects extraneous fields', () {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue