Skip to content

Commit 925e3c7

Browse files
authored
Merge pull request #14 from meganemura/add-date-specs
Add and improve the tests for Date/DateTime types
2 parents 177c088 + a7d270b commit 925e3c7

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

test/test_query_result.rb

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
require_relative "foo_helper"
88

99
class TestQueryResult < Minitest::Test
10-
class DateTimeType < GraphQL::Schema::Scalar
11-
def self.coerce_input(value, ctx)
12-
Time.iso8601(value)
13-
end
14-
15-
def self.coerce_result(value, ctx)
16-
value.utc.iso8601
17-
end
18-
end
19-
2010
module NodeType
2111
include GraphQL::Schema::Interface
2212
field :id, ID, null: false
@@ -58,7 +48,7 @@ class UserType < GraphQL::Schema::Object
5848

5949
module HumanLike
6050
include GraphQL::Schema::Interface
61-
field :updated_at, DateTimeType, null: false
51+
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
6252
end
6353

6454
class PersonType < GraphQL::Schema::Object
@@ -69,7 +59,8 @@ class PersonType < GraphQL::Schema::Object
6959
field :last_name, String, null: true
7060
field :company, String, null: true
7161
field :homepageURL, String, null: true, method: :homepage_url, camelize: false
72-
field :created_at, DateTimeType, null: false
62+
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
63+
field :created_on, GraphQL::Types::ISO8601Date, null: false
7364
field :hobbies, [String], null: true
7465
field :plan, PlanType, null: false
7566
end
@@ -113,6 +104,7 @@ def me
113104
last_name: "Peek",
114105
company: "GitHub",
115106
created_at: Time.at(0),
107+
created_on: Date.new(1970, 1, 1),
116108
updated_at: Time.at(1),
117109
hobbies: ["soccer", "coding"],
118110
homepage_url: nil,
@@ -133,6 +125,7 @@ def issue_or_pull_request
133125
last_name: "Peek",
134126
company: "GitHub",
135127
created_at: Time.at(0),
128+
created_on: Date.new(1970, 1, 1),
136129
updated_at: Time.at(1),
137130
hobbies: ["soccer", "coding"],
138131
plan: "LARGE"
@@ -596,7 +589,7 @@ def test_interface_within_union_values
596589
assert_equal Time.at(1).utc, actor.updated_at
597590
end
598591

599-
def test_date_scalar_casting
592+
def test_datetime_scalar_casting
600593
Temp.const_set :Query, @client.parse(<<-'GRAPHQL')
601594
{
602595
me {
@@ -615,6 +608,23 @@ def test_date_scalar_casting
615608
assert_equal Time.at(1), person.updated_at
616609
end
617610

611+
def test_date_scalar_casting
612+
Temp.const_set :Query, @client.parse(<<-'GRAPHQL')
613+
{
614+
me {
615+
name
616+
createdOn
617+
}
618+
}
619+
GRAPHQL
620+
621+
response = @client.query(Temp::Query)
622+
623+
person = response.data.me
624+
assert_equal "Josh", person.name
625+
assert_equal Date.new(1970, 1, 1), person.created_on
626+
end
627+
618628
include FooHelper
619629

620630
def test_source_location

0 commit comments

Comments
 (0)