Be able to POST subscriptions for system hooks
This commit is contained in:
parent
76690017e2
commit
a4827ee2b9
2 changed files with 20 additions and 2 deletions
|
@ -19,10 +19,14 @@ module API
|
|||
success Entities::Hook
|
||||
end
|
||||
params do
|
||||
requires :url, type: String, desc: 'The URL for the system hook'
|
||||
requires :url, type: String, desc: "The URL to send the request to"
|
||||
optional :token, type: String, desc: 'The token used to validate payloads'
|
||||
optional :push_events, type: Boolean, desc: "Trigger hook on push events"
|
||||
optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
|
||||
optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
|
||||
end
|
||||
post do
|
||||
hook = SystemHook.new declared(params).to_h
|
||||
hook = SystemHook.new declared(params, include_missing: false).to_h
|
||||
|
||||
if hook.save
|
||||
present hook, with: Entities::Hook
|
||||
|
|
|
@ -13,6 +13,7 @@ describe API::API, api: true do
|
|||
context "when no user" do
|
||||
it "returns authentication error" do
|
||||
get api("/hooks")
|
||||
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
|
@ -20,6 +21,7 @@ describe API::API, api: true do
|
|||
context "when not an admin" do
|
||||
it "returns forbidden error" do
|
||||
get api("/hooks", user)
|
||||
|
||||
expect(response).to have_http_status(403)
|
||||
end
|
||||
end
|
||||
|
@ -27,9 +29,13 @@ describe API::API, api: true do
|
|||
context "when authenticated as admin" do
|
||||
it "returns an array of hooks" do
|
||||
get api("/hooks", admin)
|
||||
|
||||
byebug
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json_response).to be_an Array
|
||||
expect(json_response.first['url']).to eq(hook.url)
|
||||
expect(json_response.first['push_events']).to be true
|
||||
expect(json_response.first['tag_push_events']).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -51,6 +57,14 @@ describe API::API, api: true do
|
|||
post api("/hooks", admin)
|
||||
end.not_to change { SystemHook.count }
|
||||
end
|
||||
|
||||
it 'allows the events to be selected' 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
|
||||
end
|
||||
|
||||
describe "GET /hooks/:id" do
|
||||
|
|
Loading…
Reference in a new issue