2018-08-03 22:41:13 +00:00
|
|
|
import 'package:graphql_schema/graphql_schema.dart';
|
|
|
|
import 'package:graphql_server/mirrors.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
group('convertDartType', () {
|
|
|
|
group('on enum', () {
|
2019-04-24 17:06:14 +00:00
|
|
|
// ignore: deprecated_member_use_from_same_package
|
2018-08-03 22:41:13 +00:00
|
|
|
var type = convertDartType(RomanceLanguage);
|
|
|
|
var asEnumType = type as GraphQLEnumType;
|
|
|
|
|
|
|
|
test('produces enum type', () {
|
|
|
|
expect(type is GraphQLEnumType, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('rejects invalid value', () {
|
|
|
|
expect(asEnumType.validate('@root', 'GERMAN').successful, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('accepts valid value', () {
|
|
|
|
expect(asEnumType.validate('@root', 'SPANISH').successful, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('deserializes to concrete value', () {
|
|
|
|
expect(asEnumType.deserialize('ITALIAN'), RomanceLanguage.ITALIAN);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('serializes to concrete value', () {
|
|
|
|
expect(asEnumType.serialize(RomanceLanguage.FRANCE), 'FRANCE');
|
|
|
|
});
|
|
|
|
|
2018-08-03 22:42:35 +00:00
|
|
|
test('can serialize null', () {
|
|
|
|
expect(asEnumType.serialize(null), null);
|
|
|
|
});
|
|
|
|
|
2018-08-03 22:41:13 +00:00
|
|
|
test('fails to serialize invalid value', () {
|
|
|
|
expect(() => asEnumType.serialize(34), throwsStateError);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('fails to deserialize invalid value', () {
|
|
|
|
expect(() => asEnumType.deserialize('JAPANESE'), throwsStateError);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-29 18:32:31 +00:00
|
|
|
@graphQLClass
|
2018-08-03 22:41:13 +00:00
|
|
|
enum RomanceLanguage {
|
|
|
|
SPANISH,
|
|
|
|
FRANCE,
|
|
|
|
ITALIAN,
|
|
|
|
}
|