Added basic validation tests to graphql_schema
This commit is contained in:
parent
ca87fbdba9
commit
2ff531eb4f
3 changed files with 44 additions and 0 deletions
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="tests in validation_test.dart" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true" nameIsGenerated="true">
|
||||||
|
<option name="filePath" value="$PROJECT_DIR$/graphql_schema/test/validation_test.dart" />
|
||||||
|
<option name="testRunnerOptions" value="-j4" />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
32
graphql_schema/test/validation_test.dart
Normal file
32
graphql_schema/test/validation_test.dart
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import 'package:graphql_schema/graphql_schema.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
var pokemonType = objectType('Pokémon', fields: [
|
||||||
|
field('name', type: graphQLString.nonNullable()),
|
||||||
|
]);
|
||||||
|
|
||||||
|
var isValidPokemon = predicate(
|
||||||
|
(x) =>
|
||||||
|
pokemonType.validate('@root', x as Map<String, dynamic>).successful,
|
||||||
|
'is a valid Pokémon');
|
||||||
|
|
||||||
|
var throwsATypeError =
|
||||||
|
throwsA(predicate((x) => x is TypeError, 'is a type error'));
|
||||||
|
|
||||||
|
test('mismatched scalar type', () {
|
||||||
|
expect(() => pokemonType.validate('@root', {'name': 24}), throwsATypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('empty passed for non-nullable', () {
|
||||||
|
expect(<String, dynamic>{}, isNot(isValidPokemon));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('null passed for non-nullable', () {
|
||||||
|
expect({'name': null}, isNot(isValidPokemon));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rejects extraneous fields', () {
|
||||||
|
expect({'name': 'Vulpix', 'foo': 'bar'}, isNot(isValidPokemon));
|
||||||
|
});
|
||||||
|
}
|
5
graphql_server/test/common.dart
Normal file
5
graphql_server/test/common.dart
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import 'package:graphql_schema/graphql_schema.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
final Matcher throwsAGraphQLException =
|
||||||
|
throwsA(predicate((x) => x is GraphQLException, 'is a GraphQL exception'));
|
Loading…
Reference in a new issue