debian-mirror-gitlab/spec/requests/api/system_hooks_spec.rb

107 lines
2.8 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe API::SystemHooks do
2014-09-02 18:07:02 +05:30
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let!(:hook) { create(:system_hook, url: "http://example.com") }
2017-09-10 17:25:29 +05:30
before do
stub_request(:post, hook.url)
end
2014-09-02 18:07:02 +05:30
describe "GET /hooks" do
context "when no user" do
2016-09-13 17:45:13 +05:30
it "returns authentication error" do
2014-09-02 18:07:02 +05:30
get api("/hooks")
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2014-09-02 18:07:02 +05:30
end
end
context "when not an admin" do
2016-09-13 17:45:13 +05:30
it "returns forbidden error" do
2014-09-02 18:07:02 +05:30
get api("/hooks", user)
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(403)
2014-09-02 18:07:02 +05:30
end
end
context "when authenticated as admin" do
2016-09-13 17:45:13 +05:30
it "returns an array of hooks" do
2014-09-02 18:07:02 +05:30
get api("/hooks", admin)
2017-08-17 22:00:37 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2017-08-17 22:00:37 +05:30
expect(response).to include_pagination_headers
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.first['url']).to eq(hook.url)
2017-09-10 17:25:29 +05:30
expect(json_response.first['push_events']).to be false
2017-08-17 22:00:37 +05:30
expect(json_response.first['tag_push_events']).to be false
2017-09-10 17:25:29 +05:30
expect(json_response.first['repository_update_events']).to be true
2014-09-02 18:07:02 +05:30
end
end
end
describe "POST /hooks" do
2016-09-13 17:45:13 +05:30
it "creates new hook" do
2015-09-11 14:41:01 +05:30
expect do
2014-09-02 18:07:02 +05:30
post api("/hooks", admin), url: 'http://example.com'
2015-09-11 14:41:01 +05:30
end.to change { SystemHook.count }.by(1)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "responds with 400 if url not given" do
2014-09-02 18:07:02 +05:30
post api("/hooks", admin)
2017-08-17 22:00:37 +05:30
expect(response).to have_http_status(400)
end
it "responds with 400 if url is invalid" do
post api("/hooks", admin), url: 'hp://mep.mep'
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(400)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "does not create new hook without url" do
2015-09-11 14:41:01 +05:30
expect do
2014-09-02 18:07:02 +05:30
post api("/hooks", admin)
end.not_to change { SystemHook.count }
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
it 'sets default values for events' do
post api('/hooks', admin), url: 'http://mep.mep', enable_ssl_verification: true
expect(response).to have_http_status(201)
expect(json_response['enable_ssl_verification']).to be true
expect(json_response['tag_push_events']).to be false
end
2014-09-02 18:07:02 +05:30
end
describe "GET /hooks/:id" do
2016-09-13 17:45:13 +05:30
it "returns hook by id" do
2014-09-02 18:07:02 +05:30
get api("/hooks/#{hook.id}", admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['event_name']).to eq('project_create')
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns 404 on failure" do
2014-09-02 18:07:02 +05:30
get api("/hooks/404", admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
describe "DELETE /hooks/:id" do
2016-09-13 17:45:13 +05:30
it "deletes a hook" do
2015-09-11 14:41:01 +05:30
expect do
2014-09-02 18:07:02 +05:30
delete api("/hooks/#{hook.id}", admin)
2017-08-17 22:00:37 +05:30
expect(response).to have_http_status(204)
2015-09-11 14:41:01 +05:30
end.to change { SystemHook.count }.by(-1)
2014-09-02 18:07:02 +05:30
end
2016-11-03 12:29:30 +05:30
it 'returns 404 if the system hook does not exist' do
delete api('/hooks/12345', admin)
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
end