diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-07 14:29:12 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-09-07 18:40:32 +0300 |
commit | 9e2015752848c908d99a26daf3c0e6e968b95f68 (patch) | |
tree | b41f1e781d346867a8198cc139de73c50ec77049 /spec/services/test_hooks | |
parent | d2cafa894a9e15e3f8827029ead064543d2a3b19 (diff) |
Fix a wrong `X-Gitlab-Event` header when testing webhooks
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/services/test_hooks')
-rw-r--r-- | spec/services/test_hooks/project_service_spec.rb | 27 | ||||
-rw-r--r-- | spec/services/test_hooks/system_service_spec.rb | 9 |
2 files changed, 24 insertions, 12 deletions
diff --git a/spec/services/test_hooks/project_service_spec.rb b/spec/services/test_hooks/project_service_spec.rb index 4218c15a3ce..28dfa9cf59c 100644 --- a/spec/services/test_hooks/project_service_spec.rb +++ b/spec/services/test_hooks/project_service_spec.rb @@ -21,6 +21,7 @@ describe TestHooks::ProjectService do context 'push_events' do let(:trigger) { 'push_events' } + let(:trigger_key) { :push_hooks } it 'returns error message if not enough data' do allow(project).to receive(:empty_repo?).and_return(true) @@ -33,13 +34,14 @@ describe TestHooks::ProjectService do allow(project).to receive(:empty_repo?).and_return(false) allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'tag_push_events' do let(:trigger) { 'tag_push_events' } + let(:trigger_key) { :tag_push_hooks } it 'returns error message if not enough data' do allow(project).to receive(:empty_repo?).and_return(true) @@ -52,13 +54,14 @@ describe TestHooks::ProjectService do allow(project).to receive(:empty_repo?).and_return(false) allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'note_events' do let(:trigger) { 'note_events' } + let(:trigger_key) { :note_hooks } it 'returns error message if not enough data' do expect(hook).not_to receive(:execute) @@ -69,13 +72,14 @@ describe TestHooks::ProjectService do allow(project).to receive(:notes).and_return([Note.new]) allow(Gitlab::DataBuilder::Note).to receive(:build).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'issues_events' do let(:trigger) { 'issues_events' } + let(:trigger_key) { :issue_hooks } let(:issue) { build(:issue) } it 'returns error message if not enough data' do @@ -87,13 +91,14 @@ describe TestHooks::ProjectService do allow(project).to receive(:issues).and_return([issue]) allow(issue).to receive(:to_hook_data).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'confidential_issues_events' do let(:trigger) { 'confidential_issues_events' } + let(:trigger_key) { :confidential_issue_hooks } let(:issue) { build(:issue) } it 'returns error message if not enough data' do @@ -105,13 +110,14 @@ describe TestHooks::ProjectService do allow(project).to receive(:issues).and_return([issue]) allow(issue).to receive(:to_hook_data).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'merge_requests_events' do let(:trigger) { 'merge_requests_events' } + let(:trigger_key) { :merge_request_hooks } it 'returns error message if not enough data' do expect(hook).not_to receive(:execute) @@ -122,13 +128,14 @@ describe TestHooks::ProjectService do 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).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'job_events' do let(:trigger) { 'job_events' } + let(:trigger_key) { :job_hooks } it 'returns error message if not enough data' do expect(hook).not_to receive(:execute) @@ -139,13 +146,14 @@ describe TestHooks::ProjectService do create(:ci_build, project: project) allow(Gitlab::DataBuilder::Build).to receive(:build).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'pipeline_events' do let(:trigger) { 'pipeline_events' } + let(:trigger_key) { :pipeline_hooks } it 'returns error message if not enough data' do expect(hook).not_to receive(:execute) @@ -156,13 +164,14 @@ describe TestHooks::ProjectService do create(:ci_empty_pipeline, project: project) allow(Gitlab::DataBuilder::Pipeline).to receive(:build).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'wiki_page_events' do let(:trigger) { 'wiki_page_events' } + let(:trigger_key) { :wiki_page_hooks } it 'returns error message if wiki disabled' do allow(project).to receive(:wiki_enabled?).and_return(false) @@ -180,7 +189,7 @@ describe TestHooks::ProjectService do create(:wiki_page, wiki: project.wiki) allow(Gitlab::DataBuilder::WikiPage).to receive(:build).and_return(sample_data) - expect(hook).to receive(:execute).with(sample_data, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end diff --git a/spec/services/test_hooks/system_service_spec.rb b/spec/services/test_hooks/system_service_spec.rb index a15708bf82f..ff8b9595538 100644 --- a/spec/services/test_hooks/system_service_spec.rb +++ b/spec/services/test_hooks/system_service_spec.rb @@ -24,36 +24,39 @@ describe TestHooks::SystemService do context 'push_events' do let(:trigger) { 'push_events' } + let(:trigger_key) { :push_hooks } it 'executes hook' do allow(project).to receive(:empty_repo?).and_return(false) expect(Gitlab::DataBuilder::Push).to receive(:sample_data).and_call_original - expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'tag_push_events' do let(:trigger) { 'tag_push_events' } + let(:trigger_key) { :tag_push_hooks } it 'executes hook' do allow(project.repository).to receive(:tags).and_return(['tag']) expect(Gitlab::DataBuilder::Push).to receive(:sample_data).and_call_original - expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end context 'repository_update_events' do let(:trigger) { 'repository_update_events' } + let(:trigger_key) { :repository_update_hooks } it 'executes hook' do allow(project).to receive(:empty_repo?).and_return(false) expect(Gitlab::DataBuilder::Repository).to receive(:sample_data).and_call_original - expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Repository::SAMPLE_DATA, trigger).and_return(success_result) + expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Repository::SAMPLE_DATA, trigger_key).and_return(success_result) expect(service.execute).to include(success_result) end end |