2019-04-22 15:46:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-17 19:43:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
# Based on spec/requests/api/groups_spec.rb
|
|
|
|
# Should follow closely in order to ensure all situations are covered
|
2020-03-02 07:07:57 -05:00
|
|
|
describe 'getting group information', :do_not_mock_admin_mode do
|
2019-04-17 19:43:19 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
include UploadHelpers
|
|
|
|
|
2019-04-22 15:46:13 -04:00
|
|
|
let(:user1) { create(:user, can_create_group: false) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:public_group) { create(:group, :public) }
|
|
|
|
let(:private_group) { create(:group, :private) }
|
2019-04-17 19:43:19 -04:00
|
|
|
|
|
|
|
# similar to the API "GET /groups/:id"
|
|
|
|
describe "Query group(fullPath)" do
|
|
|
|
def group_query(group)
|
|
|
|
graphql_query_for('group', 'fullPath' => group.full_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a working graphql query' do
|
|
|
|
before do
|
2019-04-22 15:46:13 -04:00
|
|
|
post_graphql(group_query(public_group))
|
2019-04-17 19:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated' do
|
|
|
|
it 'returns nil for a private group' do
|
2019-04-22 15:46:13 -04:00
|
|
|
post_graphql(group_query(private_group))
|
2019-04-17 19:43:19 -04:00
|
|
|
|
|
|
|
expect(graphql_data['group']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a public group' do
|
2019-04-22 15:46:13 -04:00
|
|
|
post_graphql(group_query(public_group))
|
2019-04-17 19:43:19 -04:00
|
|
|
|
|
|
|
expect(graphql_data['group']).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when authenticated as user" do
|
2019-04-22 15:46:13 -04:00
|
|
|
let!(:group1) { create(:group, avatar: File.open(uploaded_image_temp_path)) }
|
|
|
|
let!(:group2) { create(:group, :private) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group1.add_owner(user1)
|
|
|
|
group2.add_owner(user2)
|
|
|
|
end
|
|
|
|
|
2019-04-17 19:43:19 -04:00
|
|
|
it "returns one of user1's groups" do
|
|
|
|
project = create(:project, namespace: group2, path: 'Foo')
|
2020-03-24 08:09:42 -04:00
|
|
|
issue = create(:issue, project: create(:project, group: group1))
|
2019-04-17 19:43:19 -04:00
|
|
|
create(:project_group_link, project: project, group: group1)
|
|
|
|
|
|
|
|
post_graphql(group_query(group1), current_user: user1)
|
|
|
|
|
2020-02-17 13:09:00 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-06-03 13:38:16 -04:00
|
|
|
expect(graphql_data['group']['id']).to eq(group1.to_global_id.to_s)
|
2019-04-17 19:43:19 -04:00
|
|
|
expect(graphql_data['group']['name']).to eq(group1.name)
|
|
|
|
expect(graphql_data['group']['path']).to eq(group1.path)
|
|
|
|
expect(graphql_data['group']['description']).to eq(group1.description)
|
|
|
|
expect(graphql_data['group']['visibility']).to eq(Gitlab::VisibilityLevel.string_level(group1.visibility_level))
|
|
|
|
expect(graphql_data['group']['avatarUrl']).to eq(group1.avatar_url(only_path: false))
|
|
|
|
expect(graphql_data['group']['webUrl']).to eq(group1.web_url)
|
|
|
|
expect(graphql_data['group']['requestAccessEnabled']).to eq(group1.request_access_enabled)
|
|
|
|
expect(graphql_data['group']['fullName']).to eq(group1.full_name)
|
|
|
|
expect(graphql_data['group']['fullPath']).to eq(group1.full_path)
|
|
|
|
expect(graphql_data['group']['parentId']).to eq(group1.parent_id)
|
2020-03-24 08:09:42 -04:00
|
|
|
expect(graphql_data['group']['issues']['nodes'].count).to eq(1)
|
|
|
|
expect(graphql_data['group']['issues']['nodes'][0]['iid']).to eq(issue.iid.to_s)
|
2019-04-17 19:43:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return a non existing group" do
|
|
|
|
query = graphql_query_for('group', 'fullPath' => '1328')
|
2019-04-22 15:46:13 -04:00
|
|
|
|
2019-04-17 19:43:19 -04:00
|
|
|
post_graphql(query, current_user: user1)
|
|
|
|
|
|
|
|
expect(graphql_data['group']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return a group not attached to user1" do
|
2019-04-22 15:46:13 -04:00
|
|
|
private_group.add_owner(user2)
|
|
|
|
|
|
|
|
post_graphql(group_query(private_group), current_user: user1)
|
2019-04-17 19:43:19 -04:00
|
|
|
|
|
|
|
expect(graphql_data['group']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'avoids N+1 queries' do
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new do
|
|
|
|
post_graphql(group_query(group1), current_user: admin)
|
|
|
|
end.count
|
|
|
|
|
2019-05-12 17:10:46 -04:00
|
|
|
queries = [{ query: group_query(group1) },
|
|
|
|
{ query: group_query(group2) }]
|
2019-04-17 19:43:19 -04:00
|
|
|
|
|
|
|
expect do
|
2019-05-12 17:10:46 -04:00
|
|
|
post_multiplex(queries, current_user: admin)
|
2019-04-17 19:43:19 -04:00
|
|
|
end.not_to exceed_query_limit(control_count)
|
2019-05-12 17:10:46 -04:00
|
|
|
|
|
|
|
expect(graphql_errors).to contain_exactly(nil, nil)
|
2019-04-17 19:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when authenticated as admin" do
|
|
|
|
it "returns any existing group" do
|
2019-04-22 15:46:13 -04:00
|
|
|
post_graphql(group_query(private_group), current_user: admin)
|
2019-04-17 19:43:19 -04:00
|
|
|
|
2019-04-22 15:46:13 -04:00
|
|
|
expect(graphql_data['group']['name']).to eq(private_group.name)
|
2019-04-17 19:43:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return a non existing group" do
|
|
|
|
query = graphql_query_for('group', 'fullPath' => '1328')
|
|
|
|
post_graphql(query, current_user: admin)
|
|
|
|
|
|
|
|
expect(graphql_data['group']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|