diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/controllers/import | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/controllers/import')
-rw-r--r-- | spec/controllers/import/bulk_imports_controller_spec.rb | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb index 08a54f112bb..b450318f6f7 100644 --- a/spec/controllers/import/bulk_imports_controller_spec.rb +++ b/spec/controllers/import/bulk_imports_controller_spec.rb @@ -123,7 +123,7 @@ RSpec.describe Import::BulkImportsController do it 'denies network request' do get :status - expect(controller).to redirect_to(new_group_path) + expect(controller).to redirect_to(new_group_path(anchor: 'import-group-pane')) expect(flash[:alert]).to eq('Specified URL cannot be used: "Only allowed schemes are http, https"') end end @@ -184,9 +184,15 @@ RSpec.describe Import::BulkImportsController do end describe 'POST create' do - let(:instance_url) { "http://fake-intance" } + let(:instance_url) { "http://fake-instance" } let(:bulk_import) { create(:bulk_import) } let(:pat) { "fake-pat" } + let(:bulk_import_params) do + [{ "source_type" => "group_entity", + "source_full_path" => "full_path", + "destination_name" => "destination_name", + "destination_namespace" => "root" }] + end before do session[:bulk_import_gitlab_access_token] = pat @@ -194,15 +200,9 @@ RSpec.describe Import::BulkImportsController do end it 'executes BulkImportService' do - bulk_import_params = [{ "source_type" => "group_entity", - "source_full_path" => "full_path", - "destination_name" => - "destination_name", - "destination_namespace" => "root" }] - expect_next_instance_of( BulkImportService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service| - allow(service).to receive(:execute).and_return(bulk_import) + allow(service).to receive(:execute).and_return(ServiceResponse.success(payload: bulk_import)) end post :create, params: { bulk_import: bulk_import_params } @@ -210,6 +210,19 @@ RSpec.describe Import::BulkImportsController do expect(response).to have_gitlab_http_status(:ok) expect(response.body).to eq({ id: bulk_import.id }.to_json) end + + it 'returns error when validation fails' do + error_response = ServiceResponse.error(message: 'Record invalid', http_status: :unprocessable_entity) + expect_next_instance_of( + BulkImportService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service| + allow(service).to receive(:execute).and_return(error_response) + end + + post :create, params: { bulk_import: bulk_import_params } + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(response.body).to eq({ error: 'Record invalid' }.to_json) + end end end |