diff options
Diffstat (limited to 'spec/requests/api/system_hooks_spec.rb')
-rw-r--r-- | spec/requests/api/system_hooks_spec.rb | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/spec/requests/api/system_hooks_spec.rb b/spec/requests/api/system_hooks_spec.rb index 1511872d183..d94b70ec0f9 100644 --- a/spec/requests/api/system_hooks_spec.rb +++ b/spec/requests/api/system_hooks_spec.rb @@ -36,12 +36,57 @@ RSpec.describe API::SystemHooks do expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers - expect(json_response).to be_an Array + expect(response).to match_response_schema('public_api/v4/system_hooks') + expect(json_response.first).not_to have_key("token") expect(json_response.first['url']).to eq(hook.url) expect(json_response.first['push_events']).to be false expect(json_response.first['tag_push_events']).to be false expect(json_response.first['merge_requests_events']).to be false expect(json_response.first['repository_update_events']).to be true + expect(json_response.first['enable_ssl_verification']).to be true + end + end + end + + describe "GET /hooks/:id" do + context "when no user" do + it "returns authentication error" do + get api("/hooks/#{hook.id}") + + expect(response).to have_gitlab_http_status(:unauthorized) + end + end + + context "when not an admin" do + it "returns forbidden error" do + get api("/hooks/#{hook.id}", user) + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context "when authenticated as admin" do + it "gets a hook", :aggregate_failures do + get api("/hooks/#{hook.id}", admin) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/system_hook') + expect(json_response).to match( + 'id' => be(hook.id), + 'url' => eq(hook.url), + 'created_at' => eq(hook.created_at.iso8601(3)), + 'push_events' => be(hook.push_events), + 'tag_push_events' => be(hook.tag_push_events), + 'merge_requests_events' => be(hook.merge_requests_events), + 'repository_update_events' => be(hook.repository_update_events), + 'enable_ssl_verification' => be(hook.enable_ssl_verification) + ) + end + + it 'returns 404 if the system hook does not exist' do + get api("/hooks/#{non_existing_record_id}", admin) + + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -77,6 +122,7 @@ RSpec.describe API::SystemHooks do post api('/hooks', admin), params: { url: 'http://mep.mep' } expect(response).to have_gitlab_http_status(:created) + expect(response).to match_response_schema('public_api/v4/system_hook') expect(json_response['enable_ssl_verification']).to be true expect(json_response['push_events']).to be false expect(json_response['tag_push_events']).to be false @@ -98,6 +144,7 @@ RSpec.describe API::SystemHooks do } expect(response).to have_gitlab_http_status(:created) + expect(response).to match_response_schema('public_api/v4/system_hook') expect(json_response['enable_ssl_verification']).to be false expect(json_response['push_events']).to be true expect(json_response['tag_push_events']).to be true |