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

remote_mirrors_spec.rb « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 065d9c7ca5bf4ca35d12a9747b168c8f804dfade (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
# frozen_string_literal: true

require 'spec_helper'

describe API::RemoteMirrors do
  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project, :repository, :remote_mirror) }
  let_it_be(:developer) { create(:user) { |u| project.add_developer(u) } }

  describe 'GET /projects/:id/remote_mirrors' do
    let(:route) { "/projects/#{project.id}/remote_mirrors" }

    it 'requires `admin_remote_mirror` permission' do
      get api(route, developer)

      expect(response).to have_gitlab_http_status(:unauthorized)
    end

    it 'returns a list of remote mirrors' do
      project.add_maintainer(user)

      get api(route, user)

      expect(response).to have_gitlab_http_status(:success)
      expect(response).to match_response_schema('remote_mirrors')
    end

    # TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121
    context 'with the `remote_mirrors_api` feature disabled' do
      before do
        stub_feature_flags(remote_mirrors_api: false)
      end

      it 'responds with `not_found`' do
        get api(route, user)

        expect(response).to have_gitlab_http_status(:not_found)
      end
    end
  end

  describe 'PUT /projects/:id/remote_mirrors/:mirror_id' do
    let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
    let(:mirror) { project.remote_mirrors.first }

    it 'requires `admin_remote_mirror` permission' do
      put api(route[mirror.id], developer)

      expect(response).to have_gitlab_http_status(:unauthorized)
    end

    it 'updates a remote mirror' do
      project.add_maintainer(user)

      put api(route[mirror.id], user), params: {
        enabled: '0',
        only_protected_branches: 'true'
      }

      expect(response).to have_gitlab_http_status(:success)
      expect(json_response['enabled']).to eq(false)
      expect(json_response['only_protected_branches']).to eq(true)
    end

    # TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121
    context 'with the `remote_mirrors_api` feature disabled' do
      before do
        stub_feature_flags(remote_mirrors_api: false)
      end

      it 'responds with `not_found`' do
        put api(route[mirror.id], user)

        expect(response).to have_gitlab_http_status(:not_found)
      end
    end
  end
end