Skip to content

Commit 85b46f4

Browse files
committed
Fix more specs
1 parent 5a41993 commit 85b46f4

File tree

6 files changed

+213
-201
lines changed

6 files changed

+213
-201
lines changed
Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardLimitersLimitersControllerTest < ActionDispatch::IntegrationTest
5-
def test_it_checks_installed
6-
get graphql_dashboard.limiters_limiter_path("runtime", { schema: "GraphQL::Schema" })
7-
assert_includes response.body, CGI::escapeHTML("Rate limiters aren't installed on this schema yet.")
8-
refute_includes response.headers["Content-Security-Policy"], "nonce-"
9-
end
4+
if defined?(GraphQL::Pro)
5+
class DashboardLimitersLimitersControllerTest < ActionDispatch::IntegrationTest
6+
def test_it_checks_installed
7+
get graphql_dashboard.limiters_limiter_path("runtime", { schema: "GraphQL::Schema" })
8+
assert_includes response.body, CGI::escapeHTML("Rate limiters aren't installed on this schema yet.")
9+
refute_includes response.headers["Content-Security-Policy"], "nonce-"
10+
end
1011

11-
def test_it_shows_limiters
12-
Redis.new(db: DummySchema::DB_NUMBER).flushdb
12+
def test_it_shows_limiters
13+
Redis.new(db: DummySchema::DB_NUMBER).flushdb
1314

14-
3.times do
15-
DummySchema.execute("{ sleep(seconds: 0.02) }", context: { limiter_key: "client-1" }).to_h
16-
end
17-
4.times do
18-
DummySchema.execute("{ sleep(seconds: 0.110) }", context: { limiter_key: "client-2" }).to_h
19-
end
15+
3.times do
16+
DummySchema.execute("{ sleep(seconds: 0.02) }", context: { limiter_key: "client-1" }).to_h
17+
end
18+
4.times do
19+
DummySchema.execute("{ sleep(seconds: 0.110) }", context: { limiter_key: "client-2" }).to_h
20+
end
2021

21-
get graphql_dashboard.limiters_limiter_path("runtime")
22-
assert_includes response.body, "<span class=\"data\">4</span>"
23-
assert_includes response.body, "<span class=\"data\">3</span>"
24-
assert_includes response.body, "Disable Soft Limiting"
25-
assert_includes response.headers["Content-Security-Policy"], "nonce-"
22+
get graphql_dashboard.limiters_limiter_path("runtime")
23+
assert_includes response.body, "<span class=\"data\">4</span>"
24+
assert_includes response.body, "<span class=\"data\">3</span>"
25+
assert_includes response.body, "Disable Soft Limiting"
26+
assert_includes response.headers["Content-Security-Policy"], "nonce-"
2627

27-
patch graphql_dashboard.limiters_limiter_path("runtime")
28-
get graphql_dashboard.limiters_limiter_path("runtime")
29-
assert_includes response.body, "Enable Soft Limiting"
28+
patch graphql_dashboard.limiters_limiter_path("runtime")
29+
get graphql_dashboard.limiters_limiter_path("runtime")
30+
assert_includes response.body, "Enable Soft Limiting"
3031

31-
get graphql_dashboard.limiters_limiter_path("active_operations")
32-
assert_includes response.body, "It looks like this limiter isn't installed yet."
32+
get graphql_dashboard.limiters_limiter_path("active_operations")
33+
assert_includes response.body, "It looks like this limiter isn't installed yet."
3334

35+
end
3436
end
3537
end
Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,65 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardOperationStoreClientsControllerTest < ActionDispatch::IntegrationTest
5-
def test_it_manages_clients
6-
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
7-
get graphql_dashboard.operation_store_clients_path
8-
assert_includes response.body, "0 Clients"
9-
assert_includes response.body, "To get started, create"
10-
11-
get graphql_dashboard.new_operation_store_client_path
12-
assert_includes response.body, "New Client"
13-
14-
post graphql_dashboard.operation_store_clients_path, params: {
15-
client: {
16-
name: "client-1",
17-
secret: "abcdefedcba"
18-
}
19-
}
4+
if defined?(GraphQL::Pro)
5+
class DashboardOperationStoreClientsControllerTest < ActionDispatch::IntegrationTest
6+
def test_it_manages_clients
7+
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
8+
get graphql_dashboard.operation_store_clients_path
9+
assert_includes response.body, "0 Clients"
10+
assert_includes response.body, "To get started, create"
2011

21-
get graphql_dashboard.operation_store_clients_path
22-
assert_includes response.body, "1 Client"
12+
get graphql_dashboard.new_operation_store_client_path
13+
assert_includes response.body, "New Client"
2314

