Skip to content

Commit e30da9c

Browse files
committed
✅ Fix graphql schema render tests
1 parent 02af2b8 commit e30da9c

File tree

2 files changed

+95
-53
lines changed

2 files changed

+95
-53
lines changed

scripts/graphql_api_content/render_helpers.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ def render_of_type(type, is_list = false, is_non_nullable = false, size = "mediu
2424
formatted_type = "[#{formatted_type}]" if is_list
2525

2626
<<~HTML
27-
<a \
28-
href="/docs/apis/graphql/schemas/#{kind.downcase}/#{name.downcase}"
29-
class="pill pill--#{kind.downcase} pill--normal-case pill--#{size}"
30-
title="Go to #{kind} #{name}"
31-
>
27+
<a href="/docs/apis/graphql/schemas/#{kind.downcase}/#{name.downcase}" class="pill pill--#{kind.downcase} pill--normal-case pill--#{size}" title="Go to #{kind} #{name}">
3228
<code>#{formatted_type}</code>
3329
</a>
3430
HTML
@@ -110,7 +106,7 @@ def render_possible_types(possible_types)
110106
if possible_types.is_a?(Array) && !possible_types.empty?
111107
<<~HTML
112108
<h2 data-algolia-exclude>Possible types</h2>
113-
<div>#{possible_types.map { |possible_type| render_of_type(possible_type, false, "large") }.join('')}</div>
109+
<div>#{possible_types.map { |possible_type| render_of_type(possible_type, false, false, "large") }.join('')}</div>
114110
HTML
115111
end
116112
end
@@ -133,7 +129,7 @@ def render_input_fields(input_fields)
133129
<td>
134130
<p>
135131
<strong><code>#{input_field["name"]}</code></strong>
136-
<div>#{render_of_type(input_field["type"])}</div>
132+
#{render_of_type(input_field["type"])}
137133
</p>
138134
#{input_field["description"] ? "#{render_html(input_field["description"].gsub("\n", " "))}" : nil}
139135
#{input_field["defaultValue"] ? "<p>Default value: #{input_field["defaultValue"]}</p>" : nil}
@@ -156,7 +152,7 @@ def render_interfaces(interfaces)
156152
#{
157153
interfaces.map {
158154
|interface|
159-
render_of_type(interface, false, "large")
155+
render_of_type(interface, false, false, "large")
160156
}.join('')
161157
}
162158
</div>
@@ -205,7 +201,7 @@ def render_pill(schema_type_data, size = "medium")
205201
</span>
206202
HTML
207203
elsif type = schema_type_data["type"]
208-
render_of_type(type, false, "large")
204+
render_of_type(type, false, false, "large")
209205
else
210206
""
211207
end

spec/scripts/graphql_api_content/render_helpers_spec.rb

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,97 @@
66
it "converts markdown to html" do
77
markdown = "This _is a **sentence**_."
88
html = render_html(markdown)
9+
910
expect(html).to eq(
1011
"<p>This <em>is a <strong>sentence</strong></em>.</p>\n"
1112
)
1213
end
1314
end
1415

1516
describe "#render_of_type" do
16-
context "when of_type is not nested" do
17-
it "renders a link" do
17+
it "renders correctly" do
18+
of_type = {
19+
"kind" => "OBJECT",
20+
"name" => "Agent",
21+
"ofType" => nil
22+
}
23+
24+
expect(render_of_type(of_type)).to eq(
25+
<<~HTML
26+
<a href="/docs/apis/graphql/schemas/object/agent" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT Agent">
27+
<code>Agent</code>
28+
</a>
29+
HTML
30+
)
31+
end
32+
33+
context "when type is non-nullable" do
34+
it "renders correctly" do
1835
of_type = {
19-
"kind" => "OBJECT",
20-
"name" => "Agent",
21-
"ofType" => nil
36+
"kind" => "NON_NULL",
37+
"name" => nil,
38+
"ofType" => {
39+
"kind" => "SCALAR",
40+
"name" => "ID",
41+
"ofType" => nil
42+
}
2243
}
44+
2345
expect(render_of_type(of_type)).to eq(
2446
<<~HTML
25-
<a href="/docs/apis/graphql/schemas/object/agent" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT Agent"><code>Agent!</code></a>
47+
<a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID">
48+
<code>ID!</code>
49+
</a>
2650
HTML
2751
)
2852
end
2953
end
3054

31-
context "when of_type is a nested hash" do
32-
it "renders a link from the deepest hash" do
55+
context "when type is a list" do
56+
it "renders correctly" do
3357
of_type = {
34-
"kind" => "NON_NULL",
58+
"kind" => "LIST",
3559
"name" => nil,
3660
"ofType" => {
3761
"kind" => "SCALAR",
3862
"name" => "ID",
3963
"ofType" => nil
4064
}
4165
}
66+
4267
expect(render_of_type(of_type)).to eq(
4368
<<~HTML
44-
<a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID</code></a>
69+
<a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID">
70+
<code>[ID]</code>
71+
</a>
4572
HTML
4673
)
4774
end
48-
end
4975

