1
1
package graphql.scalars.id
2
2
3
3
import graphql.language.StringValue
4
+ import graphql.scalars.ExtendedScalars
4
5
import graphql.schema.CoercingParseLiteralException
5
6
import graphql.schema.CoercingParseValueException
6
7
import graphql.schema.CoercingSerializeException
7
8
import spock.lang.Specification
8
9
import spock.lang.Unroll
9
10
10
- import static graphql.scalars.util.TestKit.*
11
+ import static graphql.scalars.util.TestKit.mkStringValue
12
+ import static graphql.scalars.util.TestKit.mkUUIDValue
11
13
12
14
class UUIDScalarTest extends Specification {
13
15
14
- def coercing = new UUIDScalar () . getCoercing()
16
+ def coercing = ExtendedScalars . UUID . getCoercing()
15
17
16
18
@Unroll
17
19
def " UUID parseValue" () {
@@ -21,9 +23,9 @@ class UUIDScalarTest extends Specification {
21
23
then :
22
24
result == expectedValue
23
25
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" )
27
29
}
28
30
29
31
@Unroll
@@ -34,10 +36,10 @@ class UUIDScalarTest extends Specification {
34
36
then :
35
37
thrown(expectedValue)
36
38
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
41
43
}
42
44
43
45
def " UUID AST literal" () {
@@ -58,8 +60,8 @@ class UUIDScalarTest extends Specification {
58
60
then :
59
61
thrown(expectedValue)
60
62
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
63
65
}
64
66
65
67
def " UUID serialization" () {
@@ -69,10 +71,10 @@ class UUIDScalarTest extends Specification {
69
71
then :
70
72
result == expectedValue
71
73
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"
76
78
}
77
79
78
80
def " UUID serialization bad inputs" () {
@@ -82,9 +84,22 @@ class UUIDScalarTest extends Specification {
82
84
then :
83
85
thrown(expectedValue)
84
86
where :
85
- input | expectedValue
86
- " 1985-04-12" | CoercingSerializeException
87
- 100 | CoercingSerializeException
87
+ input | expectedValue
88
+ " 1985-04-12" | CoercingSerializeException
89
+ 100 | CoercingSerializeException
88
90
}
89
91
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
+ }
90
105
}
0 commit comments