24-
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
25-
assert_includes response.body, "abcdefedcba"
15+
post graphql_dashboard.operation_store_clients_path, params: {
16+
client: {
17+
name: "client-1",
18+
secret: "abcdefedcba"
19+
}
20+
}
2621

27-
patch graphql_dashboard.operation_store_client_path(name: "client-1"), params: { client: { secret: "123456789" } }
28-
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
29-
assert_includes response.body, "123456789"
22+
get graphql_dashboard.operation_store_clients_path
23+
assert_includes response.body, "1 Client"
3024

31-
delete graphql_dashboard.operation_store_client_path(name: "client-1")
32-
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
33-
ensure
34-
DummySchema.operation_store.delete_client("client-1")
35-
end
25+
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
26+
assert_includes response.body, "abcdefedcba"
3627

37-
def test_it_paginates
38-
5.times do |i|
39-
DummySchema.operation_store.upsert_client("client-#{i}", "abcdef")
28+
patch graphql_dashboard.operation_store_client_path(name: "client-1"), params: { client: { secret: "123456789" } }
29+
get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
30+
assert_includes response.body, "123456789"
31+
32+
delete graphql_dashboard.operation_store_client_path(name: "client-1")
33+
assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
34+
ensure
35+
DummySchema.operation_store.delete_client("client-1")
4036
end
41-
get graphql_dashboard.operation_store_clients_path(per_page: 2)
42-
assert_includes response.body, "5 Clients"
43-
assert_includes response.body, "?page=2&amp;per_page=2"
44-
assert_includes response.body, "disabled>« prev</button>"
45-
46-
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 2)
47-
assert_includes response.body, "?page=1&amp;per_page=2"
48-
assert_includes response.body, "?page=3&amp;per_page=2"
49-
50-
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 3)
51-
assert_includes response.body, "disabled>next »</button>"
52-
assert_includes response.body, "?page=2&amp;per_page=2"
53-
ensure
54-
5.times do |i|
55-
DummySchema.operation_store.delete_client("client-#{i}")
37+
38+
def test_it_paginates
39+
5.times do |i|
40+
DummySchema.operation_store.upsert_client("client-#{i}", "abcdef")
41+
end
42+
get graphql_dashboard.operation_store_clients_path(per_page: 2)
43+
assert_includes response.body, "5 Clients"
44+
assert_includes response.body, "?page=2&amp;per_page=2"
45+
assert_includes response.body, "disabled>« prev</button>"
46+
47+
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 2)
48+
assert_includes response.body, "?page=1&amp;per_page=2"
49+
assert_includes response.body, "?page=3&amp;per_page=2"
50+
51+
get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 3)
52+
assert_includes response.body, "disabled>next »</button>"
53+
assert_includes response.body, "?page=2&amp;per_page=2"
54+
ensure
55+
5.times do |i|
56+
DummySchema.operation_store.delete_client("client-#{i}")
57+
end
5658
end
57-
end
5859

59-
def test_it_checks_installed
60-
get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
61-
assert_includes response.body, "isn't installed for this schema yet"
60+
def test_it_checks_installed
61+
get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
62+
assert_includes response.body, "isn't installed for this schema yet"
63+
end
6264
end
6365
end
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardOperationStoreIndexEntriesControllerTest < ActionDispatch::IntegrationTest
5-
def test_it_shows_entries
6-
DummySchema.operation_store.upsert_client("client-1", "abcdef")
7-
DummySchema.operation_store.add(body: "query GetTypename { __type(name: \"Query\") { name @skip(if: true) } }", operation_alias: "GetTypename", client_name: "client-1")
4+
if defined?(GraphQL::Pro)
5+
class DashboardOperationStoreIndexEntriesControllerTest < ActionDispatch::IntegrationTest
6+
def test_it_shows_entries
7+
DummySchema.operation_store.upsert_client("client-1", "abcdef")
8+
DummySchema.operation_store.add(body: "query GetTypename { __type(name: \"Query\") { name @skip(if: true) } }", operation_alias: "GetTypename", client_name: "client-1")
89

9-
get graphql_dashboard.operation_store_index_entries_path
10-
assert_includes response.body, "Query.__type.name"
11-
assert_includes response.body, "7 entries"
10+
get graphql_dashboard.operation_store_index_entries_path
11+
assert_includes response.body, "Query.__type.name"
12+
assert_includes response.body, "7 entries"
1213

