summaryrefslogtreecommitdiff
path: root/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb')
-rw-r--r--spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb35
1 files changed, 34 insertions, 1 deletions
diff --git a/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb b/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb
index c4c19f2f9c5..cba6c578d11 100644
--- a/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb
+++ b/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb
@@ -2,13 +2,17 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category: :importer do
+RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, :clean_gitlab_redis_cache, feature_category: :importers do
subject(:worker) { described_class.new }
let_it_be(:user) { create(:user) }
describe '#perform', :aggregate_failures do
context 'when there are no remaining jobs' do
+ before do
+ allow(Gitlab::Cache::Import::Caching).to receive(:values_from_hash).and_return(nil)
+ end
+
it 'marks import status as finished' do
waiter = instance_double(Gitlab::JobWaiter, key: :key, jobs_remaining: 0)
expect(Gitlab::JobWaiter).to receive(:new).and_return(waiter)
@@ -19,6 +23,8 @@ RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category:
expect(Gitlab::GithubImport::Logger)
.to receive(:info)
.with(user_id: user.id, message: 'GitHub Gists import finished')
+ expect(Notify).not_to receive(:github_gists_import_errors_email)
+ expect(Gitlab::Cache::Import::Caching).to receive(:expire).and_call_original
worker.perform(user.id, waiter.key, waiter.jobs_remaining)
end
@@ -35,6 +41,33 @@ RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category:
worker.perform(user.id, waiter.key, waiter.jobs_remaining)
end
end
+
+ context 'when some gists were failed to import' do
+ let(:errors) { { '12345' => 'Snippet maximum file count exceeded.' } }
+ let(:waiter) { instance_double(Gitlab::JobWaiter, key: :key, jobs_remaining: 0) }
+ let(:mail_instance) { instance_double(ActionMailer::MessageDelivery, deliver_now: true) }
+
+ before do
+ allow(Gitlab::Cache::Import::Caching).to receive(:values_from_hash).and_return(errors)
+ allow(Gitlab::JobWaiter).to receive(:new).and_return(waiter)
+ allow(waiter).to receive(:wait).with(described_class::BLOCKING_WAIT_TIME)
+ end
+
+ it 'sends an email to user' do
+ expect_next_instance_of(Gitlab::GithubGistsImport::Status) do |status|
+ expect(status).to receive(:finish!)
+ end
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(user_id: user.id, message: 'GitHub Gists import finished')
+ expect(Notify).to receive(:github_gists_import_errors_email)
+ .with(user.id, errors).once.and_return(mail_instance)
+ expect(mail_instance).to receive(:deliver_now)
+ expect(Gitlab::Cache::Import::Caching).to receive(:expire).and_call_original
+
+ worker.perform(user.id, waiter.key, waiter.jobs_remaining)
+ end
+ end
end
describe '.sidekiq_retries_exhausted' do