2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe ProjectImportEntity, feature_category: :importers do
|
2019-07-07 11:18:12 +05:30
|
|
|
include ImportHelper
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
let_it_be(:project) { create(:project, import_status: :started, import_source: 'import_user/project') }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
let(:provider_url) { 'https://provider.com' }
|
2023-05-27 22:25:52 +05:30
|
|
|
let(:client) { nil }
|
|
|
|
let(:entity) { described_class.represent(project, provider_url: provider_url, client: client) }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
before do
|
|
|
|
create(:import_failure, project: project)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe '#as_json' do
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
it 'includes required fields' do
|
|
|
|
expect(subject[:import_source]).to eq(project.import_source)
|
|
|
|
expect(subject[:import_status]).to eq(project.import_status)
|
|
|
|
expect(subject[:human_import_status_name]).to eq(project.human_import_status_name)
|
|
|
|
expect(subject[:provider_link]).to eq(provider_project_link_url(provider_url, project[:import_source]))
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(subject[:import_error]).to eq(nil)
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(subject[:relation_type]).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when client option present', :clean_gitlab_redis_cache do
|
|
|
|
let(:octokit) { instance_double(Octokit::Client, access_token: 'stub') }
|
|
|
|
let(:client) do
|
|
|
|
instance_double(
|
|
|
|
::Gitlab::GithubImport::Clients::Proxy,
|
|
|
|
user: { login: 'import_user' }, octokit: octokit
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes relation_type' do
|
|
|
|
expect(subject[:relation_type]).to eq('owned')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with remove_legacy_github_client FF is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(remove_legacy_github_client: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't include relation_type" do
|
|
|
|
expect(subject[:relation_type]).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when import is failed' do
|
|
|
|
let!(:last_import_failure) { create(:import_failure, project: project, exception_message: 'LAST ERROR') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.import_state.fail_op!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes only the last import failure' do
|
|
|
|
expect(subject[:import_error]).to eq(last_import_failure.exception_message)
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|