Commit 3702fdde authored by Rémy Coutable's avatar Rémy Coutable

Fix Groups::HooksController#test implementation

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 80abdad6
class Groups::HooksController < Groups::ApplicationController
include HooksExecution
# Authorize
before_action :group
before_action :authorize_admin_group!
......@@ -27,13 +29,11 @@ class Groups::HooksController < Groups::ApplicationController
def test
if @group.first_non_empty_project
status, message = TestHookService.new.execute(hook, current_user)
service = TestHooks::ProjectService.new(hook, current_user, 'push_hooks')
service.project = @group.first_non_empty_project
result = service.execute
if status
flash[:notice] = 'Hook successfully executed.'
else
flash[:alert] = "Hook execution failed: #{message}"
end
set_hook_execution_notice(result)
else
flash[:alert] = 'Hook execution failed. Ensure the group has a project with commits.'
end
......
class TestHookService
def execute(hook, current_user)
data = Gitlab::DataBuilder::Push.build_sample(project(hook), current_user)
hook.execute(data, 'push_hooks')
end
private
def project(hook)
if hook.is_a? GroupHook
hook.group.first_non_empty_project
else
hook.project
end
end
end
......@@ -55,7 +55,7 @@ class Spinach::Features::GroupHooks < Spinach::FeatureSteps
step 'hook should be triggered' do
expect(current_path).to eq group_hooks_path(@group)
expect(page).to have_selector '.flash-notice',
text: 'Hook successfully executed.'
text: 'Hook executed successfully: HTTP 200'
end
step 'I should see hook error message' do
......
require 'spec_helper'
describe TestHookService, services: true do
let(:user) { create :user }
let(:group) { create :group }
let(:project) { create :project, :repository, group: group }
let(:project_hook) { create :project_hook, project: project }
let(:group_hook) { create :group_hook, group: group }
describe '#execute' do
it "successfully executes the project hook" do
stub_request(:post, project_hook.url).to_return(status: 200)
expect(TestHookService.new.execute(project_hook, user)).to be_truthy
end
it "successfully executes the group hook" do
project.reload
stub_request(:post, group_hook.url).to_return(status: 200)
expect(TestHookService.new.execute(group_hook, user)).to be_truthy
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment