diff options
Diffstat (limited to 'spec/workers/gitlab')
4 files changed, 38 insertions, 4 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 diff --git a/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb b/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb index dfc5084bb10..1c24cdcccae 100644 --- a/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb +++ b/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::ImportGistWorker, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::ImportGistWorker, feature_category: :importers do subject { described_class.new } let_it_be(:user) { create(:user) } diff --git a/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb b/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb index 523b7463a9d..220f2bb0c75 100644 --- a/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb +++ b/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::StartImportWorker, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::StartImportWorker, feature_category: :importers do subject(:worker) { described_class.new } let_it_be(:user) { create(:user) } diff --git a/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb b/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb index 4a3ef2bf560..c2b8ee661a3 100644 --- a/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb @@ -14,7 +14,8 @@ RSpec.describe Gitlab::GithubImport::ImportProtectedBranchWorker do let(:json_hash) do { id: 'main', - allow_force_pushes: true + allow_force_pushes: true, + allowed_to_push_users: [] } end |