diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/services/web_hooks/destroy_service_spec.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/services/web_hooks/destroy_service_spec.rb')
-rw-r--r-- | spec/services/web_hooks/destroy_service_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/services/web_hooks/destroy_service_spec.rb b/spec/services/web_hooks/destroy_service_spec.rb new file mode 100644 index 00000000000..fda40eb01e2 --- /dev/null +++ b/spec/services/web_hooks/destroy_service_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WebHooks::DestroyService do + let_it_be(:user) { create(:user) } + + subject { described_class.new(user) } + + shared_examples 'batched destroys' do + it 'destroys all hooks in batches' do + stub_const("#{described_class}::BATCH_SIZE", 1) + expect(subject).to receive(:delete_web_hook_logs_in_batches).exactly(4).times.and_call_original + + expect do + status = subject.execute(hook) + expect(status[:async]).to be false + end + .to change { WebHook.count }.from(1).to(0) + .and change { WebHookLog.count }.from(3).to(0) + end + + it 'returns an error if sync destroy fails' do + expect(hook).to receive(:destroy).and_return(false) + + result = subject.sync_destroy(hook) + + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq("Unable to destroy #{hook.model_name.human}") + end + + it 'schedules an async delete' do + stub_const('WebHooks::DestroyService::LOG_COUNT_THRESHOLD', 1) + + expect(WebHooks::DestroyWorker).to receive(:perform_async).with(user.id, hook.id).and_call_original + + status = subject.execute(hook) + + expect(status[:async]).to be true + end + end + + context 'with system hook' do + let_it_be(:hook) { create(:system_hook, url: "http://example.com") } + let_it_be(:log) { create_list(:web_hook_log, 3, web_hook: hook) } + + it_behaves_like 'batched destroys' + end + + context 'with project hook' do + let_it_be(:hook) { create(:project_hook) } + let_it_be(:log) { create_list(:web_hook_log, 3, web_hook: hook) } + + it_behaves_like 'batched destroys' + end +end |