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 ...@@ -31,6 +31,7 @@ module API
end end
params do params do
requires :url, type: String, desc: 'The URL for a remote mirror' 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' optional :only_protected_branches, type: Boolean, desc: 'Determines if only protected branches are mirrored'
end end
post ':id/remote_mirrors' do post ':id/remote_mirrors' do
......
...@@ -42,21 +42,37 @@ describe API::RemoteMirrors do ...@@ -42,21 +42,37 @@ describe API::RemoteMirrors do
describe 'POST /projects/:id/remote_mirrors' do describe 'POST /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" } 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 it 'requires `admin_remote_mirror` permission' do
post api(route, developer) post api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it 'creates a remote mirror' do context 'creates a remote mirror' do
project.add_maintainer(user) context 'disabled by default' do
let(:params) { { url: 'https://foo:bar@test.com' } }
post api(route, user), params: { it_behaves_like 'creates a remote mirror'
url: 'https://foo:bar@test.com' end
}
expect(response).to have_gitlab_http_status(:success) context 'enabled' do
expect(response).to match_response_schema('remote_mirror') let(:params) { { url: 'https://foo:bar@test.com', enabled: true } }
it_behaves_like 'creates a remote mirror'
end
end end
it 'returns error if url is invalid' do 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