diff options
Diffstat (limited to 'spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb')
-rw-r--r-- | spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb index 582cb76a6cd..24fca3b7c73 100644 --- a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb @@ -19,18 +19,69 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do end context 'when the import succeeds' do - it 'schedules the importing of the base data' do - client = double(:client) + context 'with issues' do + it 'schedules the importing of the base data' do + client = double(:client) + options = { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } - expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| - expect(instance).to receive(:execute).and_return(true) + expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| + expect(instance).to receive(:execute).and_return(true) + end + + expect(InternalId).to receive(:exists?).and_return(false) + expect(client).to receive(:each_object).with( + :issues, project.import_source, options + ).and_return([{ number: 5 }].each) + + expect(Issue).to receive(:track_project_iid!).with(project, 5) + + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) + .to receive(:perform_async) + .with(project.id) + + worker.import(client, project) end + end - expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) - .to receive(:perform_async) - .with(project.id) + context 'without issues' do + it 'schedules the importing of the base data' do + client = double(:client) + options = { state: 'all', sort: 'number', direction: 'desc', per_page: '1' } + + expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| + expect(instance).to receive(:execute).and_return(true) + end + + expect(InternalId).to receive(:exists?).and_return(false) + expect(client).to receive(:each_object).with(:issues, project.import_source, options).and_return([nil].each) + expect(Issue).not_to receive(:track_project_iid!) - worker.import(client, project) + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) + .to receive(:perform_async) + .with(project.id) + + worker.import(client, project) + end + end + + context 'when retrying' do + it 'does not allocate internal ids' do + client = double(:client) + + expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| + expect(instance).to receive(:execute).and_return(true) + end + + expect(InternalId).to receive(:exists?).and_return(true) + expect(client).not_to receive(:each_object) + expect(Issue).not_to receive(:track_project_iid!) + + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) + .to receive(:perform_async) + .with(project.id) + + worker.import(client, project) + end end end @@ -43,6 +94,10 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do expect(instance).to receive(:execute).and_raise(exception_class) end + expect(InternalId).to receive(:exists?).and_return(false) + expect(client).to receive(:each_object).and_return([nil].each) + expect(Issue).not_to receive(:track_project_iid!) + expect(Gitlab::Import::ImportFailureService).to receive(:track) .with( project_id: project.id, |