13-
get graphql_dashboard.operation_store_index_entries_path(q: "Query")
14-
assert_includes response.body, "3 results"
15-
assert_includes response.body, ">Query</a>"
16-
assert_includes response.body, ">Query.__type</a>"
17-
assert_includes response.body, ">Query.__type.name</a>"
14+
get graphql_dashboard.operation_store_index_entries_path(q: "Query")
15+
assert_includes response.body, "3 results"
16+
assert_includes response.body, ">Query</a>"
17+
assert_includes response.body, ">Query.__type</a>"
18+
assert_includes response.body, ">Query.__type.name</a>"
1819

19-
get graphql_dashboard.operation_store_index_entries_path(q: "Query", per_page: 1, page: 2)
20-
assert_includes response.body, "3 results"
21-
refute_includes response.body, ">Query</a>"
22-
assert_includes response.body, ">Query.__type</a>"
23-
refute_includes response.body, ">Query.__type.name</a>"
20+
get graphql_dashboard.operation_store_index_entries_path(q: "Query", per_page: 1, page: 2)
21+
assert_includes response.body, "3 results"
22+
refute_includes response.body, ">Query</a>"
23+
assert_includes response.body, ">Query.__type</a>"
24+
refute_includes response.body, ">Query.__type.name</a>"
2425

25-
get graphql_dashboard.operation_store_index_entry_path(name: "Query.__type.name")
26-
assert_includes response.body, "GetTypename"
27-
ensure
28-
DummySchema.operation_store.delete_client("client-1")
26+
get graphql_dashboard.operation_store_index_entry_path(name: "Query.__type.name")
27+
assert_includes response.body, "GetTypename"
28+
ensure
29+
DummySchema.operation_store.delete_client("client-1")
30+
end
2931
end
3032
end
Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,76 @@
11
# frozen_string_literal: true
22
require "test_helper"
33

