Skip to content

Commit a8d6a9e

Browse files
authored
test: use newer UserInfo GQL query in tests (#95)
1 parent 879902c commit a8d6a9e

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

test/datasets-live.jl

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import HTTP, JSON, JuliaHub
2-
function _get_user_groups_rest(auth::JuliaHub.Authentication)
3-
r = HTTP.get(
4-
JuliaHub._url(auth, "user", "groups"),
5-
JuliaHub._authheaders(auth),
6-
)
7-
r.status == 200 && return String.(JSON.parse(String(r.body)))
8-
JuliaHub._throw_invalidresponse(r)
9-
end
10-
function _get_user_groups_gql(auth::JuliaHub.Authentication)
2+
function _get_user_groups(auth::JuliaHub.Authentication)::Vector{String}
113
# Note: this query is newer than the one we use in src/userinfo.jl, and works
124
# with newer JuliaHub versions, whereas the other one specifically works with
13-
# older versions.
5+
# older versions. This specific query has been tested with JuliaHub 6.8+
146
userinfo_gql = read(joinpath(@__DIR__, "userInfo.gql"), String)
15-
r = JuliaHub._gql_request(auth, userinfo_gql)
16-
r.status == 200 || error("Invalid response from GQL ($(r.status))\n$(r.body)")
17-
user = only(r.json["data"]["users"])
18-
String[g["group"]["name"] for g in user["groups"]]
19-
end
20-
function _get_user_groups(auth::JuliaHub.Authentication)::Vector{String}
21-
rest_exception = try
22-
return _get_user_groups_rest(auth)
23-
catch e
24-
@debug "Failed to fetch user groups via REST API" exception = (e, catch_backtrace())
25-
e, catch_backtrace()
26-
end
277
try
28-
return _get_user_groups_gql(auth)
8+
r = JuliaHub._gql_request(auth, userinfo_gql)
9+
r.status == 200 || error("Invalid response from GQL ($(r.status))\n$(r.body)")
10+
user = only(r.json["data"]["users"])
11+
return String[g["group"]["name"] for g in user["groups"]]
2912
catch e
3013
@error "Unable to determine valid user groups"
3114
@error "> REST API failure" exception = rest_exception

test/userInfo.gql

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# # LIMITATIONS ON EXTERNAL USE: external users are only allowed to depend
2+
# # on certain fields exposed in this query. No backwards compatibility
3+
# # guarantees are made for the fields marked "DISALLOWED".
4+
#
5+
# external_query = true
6+
# roles = ["default"]
7+
18
query UserInfo {
29
users(limit: 1) {
310
id
@@ -6,7 +13,19 @@ query UserInfo {
613
emails {
714
email
815
}
9-
groups: user_groups {
16+
# DISALLOWED: .features is disallowed for external users
17+
# No guarantees are made about the contents or validity of this field.
18+
features: user_feature_maps {
19+
feature {
20+
name
21+
id
22+
product_id
23+
}
24+
}
25+
# DISALLOWED: .get_started_viewed is disallowed for external users
26+
# No guarantees are made about the contents or validity of this field.
27+
get_started_viewed
28+
groups: user_groups(where: { _not: { is_deleted: { _eq: true } } }) {
1029
id: group_id
1130
group {
1231
name
@@ -22,6 +41,15 @@ query UserInfo {
2241
}
2342
}
2443
accepted_tos
44+
# DISALLOWED: .accepted_tos_time is disallowed for external users
45+
# No guarantees are made about the contents or validity of this field.
46+
accepted_tos_time
2547
survey_submitted_time
2648
}
49+
# DISALLOWED: .features is disallowed for external users
50+
# No guarantees are made about the contents or validity of this field.
51+
features(where: { public: { _eq: true } }) {
52+
id
53+
name
54+
}
2755
}

0 commit comments

Comments
 (0)