2014-01-15 09:38:48 -05:00
|
|
|
require 'webmock'
|
|
|
|
|
2014-09-22 10:30:25 -04:00
|
|
|
class Spinach::Features::ProjectHooks < Spinach::FeatureSteps
|
2012-09-27 16:52:08 -04:00
|
|
|
include SharedAuthentication
|
|
|
|
include SharedProject
|
|
|
|
include SharedPaths
|
|
|
|
include RSpec::Matchers
|
|
|
|
include RSpec::Mocks::ExampleMethods
|
2014-01-15 09:38:48 -05:00
|
|
|
include WebMock::API
|
2012-09-27 16:52:08 -04:00
|
|
|
|
2014-07-27 16:26:23 -04:00
|
|
|
step 'project has hook' do
|
2012-11-05 22:31:55 -05:00
|
|
|
@hook = create(:project_hook, project: current_project)
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|
|
|
|
|
2014-07-27 16:26:23 -04:00
|
|
|
step 'I own empty project with hook' do
|
|
|
|
@project = create(:empty_project,
|
|
|
|
name: 'Empty Project', namespace: @user.namespace)
|
|
|
|
@hook = create(:project_hook, project: current_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
step 'I should see project hook' do
|
2015-06-12 00:44:13 -04:00
|
|
|
expect(page).to have_content @hook.url
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|
|
|
|
|
2014-07-27 16:26:23 -04:00
|
|
|
step 'I submit new hook' do
|
2015-05-20 19:22:00 -04:00
|
|
|
@url = FFaker::Internet.uri("http")
|
2012-09-27 16:52:08 -04:00
|
|
|
fill_in "hook_url", with: @url
|
2016-03-10 14:48:29 -05:00
|
|
|
expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1)
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|
|
|
|
|
2015-08-11 02:59:40 -04:00
|
|
|
step 'I submit new hook with SSL verification enabled' do
|
|
|
|
@url = FFaker::Internet.uri("http")
|
|
|
|
fill_in "hook_url", with: @url
|
|
|
|
check "hook_enable_ssl_verification"
|
2016-03-10 14:48:29 -05:00
|
|
|
expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1)
|
2015-08-11 02:59:40 -04:00
|
|
|
end
|
|
|
|
|
2014-07-27 16:26:23 -04:00
|
|
|
step 'I should see newly created hook' do
|
2015-06-12 00:44:13 -04:00
|
|
|
expect(current_path).to eq namespace_project_hooks_path(current_project.namespace, current_project)
|
|
|
|
expect(page).to have_content(@url)
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|
|
|
|
|
2015-08-11 02:59:40 -04:00
|
|
|
step 'I should see newly created hook with SSL verification enabled' do
|
|
|
|
expect(current_path).to eq namespace_project_hooks_path(current_project.namespace, current_project)
|
|
|
|
expect(page).to have_content(@url)
|
|
|
|
expect(page).to have_content("SSL Verification: enabled")
|
|
|
|
end
|
|
|
|
|
2014-07-27 16:26:23 -04:00
|
|
|
step 'I click test hook button' do
|
2014-01-15 09:38:48 -05:00
|
|
|
stub_request(:post, @hook.url).to_return(status: 200)
|
2016-04-26 09:14:34 -04:00
|
|
|
click_link 'Test'
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|
|
|
|
|
2014-07-29 05:49:46 -04:00
|
|
|
step 'I click test hook button with invalid URL' do
|
|
|
|
stub_request(:post, @hook.url).to_raise(SocketError)
|
2016-04-26 09:14:34 -04:00
|
|
|
click_link 'Test'
|
2014-07-29 05:49:46 -04:00
|
|
|
end
|
|
|
|
|
2014-07-27 16:26:23 -04:00
|
|
|
step 'hook should be triggered' do
|
2015-06-12 00:44:13 -04:00
|
|
|
expect(current_path).to eq namespace_project_hooks_path(current_project.namespace, current_project)
|
|
|
|
expect(page).to have_selector '.flash-notice',
|
2016-05-09 07:58:43 -04:00
|
|
|
text: 'Hook executed successfully: HTTP 200'
|
2014-07-27 16:26:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
step 'I should see hook error message' do
|
2015-06-12 00:44:13 -04:00
|
|
|
expect(page).to have_selector '.flash-alert',
|
2014-07-27 16:26:23 -04:00
|
|
|
text: 'Hook execution failed. '\
|
|
|
|
'Ensure the project has commits.'
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|
2014-07-29 05:49:46 -04:00
|
|
|
|
|
|
|
step 'I should see hook service down error message' do
|
2015-06-12 00:44:13 -04:00
|
|
|
expect(page).to have_selector '.flash-alert',
|
2015-12-01 19:45:40 -05:00
|
|
|
text: 'Hook execution failed: Exception from'
|
2014-07-29 05:49:46 -04:00
|
|
|
end
|
2012-09-27 16:52:08 -04:00
|
|
|
end
|