2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe 'getting a repository in a project' do
|
2019-09-04 21:01:54 +05:30
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project, :repository) }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:current_user) { project.first_owner }
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:fields) do
|
|
|
|
<<~QUERY
|
|
|
|
#{all_graphql_fields_for('repository'.classify)}
|
|
|
|
QUERY
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:query) do
|
|
|
|
graphql_query_for(
|
|
|
|
'project',
|
|
|
|
{ 'fullPath' => project.full_path },
|
|
|
|
query_graphql_field('repository', {}, fields)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns repository' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as a non-authorized user' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(graphql_data['project']).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'as a non-admin' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_role(current_user, :developer)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return diskPath' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']).not_to be_nil
|
|
|
|
expect(graphql_data['project']['repository']['diskPath']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as an admin' do
|
|
|
|
it 'returns diskPath' do
|
|
|
|
post_graphql(query, current_user: create(:admin))
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']).not_to be_nil
|
|
|
|
expect(graphql_data['project']['repository']['diskPath']).to eq project.disk_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when the repository is only accessible to members' do
|
|
|
|
let(:project) do
|
|
|
|
create(:project, :public, :repository, repository_access_level: ProjectFeature::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a repository for the owner' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for the repository for other users' do
|
|
|
|
post_graphql(query, current_user: create(:user))
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for the repository for other users' do
|
|
|
|
post_graphql(query, current_user: nil)
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
context 'when paginated tree requested' do
|
|
|
|
let(:fields) do
|
|
|
|
%(
|
|
|
|
paginatedTree {
|
|
|
|
nodes {
|
|
|
|
trees {
|
|
|
|
nodes {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns paginated tree' do
|
|
|
|
post_graphql(query, current_user: current_user)
|
|
|
|
|
|
|
|
expect(graphql_data['project']['repository']['paginatedTree']).to be_present
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|