From c9e2cb2accb9a1a484b0d709fe5eb5d537486e21 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 23 Dec 2020 16:44:27 -0700 Subject: test: start to test schema --- bin/test | 6 +++++- lib/types/cake.rb | 2 ++ lib/types/query.rb | 5 +++++ test/integration/server_test.rb | 2 +- test/unit/schema_test.rb | 9 +++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/unit/schema_test.rb diff --git a/bin/test b/bin/test index 7ebbbb9..ce0a08c 100755 --- a/bin/test +++ b/bin/test @@ -5,4 +5,8 @@ set -e cd "$(dirname "$0")/.." ./bin/setup -bundle exec ruby -Ilib:test -r test_helper test/**/*.rb +if [ $# -eq 0 ]; then + bundle exec ruby -Ilib:test -r test_helper test/**/*.rb +else + bundle exec ruby -Ilib:test -r test_helper "$@" +fi diff --git a/lib/types/cake.rb b/lib/types/cake.rb index 94f3240..d610a0a 100644 --- a/lib/types/cake.rb +++ b/lib/types/cake.rb @@ -1,5 +1,7 @@ module Types class Cake < GraphQL::Schema::Object field :name, String, null: false + #field :created_at, DateTime, null: false + #field :updated_at, DateTime, null: false end end diff --git a/lib/types/query.rb b/lib/types/query.rb index 253f5d7..cda6b50 100644 --- a/lib/types/query.rb +++ b/lib/types/query.rb @@ -1,5 +1,10 @@ module Types + class User < GraphQL::Schema::Object + field :username, String, null: false + end + class Query < GraphQL::Schema::Object + #field :me, User, null: false field :me, String, null: false field :cakes, [Cake], null: false diff --git a/test/integration/server_test.rb b/test/integration/server_test.rb index 9e67241..754edff 100644 --- a/test/integration/server_test.rb +++ b/test/integration/server_test.rb @@ -14,7 +14,7 @@ class ServerTest < Minitest::Test refute_empty last_response.body json = JSON.parse(last_response.body) - assert_equal 'mo', json['data']['me'] + assert_equal 'mo', json['data']['me']['name'] end def test_get_graphql_with_post_body diff --git a/test/unit/schema_test.rb b/test/unit/schema_test.rb new file mode 100644 index 0000000..ed6954e --- /dev/null +++ b/test/unit/schema_test.rb @@ -0,0 +1,9 @@ + +class SchemaTest < Minitest::Test + def test_me + result = Schema.execute("{me}") + + assert result + puts result.inspect + end +end -- cgit v1.2.3