Commit d71d8ad7 authored by Alexis Reigel's avatar Alexis Reigel Committed by Alexis Reigel

test hook for system merge request hook

parent b22ae0c0
...@@ -13,5 +13,12 @@ module TestHooks ...@@ -13,5 +13,12 @@ module TestHooks
def repository_update_events_data def repository_update_events_data
Gitlab::DataBuilder::Repository.sample_data Gitlab::DataBuilder::Repository.sample_data
end end
def merge_requests_events_data
merge_request = MergeRequest.of_projects(current_user.projects.select(:id)).first
throw(:validation_error, 'Ensure one of your projects has merge requests.') unless merge_request.present?
merge_request.to_hook_data(current_user)
end
end end
end end
...@@ -60,5 +60,25 @@ describe TestHooks::SystemService do ...@@ -60,5 +60,25 @@ describe TestHooks::SystemService do
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
end end
context 'merge_requests_events' do
let(:trigger) { 'merge_requests_events' }
it 'returns error message if the user does not have any repository with a merge request' do
expect(hook).not_to receive(:execute)
expect(service.execute).to include({ status: :error, message: 'Ensure one of your projects has merge requests.' })
end
it 'executes hook' do
trigger_key = :merge_request_hooks
sample_data = { data: 'sample' }
create(:project_member, user: current_user, project: project)
create(:merge_request, source_project: project)
allow_any_instance_of(MergeRequest).to receive(:to_hook_data).and_return(sample_data)
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end 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