diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-07 09:09:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-07 09:09:13 +0000 |
commit | 419f9c0ac3ae842964cc191932cab795463b259c (patch) | |
tree | 3441a3fb215f89997d0acc482fe5ae047d2ee3d7 /spec/workers | |
parent | b6724a211e047c35f3ba4c294997fba14bf42445 (diff) | |
download | gitlab-ce-419f9c0ac3ae842964cc191932cab795463b259c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/web_hooks/destroy_worker_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/workers/web_hooks/destroy_worker_spec.rb b/spec/workers/web_hooks/destroy_worker_spec.rb new file mode 100644 index 00000000000..fd26c8591ee --- /dev/null +++ b/spec/workers/web_hooks/destroy_worker_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WebHooks::DestroyWorker do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + before_all do + project.add_maintainer(user) + end + + subject { described_class.new } + + describe "#perform" do + context 'with a Web hook' do + let!(:hook) { create(:project_hook, project: project) } + let!(:other_hook) { create(:project_hook, project: project) } + let!(:log) { create(:web_hook_log, web_hook: hook) } + let!(:other_log) { create(:web_hook_log, web_hook: other_hook) } + + it "deletes the Web hook and logs", :aggregate_failures do + expect { subject.perform(user.id, hook.id) } + .to change { WebHookLog.count }.from(2).to(1) + .and change { WebHook.count }.from(2).to(1) + + expect(WebHook.find(other_hook.id)).to be_present + expect(WebHookLog.find(other_log.id)).to be_present + end + + it "raises and tracks an error if destroy failed" do + allow_next_instance_of(::WebHooks::DestroyService) do |instance| + expect(instance).to receive(:sync_destroy).with(anything).and_return({ status: :error, message: "failed" }) + end + + expect(Gitlab::ErrorTracking).to receive(:track_exception) + .with(an_instance_of(::WebHooks::DestroyService::DestroyError), web_hook_id: hook.id) + .and_call_original + expect { subject.perform(user.id, hook.id) }.to raise_error(::WebHooks::DestroyService::DestroyError) + end + + context 'with unknown hook' do + it 'does not raise an error' do + expect { subject.perform(user.id, non_existing_record_id) }.not_to raise_error + + expect(WebHook.count).to eq(2) + end + end + + context 'with unknown user' do + it 'does not raise an error' do + expect { subject.perform(non_existing_record_id, hook.id) }.not_to raise_error + + expect(WebHook.count).to eq(2) + end + end + end + end +end |