2020-01-01 13:55:28 +05:30
|
|
|
# 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) }
|
2020-03-09 13:42:32 +05:30
|
|
|
let_it_be(:developer) { create(:user) { |u| project.add_developer(u) } }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe 'GET /projects/:id/remote_mirrors' do
|
|
|
|
let(:route) { "/projects/#{project.id}/remote_mirrors" }
|
|
|
|
|
|
|
|
it 'requires `admin_remote_mirror` permission' do
|
2020-03-09 13:42:32 +05:30
|
|
|
get api(route, developer)
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
# TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121
|
2020-01-01 13:55:28 +05:30
|
|
|
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
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
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
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|