11package graphql.scalars.id
22
33import graphql.language.StringValue
4+ import graphql.scalars.ExtendedScalars
45import graphql.schema.CoercingParseLiteralException
56import graphql.schema.CoercingParseValueException
67import graphql.schema.CoercingSerializeException
78import spock.lang.Specification
89import spock.lang.Unroll
910
10- import static graphql.scalars.util.TestKit.*
11+ import static graphql.scalars.util.TestKit.mkStringValue
12+ import static graphql.scalars.util.TestKit.mkUUIDValue
1113
1214class UUIDScalarTest extends Specification {
1315
14- def coercing = new UUIDScalar () . getCoercing()
16+ def coercing = ExtendedScalars . UUID . getCoercing()
1517
1618 @Unroll
1719 def " UUID parseValue" () {
@@ -21,9 +23,9 @@ class UUIDScalarTest extends Specification {
2123 then :
2224 result == expectedValue
2325 where :
24- input | expectedValue
25- " 43f20307-603c-4ad1-83c6-6010d224fabf" | mkUUIDValue(" 43f20307-603c-4ad1-83c6-6010d224fabf" )
26- " 787dbc2b-3ddb-4098-ad1d-63d026bac111" | mkUUIDValue(" 787dbc2b-3ddb-4098-ad1d-63d026bac111" )
26+ input | expectedValue
27+ " 43f20307-603c-4ad1-83c6-6010d224fabf" | mkUUIDValue(" 43f20307-603c-4ad1-83c6-6010d224fabf" )
28+ " 787dbc2b-3ddb-4098-ad1d-63d026bac111" | mkUUIDValue(" 787dbc2b-3ddb-4098-ad1d-63d026bac111" )
2729 }
2830
2931 @Unroll
@@ -34,10 +36,10 @@ class UUIDScalarTest extends Specification {
3436 then :
3537 thrown(expectedValue)
3638 where :
37- input | expectedValue
38- " a-string-that-is-not-uuid" | CoercingParseValueException
39- 100 | CoercingParseValueException
40- " 1985-04-12" | CoercingParseValueException
39+ input | expectedValue
40+ " a-string-that-is-not-uuid" | CoercingParseValueException
41+ 100 | CoercingParseValueException
42+ " 1985-04-12" | CoercingParseValueException
4143 }
4244
4345 def " UUID AST literal" () {
@@ -58,8 +60,8 @@ class UUIDScalarTest extends Specification {
5860 then :
5961 thrown(expectedValue)
6062 where :
61- input | expectedValue
62- new StringValue (" a-string-that-us-not-uuid" ) | CoercingParseLiteralException
63+ input | expectedValue
64+ new StringValue (" a-string-that-us-not-uuid" ) | CoercingParseLiteralException
6365 }
6466
6567 def " UUID serialization" () {
@@ -69,10 +71,10 @@ class UUIDScalarTest extends Specification {
6971 then :
7072 result == expectedValue
7173 where :
72- input | expectedValue
73- " 42287d47-c5bd-45e4-b470-53e426d3d503" | " 42287d47-c5bd-45e4-b470-53e426d3d503"
74- " 423df0f3-cf05-4eb5-b708-ae2f4b4a052d" | " 423df0f3-cf05-4eb5-b708-ae2f4b4a052d"
75- mkUUIDValue(" 6a90b1e6-20f3-43e5-a7ba-34db8010c071" ) | " 6a90b1e6-20f3-43e5-a7ba-34db8010c071"
74+ input | expectedValue
75+ " 42287d47-c5bd-45e4-b470-53e426d3d503" | " 42287d47-c5bd-45e4-b470-53e426d3d503"
76+ " 423df0f3-cf05-4eb5-b708-ae2f4b4a052d" | " 423df0f3-cf05-4eb5-b708-ae2f4b4a052d"
77+ mkUUIDValue(" 6a90b1e6-20f3-43e5-a7ba-34db8010c071" ) | " 6a90b1e6-20f3-43e5-a7ba-34db8010c071"
7678 }
7779
7880 def " UUID serialization bad inputs" () {
@@ -82,9 +84,22 @@ class UUIDScalarTest extends Specification {
8284 then :
8385 thrown(expectedValue)
8486 where :
85- input | expectedValue
86- " 1985-04-12" | CoercingSerializeException
87- 100 | CoercingSerializeException
87+ input | expectedValue
88+ " 1985-04-12" | CoercingSerializeException
89+ 100 | CoercingSerializeException
8890 }
8991
92+ @Unroll
93+ def " UUID valueToLiteral" () {
94+
95+ when :
96+ def result = coercing. valueToLiteral(input)
97+ then :
98+ result. isEqualTo(expectedValue)
99+ where :
100+ input | expectedValue
101+ " 42287d47-c5bd-45e4-b470-53e426d3d503" | mkStringValue(" 42287d47-c5bd-45e4-b470-53e426d3d503" )
102+ " 423df0f3-cf05-4eb5-b708-ae2f4b4a052d" | mkStringValue(" 423df0f3-cf05-4eb5-b708-ae2f4b4a052d" )
103+ mkUUIDValue(" 6a90b1e6-20f3-43e5-a7ba-34db8010c071" ) | mkStringValue(" 6a90b1e6-20f3-43e5-a7ba-34db8010c071" )
104+ }
90105}
0 commit comments