-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathtest_view_module.rb
60 lines (48 loc) · 1.82 KB
/
test_view_module.rb
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
# frozen_string_literal: true
require "graphql"
require "graphql/client"
require "graphql/client/view_module"
require "minitest/autorun"
class TestViewModule < Minitest::Test
Root = File.expand_path("..", __FILE__)
class UserType < GraphQL::Schema::Object
field :login, String, null: false
end
class QueryType < GraphQL::Schema::Object
field :viewer, UserType, null: false
end
class Schema < GraphQL::Schema
query(QueryType)
def self.resolve_type(_t, _obj, _ctx)
raise NotImplementedError
end
end
Client = GraphQL::Client.new(schema: Schema)
module Views
extend GraphQL::Client::ViewModule
self.path = "#{Root}/views"
self.client = Client
end
def test_valid_constant_name
assert GraphQL::Client::ViewModule.valid_constant_name?("Foo")
refute GraphQL::Client::ViewModule.valid_constant_name?("404")
end
def test_const_missing
assert_kind_of Module, Views::Users
assert_equal "#{Root}/views/users", Views::Users.path
assert_kind_of Module, Views::Users::Show
assert_equal "#{Root}/views/users/show", Views::Users::Show.path
assert_kind_of GraphQL::Client::FragmentDefinition, Views::Users::Show::User
assert_equal(<<-'GRAPHQL'.gsub(" ", "").chomp, Views::Users::Show::User.document.to_query_string)
fragment TestViewModule__Views__Users__Show__User on User {
login
}
GRAPHQL
assert_kind_of Module, Views::Users::Profile
assert_equal "#{Root}/views/users/profile", Views::Users::Profile.path
assert_kind_of GraphQL::Client::FragmentDefinition, Views::Users::Profile::User
assert_kind_of Module, Views::Users::Profile::Show::User
assert_equal "#{Root}/views/users/profile/show", Views::Users::Profile::Show.path
assert_kind_of GraphQL::Client::FragmentDefinition, Views::Users::Profile::Show::User
end
end