50-
context "when of_type['name'] is not available" do
51-
it "renders the of_type['kind'] instead" do
52-
of_type = {
53-
"kind" => "NON_NULL",
54-
"name" => nil,
55-
"ofType" => nil
56-
}
57-
expect(render_of_type(of_type)).to eq("NON_NULL")
76+
context "and non-nullable" do
77+
it "renders correctly" do
78+
of_type = {
79+
"kind" => "LIST",
80+
"name" => nil,
81+
"ofType" => {
82+
"kind" => "NON_NULL",
83+
"name" => "nil",
84+
"ofType" => {
85+
"kind" => "SCALAR",
86+
"name" => "ID",
87+
"ofType" => nil
88+
}
89+
}
90+
}
91+
92+
expect(render_of_type(of_type)).to eq(
93+
<<~HTML
94+
<a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID">
95+
<code>[ID!]</code>
96+
</a>
97+
HTML
98+
)
99+
end
58100
end
59101
end
60102
end
@@ -139,7 +181,7 @@
139181
<tbody>
140182
<tr>
141183
<td>
142-
<h3 class="is-small has-pills"><code>agent</code><a href="/docs/apis/graphql/schemas/object/agent" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT Agent"><code>Agent!</code></a></h3>
184+
<h3 class="is-small has-pills"><code>agent</code><a href="/docs/apis/graphql/schemas/object/agent" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT Agent"><code>Agent</code></a></h3>
143185
<p>Find an agent by its slug</p>
144186
<div>
145187
<details>
@@ -148,7 +190,7 @@
148190
<tbody>
149191
<tr>
150192
<td>
151-
<h4 class="is-small has-pills no-margin"><code>slug</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID!</code></a></h4>
193+
<h4 class="is-small has-pills no-margin"><code>slug</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID</code></a></h4>
152194
<p>The UUID for the agent, prefixed by its organization's slug i.e. <code>acme-inc/0bd5ea7c-89b3-4f40-8ca3-ffac805771eb</code></p>
153195
<p class="no-margin">Default value: <code>Default</code></p>
154196
</td>
@@ -161,7 +203,7 @@
161203
</tr>
162204
<tr>
163205
<td>
164-
<h3 class="is-small has-pills"><code>agentToken</code><a href="/docs/apis/graphql/schemas/object/agenttoken" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT AgentToken"><code>AgentToken!</code></a><span class="pill pill--deprecated"><code>deprecated</code></span></h3>
206+
<h3 class="is-small has-pills"><code>agentToken</code><a href="/docs/apis/graphql/schemas/object/agenttoken" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT AgentToken"><code>AgentToken</code></a><span class="pill pill--deprecated"><code>deprecated</code></span></h3>
165207
<p><em>Deprecated: Deprecated because of reasons</em></p>
166208
<div>
167209
<details>
@@ -170,7 +212,7 @@
170212
<tbody>
171213
<tr>
172214
<td>
173-
<h4 class="is-small has-pills no-margin"><code>slug</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID!</code></a></h4>
215+
<h4 class="is-small has-pills no-margin"><code>slug</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID</code></a></h4>
174216
<p>The UUID for the agent token, prefixed by its organization's slug i.e. <code>acme-inc/0bd5ea7c-89b3-4f40-8ca3-ffac805771eb</code></p>
175217
<p class="no-margin">Default value: <code>test default</code></p>
176218
</td>
@@ -241,13 +283,13 @@
241283
<tbody>
242284
<tr>
243285
<td>
244-
<h4 class="is-small has-pills no-margin"><code>slug</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID!</code></a></h4>
286+
<h4 class="is-small has-pills no-margin"><code>slug</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID</code></a></h4>
245287
<p>The slug for the sso provider, prefixed by its organization's slug i.e. <code>acme-inc/0bd5ea7c-89b3-4f40-8ca3-ffac805771eb</code></p>
246288
</td>
247289
</tr>
248290
<tr>
249291
<td>
250-
<h4 class="is-small has-pills no-margin"><code>uuid</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID!</code></a></h4>
292+
<h4 class="is-small has-pills no-margin"><code>uuid</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID</code></a></h4>
251293
<p>The UUID of the sso provider</p>
252294
</td>
253295
</tr>
@@ -299,12 +341,14 @@
299341
expect(possible_types_string).to eq(
300342
<<~HTML.gsub(/^[\s\t]*|[\s\t]*\n/, '')
301343
<h2 data-algolia-exclude>Possible types</h2>
302-
<a href="/docs/apis/graphql/schemas/object/apiaccesstoken" class="pill pill--object pill--normal-case pill--large" title="Go to OBJECT APIAccessToken">
303-
<code>APIAccessToken</code>
304-
</a>
305-
<a href="/docs/apis/graphql/schemas/object/apiaccesstokencode" class="pill pill--object pill--normal-case pill--large" title="Go to OBJECT APIAccessTokenCode">
306-
<code>APIAccessTokenCode</code>
307-
</a>
344+
<div>
345+
<a href="/docs/apis/graphql/schemas/object/apiaccesstoken" class="pill pill--object pill--normal-case pill--large" title="Go to OBJECT APIAccessToken">
346+
<code>APIAccessToken</code>
347+
</a>
348+
<a href="/docs/apis/graphql/schemas/object/apiaccesstokencode" class="pill pill--object pill--normal-case pill--large" title="Go to OBJECT APIAccessTokenCode">
349+
<code>APIAccessTokenCode</code>
350+
</a>
351+
</div>
308352
HTML
309353
)
310354
end
@@ -368,15 +412,15 @@
368412
<td>
369413
<p>
370414
<strong><code>twoFactorEnabled</code></strong>
371-
<a href="/docs/apis/graphql/schemas/scalar/boolean" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR Boolean"><code>Boolean!</code></a>
415+
<a href="/docs/apis/graphql/schemas/scalar/boolean" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR Boolean"><code>Boolean</code></a>
372416
</p>
373417
</td>
374418
</tr>
375419
<tr>
376420
<td>
377421
<p>
378422
<strong><code>passwordProtected</code></strong>
379-
<a href="/docs/apis/graphql/schemas/scalar/boolean" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR Boolean"><code>Boolean!</code></a>
423+
<a href="/docs/apis/graphql/schemas/scalar/boolean" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR Boolean"><code>Boolean</code></a>
380424
</p>
381425
<p>Test description</p>
382426
<p>Default value: Test default</p>
@@ -427,12 +471,14 @@
427471
expect(interfaces_string).to eq(
428472
<<~HTML.gsub(/^[\s\t]*|[\s\t]*\n/, '')
429473
<h2 data-algolia-exclude>Interfaces</h2>
430-
<a href="/docs/apis/graphql/schemas/interface/authorization" class="pill pill--interface pill--normal-case pill--large" title="Go to INTERFACE Authorization">
431-
<code>Authorization</code>
432-
</a>
433-
<a href="/docs/apis/graphql/schemas/interface/node" class="pill pill--interface pill--normal-case pill--large" title="Go to INTERFACE Node">
434-
<code>Node</code>
435-
</a>
474+
<div>
475+
<a href="/docs/apis/graphql/schemas/interface/authorization" class="pill pill--interface pill--normal-case pill--large" title="Go to INTERFACE Authorization">
476+
<code>Authorization</code>
477+
</a>
478+
<a href="/docs/apis/graphql/schemas/interface/node" class="pill pill--interface pill--normal-case pill--large" title="Go to INTERFACE Node">
479+
<code>Node</code>
480+
</a>
481+
</div>
436482
HTML
437483
)
438484
end
@@ -641,27 +687,27 @@
641687
<tbody>
642688
<tr>
643689
<td>
644-
<h3 class="is-small has-pills"><code>build</code><a href="/docs/apis/graphql/schemas/object/build" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT Build"><code>Build!</code></a></h3>
690+
<h3 class="is-small has-pills"><code>build</code><a href="/docs/apis/graphql/schemas/object/build" class="pill pill--object pill--normal-case pill--medium" title="Go to OBJECT Build"><code>Build</code></a></h3>
645691
<p>The build that this job is a part of</p>
646692
</td>
647693
</tr>
648694
<tr>
649695
<td>
650-
<h3 class="is-small has-pills"><code>id</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID</code></a></h3>
696+
<h3 class="is-small has-pills"><code>id</code><a href="/docs/apis/graphql/schemas/scalar/id" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR ID"><code>ID!</code></a></h3>
651697
<div>
652698
<details>
653699
<summary>Arguments</summary>
654700
<table class="responsive-table responsive-table--single-column-rows">
655701
<tbody>
656702
<tr>
657703
<td>
658-
<h4 class="is-small has-pills no-margin"><code>first</code><a href="/docs/apis/graphql/schemas/scalar/int" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR Int"><code>Int!</code></a></h4>
704+
<h4 class="is-small has-pills no-margin"><code>first</code><a href="/docs/apis/graphql/schemas/scalar/int" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR Int"><code>Int</code></a></h4>
659705
<p>Returns the first <em>n</em> elements from the list.</p>
660706
</td>
661707
</tr>
662708
<tr>
663709
<td>
664-
<h4 class="is-small has-pills no-margin"><code>after</code><a href="/docs/apis/graphql/schemas/scalar/string" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR String"><code>String!</code></a></h4>
710+
<h4 class="is-small has-pills no-margin"><code>after</code><a href="/docs/apis/graphql/schemas/scalar/string" class="pill pill--scalar pill--normal-case pill--medium" title="Go to SCALAR String"><code>String</code></a></h4>
665711
<p>Returns the elements in the list that come after the specified cursor.</p>
666712
</td>
667713
</tr>
@@ -674,7 +720,7 @@
674720
</tbody>
675721
</table>
676722
<h2 data-algolia-exclude>Interfaces</h2>
677-
<a href="/docs/apis/graphql/schemas/interface/node" class="pill pill--interface pill--normal-case pill--large" title="Go to INTERFACE Node"><code>Node</code></a>
723+
<div><a href="/docs/apis/graphql/schemas/interface/node" class="pill pill--interface pill--normal-case pill--large" title="Go to INTERFACE Node"><code>Node</code></a></div>
678724
679725
HTML
680726
)

0 commit comments

Comments
 (0)