diff options
Diffstat (limited to 'spec/lib/gitlab/bitbucket_import/importers/issues_importer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/bitbucket_import/importers/issues_importer_spec.rb | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/spec/lib/gitlab/bitbucket_import/importers/issues_importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importers/issues_importer_spec.rb index a361a9343dd..af5a929683e 100644 --- a/spec/lib/gitlab/bitbucket_import/importers/issues_importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importers/issues_importer_spec.rb @@ -12,22 +12,37 @@ RSpec.describe Gitlab::BitbucketImport::Importers::IssuesImporter, feature_categ ) end + let(:client) { Bitbucket::Client.new(project.import_data.credentials) } + + before do + allow(Bitbucket::Client).to receive(:new).and_return(client) + allow(client).to receive(:repo).and_return(Bitbucket::Representation::Repo.new({ 'has_issues' => true })) + allow(client).to receive(:last_issue).and_return(Bitbucket::Representation::Issue.new({ 'id' => 2 })) + allow(client).to receive(:issues).and_return( + [ + Bitbucket::Representation::Issue.new({ 'id' => 1 }), + Bitbucket::Representation::Issue.new({ 'id' => 2 }) + ], + [] + ) + end + subject(:importer) { described_class.new(project) } describe '#execute', :clean_gitlab_redis_cache do - before do - allow_next_instance_of(Bitbucket::Client) do |client| - allow(client).to receive(:issues).and_return( - [ - Bitbucket::Representation::Issue.new({ 'id' => 1 }), - Bitbucket::Representation::Issue.new({ 'id' => 2 }) - ], - [] - ) + context 'when the repo does not have issue tracking enabled' do + before do + allow(client).to receive(:repo).and_return(Bitbucket::Representation::Repo.new({ 'has_issues' => false })) + end + + it 'does not import issues' do + expect(Gitlab::BitbucketImport::ImportIssueWorker).not_to receive(:perform_in) + + importer.execute end end - it 'imports each issue in parallel', :aggregate_failures do + it 'imports each issue in parallel' do expect(Gitlab::BitbucketImport::ImportIssueWorker).to receive(:perform_in).twice waiter = importer.execute @@ -38,11 +53,15 @@ RSpec.describe Gitlab::BitbucketImport::Importers::IssuesImporter, feature_categ .to match_array(%w[1 2]) end + it 'allocates internal ids' do + expect(Issue).to receive(:track_namespace_iid!).with(project.project_namespace, 2) + + importer.execute + end + context 'when the client raises an error' do before do - allow_next_instance_of(Bitbucket::Client) do |client| - allow(client).to receive(:issues).and_raise(StandardError) - end + allow(client).to receive(:issues).and_raise(StandardError) end it 'tracks the failure and does not fail' do @@ -57,7 +76,7 @@ RSpec.describe Gitlab::BitbucketImport::Importers::IssuesImporter, feature_categ Gitlab::Cache::Import::Caching.set_add(importer.already_enqueued_cache_key, 1) end - it 'does not schedule job for enqueued issues', :aggregate_failures do + it 'does not schedule job for enqueued issues' do expect(Gitlab::BitbucketImport::ImportIssueWorker).to receive(:perform_in).once waiter = importer.execute |