Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Unknown enum values/names should result in nulls and not exceptions
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package graphql.schema | ||
|
||
import spock.lang.Specification | ||
|
||
import static graphql.schema.GraphQLEnumType.newEnum | ||
|
||
|
||
class GraphQLEnumTypeTest extends Specification { | ||
|
||
GraphQLEnumType enumType | ||
|
||
def setup() { | ||
enumType = newEnum().name("TestEnum") | ||
.value("NAME", 42) | ||
.build(); | ||
} | ||
|
||
def "parse value returns null for unknown value"() { | ||
expect: | ||
enumType.getCoercing().parseValue("UNKNOWN") == null | ||
} | ||
|
||
|
||
def "parse value return value for the name"() { | ||
expect: | ||
enumType.getCoercing().parseValue("NAME") == 42 | ||
} | ||
|
||
def "serialize returns name for value"() { | ||
expect: | ||
enumType.getCoercing().serialize(42) == "NAME" | ||
} | ||
|
||
def "serialize returns null for unknown value"() { | ||
expect: | ||
enumType.getCoercing().serialize(12) == null | ||
} | ||
|
||
|
||
} |