2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Projects > Settings > Webhook Settings', feature_category: :projects do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:webhooks_path) { project_hooks_path(project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_role(user, role)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'for developer' do
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:role) { :developer }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'to be disallowed to view' do
|
2020-04-08 14:13:33 +05:30
|
|
|
visit webhooks_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(page.status_code).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
context 'for maintainer' do
|
|
|
|
let(:role) { :maintainer }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'Webhooks' do
|
|
|
|
let(:hook) { create(:project_hook, :all_events_enabled, enable_ssl_verification: true, project: project) }
|
|
|
|
let(:url) { generate(:url) }
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'show list of webhooks' do
|
2017-08-17 22:00:37 +05:30
|
|
|
hook
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
visit webhooks_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(page.status_code).to eq(200)
|
|
|
|
expect(page).to have_content(hook.url)
|
|
|
|
expect(page).to have_content('SSL Verification: enabled')
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_content('Push events')
|
|
|
|
expect(page).to have_content('Tag push events')
|
|
|
|
expect(page).to have_content('Issues events')
|
|
|
|
expect(page).to have_content('Confidential issues events')
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(page).to have_content('Comment')
|
|
|
|
expect(page).to have_content('Merge request events')
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(page).to have_content('Pipeline events')
|
|
|
|
expect(page).to have_content('Wiki page events')
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(page).to have_content('Releases events')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it 'create webhook', :js do
|
|
|
|
visit webhooks_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
fill_in 'URL', with: url
|
|
|
|
check 'Tag push events'
|
|
|
|
check 'Enable SSL verification'
|
|
|
|
check 'Job events'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
click_button 'Add webhook'
|
2023-01-13 00:05:48 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(page).to have_content(url)
|
|
|
|
expect(page).to have_content('SSL Verification: enabled')
|
|
|
|
expect(page).to have_content('Tag push events')
|
|
|
|
expect(page).to have_content('Job events')
|
|
|
|
expect(page).to have_content('Push events')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it 'edit existing webhook', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
hook
|
2020-04-08 14:13:33 +05:30
|
|
|
visit webhooks_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
click_link 'Edit'
|
2022-11-25 23:54:43 +05:30
|
|
|
fill_in 'URL', with: url
|
2017-08-17 22:00:37 +05:30
|
|
|
check 'Enable SSL verification'
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(page).to have_content('Enable SSL verification')
|
|
|
|
expect(page).to have_current_path(edit_project_hook_path(project, hook), ignore_query: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'test existing webhook', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
WebMock.stub_request(:post, hook.url)
|
2020-04-08 14:13:33 +05:30
|
|
|
visit webhooks_path
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
find('.hook-test-button.dropdown').click
|
|
|
|
click_link 'Push events'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path(webhooks_path, ignore_query: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
context 'delete existing webhook' do
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'from webhooks list page' do
|
2017-09-10 17:25:29 +05:30
|
|
|
hook
|
2020-04-08 14:13:33 +05:30
|
|
|
visit webhooks_path
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect { click_link 'Delete' }.to change(ProjectHook, :count).by(-1)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'from webhook edit page' do
|
2017-09-10 17:25:29 +05:30
|
|
|
hook
|
2020-04-08 14:13:33 +05:30
|
|
|
visit webhooks_path
|
2017-09-10 17:25:29 +05:30
|
|
|
click_link 'Edit'
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
expect { click_link 'Delete' }.to change(ProjectHook, :count).by(-1)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Webhook logs' do
|
|
|
|
let(:hook) { create(:project_hook, project: project) }
|
|
|
|
let(:hook_log) { create(:web_hook_log, web_hook: hook, internal_error_message: 'some error') }
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'show list of hook logs' do
|
2017-09-10 17:25:29 +05:30
|
|
|
hook_log
|
|
|
|
visit edit_project_hook_path(project, hook)
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(page).to have_content('Recent events')
|
|
|
|
expect(page).to have_link('View details', href: hook_log.present.details_path)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'show hook log details' do
|
2017-09-10 17:25:29 +05:30
|
|
|
hook_log
|
|
|
|
visit edit_project_hook_path(project, hook)
|
|
|
|
click_link 'View details'
|
|
|
|
|
|
|
|
expect(page).to have_content("POST #{hook_log.url}")
|
|
|
|
expect(page).to have_content(hook_log.internal_error_message)
|
|
|
|
expect(page).to have_content('Resend Request')
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'retry hook log' do
|
2017-09-10 17:25:29 +05:30
|
|
|
WebMock.stub_request(:post, hook.url)
|
|
|
|
|
|
|
|
hook_log
|
|
|
|
visit edit_project_hook_path(project, hook)
|
|
|
|
click_link 'View details'
|
|
|
|
click_link 'Resend Request'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path(edit_project_hook_path(project, hook), ignore_query: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
it 'does not show search settings on the hook log details' do
|
|
|
|
visit project_hook_hook_log_path(project, hook, hook_log)
|
|
|
|
|
|
|
|
expect(page).not_to have_field(placeholder: 'Search settings', disabled: true)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|