@@ -2,41 +2,42 @@ import { GraphQLEnumType } from 'graphql/type';
22import { parse } from 'graphql/language' ;
33import buildEnum , { buildEnumValueConfigMap } from '../buildEnum' ;
44
5- const generateEnumAST = ( { description, name = 'Enum' , values = [ 'VALUE' ] } = { } ) => parse ( `
5+ const generateEnumNode = ( { description, name = 'Enum' , values = [ 'VALUE' ] } = { } ) => parse ( `
66 # ${ description === undefined ? '' : description }
77 enum ${ name } {
88 ${ values . join ( '\n' ) }
99 }
1010` ) . definitions [ 0 ] ;
1111const generateEnumValueConfigMap = ( {
1212 name = 'VALUE' ,
13- value = 'VALUE' ,
14- description,
13+ value,
1514 deprecationReason,
16- } = { } ) => ( { [ name ] : { value, description, deprecationReason } } ) ;
15+ description,
16+ } = { } ) => ( name ? ( { [ name ] : { value, deprecationReason, description } } ) : { } ) ;
1717
1818describe ( 'buildEnumValueConfigMap()' , ( ) => {
19- it ( 'should work with minimal AST' , ( ) => {
20- expect ( buildEnumValueConfigMap ( generateEnumAST ( ) ) ) . toEqual ( generateEnumValueConfigMap ( ) ) ;
19+ it ( 'builds with minimal AST' , ( ) => {
20+ expect ( buildEnumValueConfigMap ( generateEnumNode ( ) ) ) . toEqual ( generateEnumValueConfigMap ( ) ) ;
2121 } ) ;
2222
23- it ( 'should work with description in AST' , ( ) => {
23+ it ( 'builds with description in AST' , ( ) => {
2424 const description = 'Another description.' ;
25- expect ( buildEnumValueConfigMap ( generateEnumAST ( {
25+ expect ( buildEnumValueConfigMap ( generateEnumNode ( {
2626 values : [ `# ${ description } \nVALUE` ] ,
2727 } ) ) ) . toEqual ( generateEnumValueConfigMap ( { description } ) ) ;
2828 } ) ;
2929
30- it ( 'should work with `value` in config map' , ( ) => {
31- const value = 'value' ;
32- expect ( buildEnumValueConfigMap ( generateEnumAST ( ) , { VALUE : { value } } ) )
33- . toEqual ( generateEnumValueConfigMap ( { value } ) ) ;
30+ it ( 'builds with deprecation directive in AST' , ( ) => {
31+ const deprecationReason = 'A reason.' ;
32+ expect ( buildEnumValueConfigMap ( generateEnumNode ( {
33+ values : [ `VALUE @deprecated(reason: "${ deprecationReason } ")` ] ,
34+ } ) ) ) . toEqual ( generateEnumValueConfigMap ( { deprecationReason } ) ) ;
3435 } ) ;
3536
36- it ( 'should work with `deprecationReason ` in config map' , ( ) => {
37- const deprecationReason = 'A reason. ' ;
38- expect ( buildEnumValueConfigMap ( generateEnumAST ( ) , { VALUE : { deprecationReason } } ) )
39- . toEqual ( generateEnumValueConfigMap ( { deprecationReason } ) ) ;
37+ it ( 'builds with `value ` in config map' , ( ) => {
38+ const value = 'value ' ;
39+ expect ( buildEnumValueConfigMap ( generateEnumNode ( ) , { VALUE : { value } } ) )
40+ . toEqual ( generateEnumValueConfigMap ( { value } ) ) ;
4041 } ) ;
4142} ) ;
4243
@@ -47,17 +48,17 @@ describe('buildEnum()', () => {
4748 description,
4849 } = { } ) => new GraphQLEnumType ( { name, values, description } ) ;
4950
50- it ( 'should work with minimal AST' , ( ) => {
51- expect ( buildEnum ( generateEnumAST ( ) ) ) . toEqual ( generateEnumType ( ) ) ;
51+ it ( 'builds with minimal AST' , ( ) => {
52+ expect ( buildEnum ( generateEnumNode ( ) ) ) . toEqual ( generateEnumType ( ) ) ;
5253 } ) ;
5354
54- it ( 'should work with description in AST' , ( ) => {
55+ it ( 'builds with description in AST' , ( ) => {
5556 const config = { description : 'A description.' } ;
56- expect ( buildEnum ( generateEnumAST ( config ) ) ) . toEqual ( generateEnumType ( config ) ) ;
57+ expect ( buildEnum ( generateEnumNode ( config ) ) ) . toEqual ( generateEnumType ( config ) ) ;
5758 } ) ;
5859
59- it ( 'should work with `values` in config' , ( ) => {
60+ it ( 'builds with `values` in config' , ( ) => {
6061 const config = { values : { VALUE : { value : 'value' } } } ;
61- expect ( buildEnum ( generateEnumAST ( ) , config ) ) . toEqual ( generateEnumType ( config ) ) ;
62+ expect ( buildEnum ( generateEnumNode ( ) , config ) ) . toEqual ( generateEnumType ( config ) ) ;
6263 } ) ;
6364} ) ;
0 commit comments