Commit 98f8fe95 authored by Rajendra Kadam's avatar Rajendra Kadam

Add optional enabled parameter and refactor and improve specs

parent 8961d279
......@@ -31,6 +31,7 @@ module API
end
params do
requires :url, type: String, desc: 'The URL for a remote mirror'
optional :enabled, type: Boolean, desc: 'Determines if the mirror is enabled'
optional :only_protected_branches, type: Boolean, desc: 'Determines if only protected branches are mirrored'
end
post ':id/remote_mirrors' do
......
......@@ -42,21 +42,37 @@ describe API::RemoteMirrors do
describe 'POST /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }
shared_examples 'creates a remote mirror' do
it 'creates a remote mirror and returns reponse' do
project.add_maintainer(user)
post api(route, user), params: params
enabled = params.fetch(:enabled, false)
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirror')
expect(json_response['enabled']).to eq(enabled)
end
end
it 'requires `admin_remote_mirror` permission' do
post api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'creates a remote mirror' do
project.add_maintainer(user)
context 'creates a remote mirror' do
context 'disabled by default' do
let(:params) { { url: 'https://foo:bar@test.com' } }
post api(route, user), params: {
url: 'https://foo:bar@test.com'
}
it_behaves_like 'creates a remote mirror'
end
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirror')
context 'enabled' do
let(:params) { { url: 'https://foo:bar@test.com', enabled: true } }
it_behaves_like 'creates a remote mirror'
end
end
it 'returns error if url is invalid' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment