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

project_spec.rb « entities « api « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a5349bb59b495ab9f08fa6c106d4d6676e84d81 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ::API::Entities::Project do
  let(:project) { create(:project, :public) }
  let(:current_user) { create(:user) }
  let(:options) { { current_user: current_user } }

  let(:entity) do
    ::API::Entities::Project.new(project, options)
  end

  subject(:json) { entity.as_json }

  context 'without project feature' do
    before do
      project.project_feature.destroy!
      project.reload
    end

    it 'returns a response' do
      expect(json[:issues_access_level]).to be_nil
      expect(json[:repository_access_level]).to be_nil
      expect(json[:merge_requests_access_level]).to be_nil
    end
  end

  describe '.service_desk_address' do
    before do
      allow(project).to receive(:service_desk_enabled?).and_return(true)
    end

    context 'when a user can admin issues' do
      before do
        project.add_reporter(current_user)
      end

      it 'is present' do
        expect(json[:service_desk_address]).to be_present
      end
    end

    context 'when a user can not admin project' do
      it 'is empty' do
        expect(json[:service_desk_address]).to be_nil
      end
    end
  end

  describe '.shared_with_groups' do
    let(:group) { create(:group, :private) }

    before do
      project.project_group_links.create!(group: group)
    end

    context 'when the current user does not have access to the group' do
      it 'is empty' do
        expect(json[:shared_with_groups]).to be_empty
      end
    end

    context 'when the current user has access to the group' do
      before do
        group.add_guest(current_user)
      end

      it 'contains information about the shared group' do
        expect(json[:shared_with_groups]).to contain_exactly(include(group_id: group.id))
      end
    end
  end

  describe '.ci/cd settings' do
    context 'when the user is not an admin' do
      before do
        project.add_reporter(current_user)
      end

      it 'does not return ci settings' do
        expect(json[:ci_default_git_depth]).to be_nil
      end
    end

    context 'when the user has admin privileges' do
      before do
        project.add_maintainer(current_user)
      end

      it 'returns ci settings' do
        expect(json[:ci_default_git_depth]).to be_present
      end
    end
  end
end