From 0ddecbc44e7cd784dbe65a6d2271dfe4c2de3e12 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 3 Aug 2018 18:06:02 -0400 Subject: [PATCH] Enum validation tests --- graphql_schema/test/validation_test.dart | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/graphql_schema/test/validation_test.dart b/graphql_schema/test/validation_test.dart index 3645f7de..a6c8edd3 100644 --- a/graphql_schema/test/validation_test.dart +++ b/graphql_schema/test/validation_test.dart @@ -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); + }); }