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
|
class ServerTest < Minitest::Test
include Rack::Test::Methods
def app
Server.new
end
def test_get_graphql_with_query_string
header 'Content-Type', 'application/graphql'
get '/', query: '{me}'
assert last_response.ok?
assert_equal 200, last_response.status
refute_empty last_response.body
json = JSON.parse(last_response.body)
assert_equal 'mo', json['data']['me']
end
def test_get_graphql_with_post_body
header 'Content-Type', 'application/graphql'
post '/', '{me}'
assert last_response.ok?
assert_equal 200, last_response.status
refute_empty last_response.body
json = JSON.parse(last_response.body)
assert_equal 'mo', json['data']['me']
end
def test_get_schema
header 'Content-Type', 'application/graphql'
post '/', '{ __schema { types { name } } }'
assert last_response.ok?
json = JSON.parse(last_response.body)
[
'Boolean',
'Cake',
'Query',
'String',
'__Directive',
'__DirectiveLocation',
'__EnumValue',
'__InputValue',
'__Type',
'__TypeKind',
].each do |type|
assert json['data']['__schema']['types'].include?('name' => type)
end
end
def test_get_query_type
header 'Content-Type', 'application/graphql'
post '/', '{ __schema { queryType { name } } }'
assert last_response.ok?
json = JSON.parse(last_response.body)
assert 'Query', json['data']['__schema']['queryType']['name']
end
end
|