diff options
Diffstat (limited to 'spec/requests/api/graphql/project/fork_details_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/project/fork_details_spec.rb | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/spec/requests/api/graphql/project/fork_details_spec.rb b/spec/requests/api/graphql/project/fork_details_spec.rb index efd48b00833..91a04dc7c50 100644 --- a/spec/requests/api/graphql/project/fork_details_spec.rb +++ b/spec/requests/api/graphql/project/fork_details_spec.rb @@ -10,12 +10,13 @@ RSpec.describe 'getting project fork details', feature_category: :source_code_ma let_it_be(:current_user) { create(:user, maintainer_projects: [project]) } let_it_be(:forked_project) { fork_project(project, current_user, repository: true) } + let(:ref) { 'feature' } let(:queried_project) { forked_project } let(:query) do graphql_query_for(:project, { full_path: queried_project.full_path }, <<~QUERY - forkDetails(ref: "feature"){ + forkDetails(ref: "#{ref}"){ ahead behind } @@ -23,12 +24,23 @@ RSpec.describe 'getting project fork details', feature_category: :source_code_ma ) end - it 'returns fork details' do - post_graphql(query, current_user: current_user) + context 'when a ref is specified' do + using RSpec::Parameterized::TableSyntax - expect(graphql_data['project']['forkDetails']).to eq( - { 'ahead' => 1, 'behind' => 29 } - ) + where(:ref, :counts) do + 'feature' | { 'ahead' => 1, 'behind' => 29 } + 'v1.1.1' | { 'ahead' => 5, 'behind' => 0 } + '7b5160f9bb23a3d58a0accdbe89da13b96b1ece9' | { 'ahead' => 9, 'behind' => 0 } + 'non-existent-branch' | { 'ahead' => nil, 'behind' => nil } + end + + with_them do + it 'returns fork details' do + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['forkDetails']).to eq(counts) + end + end end context 'when a project is not a fork' do @@ -41,6 +53,16 @@ RSpec.describe 'getting project fork details', feature_category: :source_code_ma end end + context 'when project source is not visible' do + it 'does not return fork details' do + project.team.truncate + + post_graphql(query, current_user: current_user) + + expect(graphql_data['project']['forkDetails']).to be_nil + end + end + context 'when a user cannot read the code' do let_it_be(:current_user) { create(:user) } |