-
Notifications
You must be signed in to change notification settings - Fork 59
/
DateTimeScalarTest.groovy
123 lines (104 loc) · 4.41 KB
/
DateTimeScalarTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package graphql.scalars.datetime
import graphql.language.StringValue
import graphql.scalars.ExtendedScalars
import graphql.schema.CoercingParseLiteralException
import graphql.schema.CoercingParseValueException
import graphql.schema.CoercingSerializeException
import spock.lang.Specification
import spock.lang.Unroll
import static graphql.scalars.util.TestKit.mkLocalDT
import static graphql.scalars.util.TestKit.mkOffsetDT
import static graphql.scalars.util.TestKit.mkStringValue
import static graphql.scalars.util.TestKit.mkZonedDT
class DateTimeScalarTest extends Specification {
def coercing = ExtendedScalars.DateTime.getCoercing()
@Unroll
def "datetime parseValue"() {
when:
def result = coercing.parseValue(input)
then:
result == expectedValue
where:
input | expectedValue
"1985-04-12T23:20:50.52Z" | mkOffsetDT("1985-04-12T23:20:50.52Z")
"1996-12-19T16:39:57-08:00" | mkOffsetDT("1996-12-19T16:39:57-08:00")
"1937-01-01T12:00:27.87+00:20" | mkOffsetDT("1937-01-01T12:00:27.87+00:20")
"2022-11-24T01:00:01.02+00:00" | mkOffsetDT("2022-11-24T01:00:01.02+00:00")
mkOffsetDT(year: 1980, hour: 3) | mkOffsetDT("1980-08-08T03:10:09+10:00")
mkZonedDT(year: 1980, hour: 3) | mkOffsetDT("1980-08-08T03:10:09+10:00")
}
@Unroll
def "datetime valueToLiteral"() {
when:
def result = coercing.valueToLiteral(input)
then:
result.isEqualTo(expectedValue)
where:
input | expectedValue
"1985-04-12T23:20:50.52Z" | mkStringValue("1985-04-12T23:20:50.520Z")
"1996-12-19T16:39:57-08:00" | mkStringValue("1996-12-19T16:39:57.000-08:00")
"1937-01-01T12:00:27.87+00:20" | mkStringValue("1937-01-01T12:00:27.870+00:20")
"1937-01-01T12:00+00:20" | mkStringValue("1937-01-01T12:00:00.000+00:20")
"2022-11-24T01:00:01.02+00:00" | mkStringValue("2022-11-24T01:00:01.020Z")
mkOffsetDT(year: 1980, hour: 3) | mkStringValue("1980-08-08T03:10:09.000+10:00")
mkZonedDT(year: 1980, hour: 3) | mkStringValue("1980-08-08T03:10:09.000+10:00")
}
@Unroll
def "datetime parseValue bad inputs"() {
when:
coercing.parseValue(input)
then:
thrown(expectedValue)
where:
input | expectedValue
"1985-04-12" | CoercingParseValueException
"2022-11-24T01:00:01.02-00:00" | CoercingParseValueException
mkLocalDT(year: 1980, hour: 3) | CoercingParseValueException
666 || CoercingParseValueException
}
def "datetime AST literal"() {
when:
def result = coercing.parseLiteral(input)
then:
result == expectedValue
where:
input | expectedValue
new StringValue("1985-04-12T23:20:50.52Z") | mkOffsetDT("1985-04-12T23:20:50.52Z")
}
def "datetime serialisation"() {
when:
def result = coercing.serialize(input)
then:
result == expectedValue
where:
input | expectedValue
"1985-04-12T23:20:50.52Z" | "1985-04-12T23:20:50.520Z"
"1996-12-19T16:39:57-08:00" | "1996-12-19T16:39:57.000-08:00"
"1937-01-01T12:00:27.87+00:20" | "1937-01-01T12:00:27.870+00:20"
"2022-11-24T01:00:01.02+00:00" | "2022-11-24T01:00:01.020Z"
mkOffsetDT(year: 1980, hour: 3) | "1980-08-08T03:10:09.000+10:00"
mkZonedDT(year: 1980, hour: 3) | "1980-08-08T03:10:09.000+10:00"
}
def "datetime serialisation bad inputs"() {
when:
coercing.serialize(input)
then:
thrown(expectedValue)
where:
input | expectedValue
"1985-04-12" | CoercingSerializeException
"2022-11-24T01:00:01.02-00:00" | CoercingSerializeException
mkLocalDT(year: 1980, hour: 3) | CoercingSerializeException
666 || CoercingSerializeException
}
@Unroll
def "datetime parseLiteral bad inputs"() {
when:
coercing.parseLiteral(input)
then:
thrown(expectedValue)
where:
input | expectedValue
"2022-11-24T01:00:01.02-00:00" | CoercingParseLiteralException
}
}