diff options
Diffstat (limited to 'spec/controllers/import')
-rw-r--r-- | spec/controllers/import/bulk_imports_controller_spec.rb | 18 | ||||
-rw-r--r-- | spec/controllers/import/github_controller_spec.rb | 58 |
2 files changed, 70 insertions, 6 deletions
diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb index a0d5b576e74..a3992ae850e 100644 --- a/spec/controllers/import/bulk_imports_controller_spec.rb +++ b/spec/controllers/import/bulk_imports_controller_spec.rb @@ -9,14 +9,12 @@ RSpec.describe Import::BulkImportsController, feature_category: :importers do stub_application_setting(bulk_import_enabled: true) sign_in(user) + + allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(false) end context 'when user is signed in' do context 'when bulk_import feature flag is enabled' do - before do - stub_feature_flags(bulk_import: true) - end - describe 'POST configure' do before do allow_next_instance_of(BulkImports::Clients::HTTP) do |instance| @@ -400,6 +398,18 @@ RSpec.describe Import::BulkImportsController, feature_category: :importers do expect(response).to have_gitlab_http_status(:unprocessable_entity) end end + + context 'when request exceeds rate limits' do + it 'prevents user from starting a new migration' do + allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true) + + post :create, params: { bulk_import: {} } + + request + + expect(response).to have_gitlab_http_status(:too_many_requests) + end + end end end diff --git a/spec/controllers/import/github_controller_spec.rb b/spec/controllers/import/github_controller_spec.rb index c1a61a78d80..406a3604b23 100644 --- a/spec/controllers/import/github_controller_spec.rb +++ b/spec/controllers/import/github_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Import::GithubController, feature_category: :import do +RSpec.describe Import::GithubController, feature_category: :importers do include ImportSpecHelper let(:provider) { :github } @@ -375,7 +375,9 @@ RSpec.describe Import::GithubController, feature_category: :import do it_behaves_like 'a GitHub-ish import controller: GET realtime_changes' it 'includes stats in response' do - create(:project, import_type: provider, namespace: user.namespace, import_status: :finished, import_source: 'example/repo') + project = create(:project, import_type: provider, namespace: user.namespace, import_status: :finished, import_source: 'example/repo') + + ::Gitlab::GithubImport::ObjectCounter.increment(project, :issue, :imported, value: 8) get :realtime_changes @@ -417,4 +419,56 @@ RSpec.describe Import::GithubController, feature_category: :import do end end end + + describe 'POST cancel_all' do + context 'when import is in progress' do + it 'returns success' do + project = create(:project, :import_scheduled, namespace: user.namespace, import_type: 'github', import_url: 'https://fake.url') + project2 = create(:project, :import_started, namespace: user.namespace, import_type: 'github', import_url: 'https://fake2.url') + + expect(Import::Github::CancelProjectImportService) + .to receive(:new).with(project, user) + .and_return(double(execute: { status: :success, project: project })) + + expect(Import::Github::CancelProjectImportService) + .to receive(:new).with(project2, user) + .and_return(double(execute: { status: :bad_request, message: 'The import cannot be canceled because it is finished' })) + + post :cancel_all + + expect(json_response).to eq([ + { + 'id' => project.id, + 'status' => 'success' + }, + { + 'id' => project2.id, + 'status' => 'bad_request', + 'error' => 'The import cannot be canceled because it is finished' + } + ]) + end + end + + context 'when there is no imports in progress' do + it 'returns an empty array' do + create(:project, :import_finished, namespace: user.namespace, import_type: 'github', import_url: 'https://fake.url') + + post :cancel_all + + expect(json_response).to eq([]) + end + end + + context 'when there is no projects created by user' do + it 'returns an empty array' do + other_user_project = create(:project, :import_started, import_type: 'github', import_url: 'https://fake.url') + + post :cancel_all + + expect(json_response).to eq([]) + expect(other_user_project.import_status).to eq('started') + end + end + end end |