4-
class DashboardOperationStoreOperationsControllerTest < ActionDispatch::IntegrationTest
5-
def teardown
6-
DummySchema.operation_store.delete_client("client-1")
7-
DummySchema.operation_store.delete_client("client-2")
8-
super
9-
end
10-
def test_it_lists_shows_and_archives_operations
11-
get graphql_dashboard.operation_store_operations_path
12-
assert_includes response.body, "Add your first stored operations with"
13-
14-
get graphql_dashboard.operation_store_operations_path(client_name: "client-5000")
15-
assert_includes response.body, "Add your first stored operations with"
16-
17-
get graphql_dashboard.archived_operation_store_operations_path
18-
assert_includes response.body, "Archived operations</a> will appear here."
19-
20-
get graphql_dashboard.archived_operation_store_client_operations_path(client_name: "client-5000")
21-
assert_includes response.body, "Archived operations</a> will appear here."
22-
23-
os = DummySchema.operation_store
24-
os.upsert_client("client-1", "abcdef")
25-
os.add(body: "query GetTypename { __typename }", operation_alias: "GetTypename", client_name: "client-1")
26-
os.add(body: "query GetAliasedTypename { t: __typename }", operation_alias: "get-aliased-typename", client_name: "client-1")
27-
28-
os.upsert_client("client-2", "abcdef")
29-
os.add(body: "query GetTypename { __typename }", operation_alias: "GetTypename2", client_name: "client-2")
30-
31-
get graphql_dashboard.operation_store_operations_path
32-
assert_includes response.body, "2 Active"
33-
assert_includes response.body, "GetTypename"
34-
assert_includes response.body, "GetAliasedTypename"
35-
36-
get graphql_dashboard.operation_store_operations_path(sort_by: "name", order_dir: "asc", per_page: 1)
37-
refute_includes response.body, "GetTypename"
38-
assert_includes response.body, "GetAliasedTypename"
39-
40-
get graphql_dashboard.operation_store_operations_path(sort_by: "name", order_dir: "desc", per_page: 1)
41-
assert_includes response.body, "GetTypename"
42-
refute_includes response.body, "GetAliasedTypename"
43-
44-
get graphql_dashboard.operation_store_operations_path(client_name: "client-2")
45-
assert_includes response.body, "1 Active"
46-
assert_includes response.body, "GetTypename"
47-
refute_includes response.body, "GetAliasedTypename"
48-
49-
get graphql_dashboard.operation_store_operation_path(digest: "4cd12cc333c91f78e8f781933ecc783d")
50-
assert_includes response.body, "GetAliasedTypename"
51-
assert_includes response.body, "client-1"
52-
assert_includes response.body, "Query.__typename"
53-
54-
post graphql_dashboard.archive_operation_store_client_operations_path(client_name: "client-1", operation_aliases: ["get-aliased-typename"])
55-
post graphql_dashboard.archive_operation_store_operations_path(digests: ["b161214b11847649e7f36cc50e1257a1"])
56-
57-
get graphql_dashboard.operation_store_operations_path
58-
assert_includes response.body, "0 Active"
59-
assert_includes response.body, "2 Archived"
60-
61-
get graphql_dashboard.archived_operation_store_operations_path
62-
assert_includes response.body, "2 Archived"
63-
assert_includes response.body, "0 Active"
64-
65-
get graphql_dashboard.operation_store_operations_path(client_name: "client-2")
66-
assert_includes response.body, "0 Active"
67-
assert_includes response.body, "1 Archived"
68-
end
69-
70-
def test_it_checks_installed
71-
get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
72-
assert_includes response.body, "isn't installed for this schema yet"
4+
if defined?(GraphQL::Pro)
5+
class DashboardOperationStoreOperationsControllerTest < ActionDispatch::IntegrationTest
6+
def teardown
7+
DummySchema.operation_store.delete_client("client-1")
8+
DummySchema.operation_store.delete_client("client-2")
9+
super
10+
end
11+
def test_it_lists_shows_and_archives_operations
12+
get graphql_dashboard.operation_store_operations_path
13+
assert_includes response.body, "Add your first stored operations with"
14+
15+
get graphql_dashboard.operation_store_operations_path(client_name: "client-5000")
16+
assert_includes response.body, "Add your first stored operations with"
17+
18+
get graphql_dashboard.archived_operation_store_operations_path
19+
assert_includes response.body, "Archived operations</a> will appear here."
20+
21+
get graphql_dashboard.archived_operation_store_client_operations_path(client_name: "client-5000")
22+
assert_includes response.body, "Archived operations</a> will appear here."
23+
24+
os = DummySchema.operation_store
25+
os.upsert_client("client-1", "abcdef")
26+
os.add(body: "query GetTypename { __typename }", operation_alias: "GetTypename", client_name: "client-1")
27+
os.add(body: "query GetAliasedTypename { t: __typename }", operation_alias: "get-aliased-typename", client_name: "client-1")
28+
29+
os.upsert_client("client-2", "abcdef")
30+
os.add(body: "query GetTypename { __typename }", operation_alias: "GetTypename2", client_name: "client-2")
31+
32+
get graphql_dashboard.operation_store_operations_path
33+
assert_includes response.body, "2 Active"
34+
assert_includes response.body, "GetTypename"
35+
assert_includes response.body, "GetAliasedTypename"
36+
37+
get graphql_dashboard.operation_store_operations_path(sort_by: "name", order_dir: "asc", per_page: 1)
38+
refute_includes response.body, "GetTypename"
39+
assert_includes response.body, "GetAliasedTypename"
40+
41+
get graphql_dashboard.operation_store_operations_path(sort_by: "name", order_dir: "desc", per_page: 1)
42+
assert_includes response.body, "GetTypename"
43+
refute_includes response.body, "GetAliasedTypename"
44+
45+
get graphql_dashboard.operation_store_operations_path(client_name: "client-2")
46+
assert_includes response.body, "1 Active"
47+
assert_includes response.body, "GetTypename"
48+
refute_includes response.body, "GetAliasedTypename"
49+
50+
get graphql_dashboard.operation_store_operation_path(digest: "4cd12cc333c91f78e8f781933ecc783d")
51+
assert_includes response.body, "GetAliasedTypename"
52+
assert_includes response.body, "client-1"
53+
assert_includes response.body, "Query.__typename"
54+
55+
post graphql_dashboard.archive_operation_store_client_operations_path(client_name: "client-1", operation_aliases: ["get-aliased-typename"])
56+
post graphql_dashboard.archive_operation_store_operations_path(digests: ["b161214b11847649e7f36cc50e1257a1"])
57+
58+
get graphql_dashboard.operation_store_operations_path
59+
assert_includes response.body, "0 Active"
60+
assert_includes response.body, "2 Archived"
61+
62+
get graphql_dashboard.archived_operation_store_operations_path
63+
assert_includes response.body, "2 Archived"
64+
assert_includes response.body, "0 Active"
65+
66+
get graphql_dashboard.operation_store_operations_path(client_name: "client-2")
67+
assert_includes response.body, "0 Active"
68+
assert_includes response.body, "1 Archived"
69+
end
70+
71+
def test_it_checks_installed
72+
get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
73+
assert_includes response.body, "isn't installed for this schema yet"
74+
end
7375
end
7476
end

0 commit comments

Comments
 (0)