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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['User'], feature_category: :user_profile do
specify { expect(described_class.graphql_name).to eq('User') }
specify do
runtime_type = described_class.resolve_type(build(:user), {})
expect(runtime_type).to require_graphql_authorizations(:read_user)
end
it 'has the expected fields' do
expected_fields = %w[
id
bot
user_permissions
snippets
name
username
email
emails
publicEmail
commitEmail
namespaceCommitEmails
avatarUrl
webUrl
webPath
todos
state
status
location
authoredMergeRequests
assignedMergeRequests
reviewRequestedMergeRequests
groupMemberships
groupCount
projectMemberships
starredProjects
callouts
namespace
timelogs
groups
gitpodEnabled
preferencesGitpodPath
profileEnableGitpodPath
savedReplies
savedReply
user_achievements
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
describe 'name field' do
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:user) { create(:user) }
let_it_be(:requested_user) { create(:user, name: 'John Smith') }
let_it_be(:requested_project_bot) { create(:user, :project_bot, name: 'Project bot') }
let_it_be(:requested_group_bot) { create(:user, :project_bot, name: 'Group bot') }
let_it_be(:project) { create(:project, :public) }
let_it_be(:group) { create(:group, :public) }
before do
project.add_maintainer(requested_project_bot)
group.add_maintainer(requested_group_bot)
end
let(:username) { requested_user.username }
let(:query) do
%(
query {
user(username: "#{username}") {
name
}
}
)
end
subject(:user_name) { GitlabSchema.execute(query, context: { current_user: current_user }).as_json.dig('data', 'user', 'name') }
context 'user requests' do
let(:current_user) { user }
context 'a user' do
it 'returns name' do
expect(user_name).to eq('John Smith')
end
end
context 'a project bot' do
let(:username) { requested_project_bot.username }
context 'when requester is nil' do
let(:current_user) { nil }
it 'returns nothing' do
expect(user_name).to be_nil
end
end
context 'when the requester is not a project member' do
it 'returns `Project bot` for a non project member in a public project' do
expect(user_name).to eq('Project bot')
end
context 'in a private project' do
let(:project) { create(:project, :private) }
it 'returns `****` for a non project member in a private project' do
expect(user_name).to eq('****')
end
end
end
context 'with a project member' do
before do
project.add_guest(user)
end
it 'returns `Project bot` for a project member' do
expect(user_name).to eq('Project bot')
end
context 'in a private project' do
let(:project) { create(:project, :private) }
it 'returns `Project bot` for a project member in a private project' do
expect(user_name).to eq('Project bot')
end
end
end
context 'a group bot' do
let(:username) { requested_group_bot.username }
context 'when requester is nil' do
let(:current_user) { nil }
it 'returns nothing' do
expect(user_name).to be_nil
end
end
context 'when the requester is not a group member' do
it 'returns `Group bot` for a non group member in a public group' do
expect(user_name).to eq('Group bot')
end
context 'in a private group' do
let(:group) { create(:group, :private) }
it 'returns `****` for a non group member in a private group' do
expect(user_name).to eq('****')
end
end
end
context 'with a group member' do
before do
group.add_guest(user)
end
it 'returns `Group bot` for a group member' do
expect(user_name).to eq('Group bot')
end
context 'in a private group' do
let(:group) { create(:group, :private) }
it 'returns `Group bot` for a group member in a private group' do
expect(user_name).to eq('Group bot')
end
end
end
end
end
end
context 'admin requests', :enable_admin_mode do
let(:current_user) { admin }
context 'a user' do
it 'returns name' do
expect(subject).to eq('John Smith')
end
end
context 'a project bot' do
let(:username) { requested_project_bot.username }
it 'returns name' do
expect(subject).to eq('Project bot')
end
end
context 'a group bot' do
let(:username) { requested_group_bot.username }
it 'returns name' do
expect(subject).to eq('Group bot')
end
end
end
end
describe 'snippets field' do
subject { described_class.fields['snippets'] }
it 'returns snippets' do
is_expected.to have_graphql_type(Types::SnippetType.connection_type)
is_expected.to have_graphql_resolver(Resolvers::Users::SnippetsResolver)
end
end
describe 'callouts field' do
subject { described_class.fields['callouts'] }
it 'returns user callouts' do
is_expected.to have_graphql_type(Types::UserCalloutType.connection_type)
end
end
describe 'timelogs field' do
subject { described_class.fields['timelogs'] }
it 'returns user timelogs' do
is_expected.to have_graphql_resolver(Resolvers::TimelogResolver)
is_expected.to have_graphql_type(Types::TimelogType.connection_type)
end
end
describe 'emails field' do
subject { described_class.fields['emails'] }
it 'returns user emails' do
is_expected.to have_graphql_type(Types::Users::EmailType.connection_type)
end
end
describe 'namespaceCommitEmails field' do
subject { described_class.fields['namespaceCommitEmails'] }
it 'returns user namespace_commit_emails' do
is_expected.to have_graphql_type(Types::Users::NamespaceCommitEmailType.connection_type)
end
end
end
|