Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fork_details_spec.rb « project « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91a04dc7c50a5b3daa74cee01a38e672c6dd5b6f (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'getting project fork details', feature_category: :source_code_management do
  include GraphqlHelpers
  include ProjectForksHelper

  let_it_be(:project) { create(:project, :public, :repository_private, :repository) }
  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: "#{ref}"){
        ahead
        behind
      }
      QUERY
    )
  end

  context 'when a ref is specified' do
    using RSpec::Parameterized::TableSyntax

    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
    let(:queried_project) { project }

    it 'does not return fork details' do
      post_graphql(query, current_user: current_user)

      expect(graphql_data['project']['forkDetails']).to be_nil
    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) }

    before do
      forked_project.update!({
                               repository_access_level: 'private',
                               merge_requests_access_level: 'private'
                             })
    end

    it 'does not return fork details' do
      post_graphql(query, current_user: current_user)

      expect(graphql_data['project']['forkDetails']).to be_nil
    end
  end
end