Commit 57b914cc authored by Illya Klymov's avatar Illya Klymov

Add specs for invalid repos

parent 88b7e697
...@@ -82,7 +82,7 @@ class Import::BitbucketController < Import::BaseController ...@@ -82,7 +82,7 @@ class Import::BitbucketController < Import::BaseController
def importable_repos def importable_repos
already_added_projects_names = already_added_projects.map(&:import_source) already_added_projects_names = already_added_projects.map(&:import_source)
bitbucket_repos.reject { |repo| (already_added_projects_names.include? repo.full_name) || !repo.valid? } bitbucket_repos.reject { |repo| already_added_projects_names.include?(repo.full_name) || !repo.valid? }
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -57,6 +57,8 @@ RSpec.describe Import::BitbucketController do ...@@ -57,6 +57,8 @@ RSpec.describe Import::BitbucketController do
describe "GET status" do describe "GET status" do
before do before do
@repo = double(name: 'vim', slug: 'vim', owner: 'asd', full_name: 'asd/vim', clone_url: 'http://test.host/demo/url.git', 'valid?' => true) @repo = double(name: 'vim', slug: 'vim', owner: 'asd', full_name: 'asd/vim', clone_url: 'http://test.host/demo/url.git', 'valid?' => true)
@invalid_repo = double(name: 'mercurialrepo', slug: 'mercurialrepo', owner: 'asd', full_name: 'asd/mercurialrepo', clone_url: 'http://test.host/demo/mercurialrepo.git', 'valid?' => false)
assign_session_tokens assign_session_tokens
stub_feature_flags(new_import_ui: false) stub_feature_flags(new_import_ui: false)
end end
...@@ -73,6 +75,25 @@ RSpec.describe Import::BitbucketController do ...@@ -73,6 +75,25 @@ RSpec.describe Import::BitbucketController do
let(:client_repos_field) { :repos } let(:client_repos_field) { :repos }
end end
context 'with new_import_ui feature flag enabled' do
before do
stub_feature_flags(new_import_ui: true)
allow(controller).to receive(:provider_url).and_return('http://demobitbucket.org')
end
it 'returns invalid repos' do
allow_any_instance_of(Bitbucket::Client).to receive(:repos).and_return([@repo, @invalid_repo])
get :status, format: :json
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['incompatible_repos'].length).to eq(1)
expect(json_response.dig("incompatible_repos", 0, "id")).to eq(@invalid_repo.full_name)
expect(json_response['provider_repos'].length).to eq(1)
expect(json_response.dig("provider_repos", 0, "id")).to eq(@repo.full_name)
end
end
it "assigns variables" do it "assigns variables" do
@project = create(:project, import_type: 'bitbucket', creator_id: user.id) @project = create(:project, import_type: 'bitbucket', creator_id: user.id)
allow_any_instance_of(Bitbucket::Client).to receive(:repos).and_return([@repo]) allow_any_instance_of(Bitbucket::Client).to receive(:repos).and_return([@repo])
......
...@@ -142,12 +142,30 @@ RSpec.describe Import::BitbucketServerController do ...@@ -142,12 +142,30 @@ RSpec.describe Import::BitbucketServerController do
allow(controller).to receive(:client).and_return(client) allow(controller).to receive(:client).and_return(client)
@repo = double(slug: 'vim', project_key: 'asd', full_name: 'asd/vim', "valid?" => true, project_name: 'asd', browse_url: 'http://test', name: 'vim') @repo = double(slug: 'vim', project_key: 'asd', full_name: 'asd/vim', "valid?" => true, project_name: 'asd', browse_url: 'http://test', name: 'vim')
@invalid_repo = double(slug: 'invalid', project_key: 'foobar', full_name: 'asd/foobar', "valid?" => false, browse_url: 'http://bad-repo') @invalid_repo = double(slug: 'invalid', project_key: 'foobar', full_name: 'asd/foobar', "valid?" => false, browse_url: 'http://bad-repo', name: 'invalid')
@created_repo = double(slug: 'created', project_key: 'existing', full_name: 'group/created', "valid?" => true, browse_url: 'http://existing') @created_repo = double(slug: 'created', project_key: 'existing', full_name: 'group/created', "valid?" => true, browse_url: 'http://existing')
assign_session_tokens assign_session_tokens
stub_feature_flags(new_import_ui: false) stub_feature_flags(new_import_ui: false)
end end
context 'with new_import_ui feature flag enabled' do
before do
stub_feature_flags(new_import_ui: true)
end
it 'returns invalid repos' do
allow(client).to receive(:repos).with(filter: nil, limit: 25, page_offset: 0).and_return([@repo, @invalid_repo])
get :status, format: :json
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['incompatible_repos'].length).to eq(1)
expect(json_response.dig("incompatible_repos", 0, "id")).to eq(@invalid_repo.full_name)
expect(json_response['provider_repos'].length).to eq(1)
expect(json_response.dig("provider_repos", 0, "id")).to eq(@repo.full_name)
end
end
it_behaves_like 'import controller with new_import_ui feature flag' do it_behaves_like 'import controller with new_import_ui feature flag' do
let(:repo) { @repo } let(:repo) { @repo }
let(:repo_id) { @repo.full_name } let(:repo_id) { @repo.full_name }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment