diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/lib/gitlab/github_import/importer | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import/importer')
-rw-r--r-- | spec/lib/gitlab/github_import/importer/issue_importer_spec.rb | 56 | ||||
-rw-r--r-- | spec/lib/gitlab/github_import/importer/releases_importer_spec.rb | 72 |
2 files changed, 111 insertions, 17 deletions
diff --git a/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb index 4287c32b947..2a06983417d 100644 --- a/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/issue_importer_spec.rb @@ -55,20 +55,54 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueImporter, :clean_gitlab_redi describe '#execute' do let(:importer) { described_class.new(issue, project, client) } - it 'creates the issue and assignees' do - expect(importer) - .to receive(:create_issue) - .and_return(10) + context 'when :issues_full_test_search is disabled' do + before do + stub_feature_flags(issues_full_text_search: false) + end + + it 'creates the issue and assignees but does not update search data' do + expect(importer) + .to receive(:create_issue) + .and_return(10) + + expect(importer) + .to receive(:create_assignees) + .with(10) + + expect(importer.issuable_finder) + .to receive(:cache_database_id) + .with(10) + + expect(importer).not_to receive(:update_search_data) + + importer.execute + end + end - expect(importer) - .to receive(:create_assignees) - .with(10) + context 'when :issues_full_text_search feature is enabled' do + before do + stub_feature_flags(issues_full_text_search: true) + end - expect(importer.issuable_finder) - .to receive(:cache_database_id) - .with(10) + it 'creates the issue and assignees and updates_search_data' do + expect(importer) + .to receive(:create_issue) + .and_return(10) + + expect(importer) + .to receive(:create_assignees) + .with(10) - importer.execute + expect(importer.issuable_finder) + .to receive(:cache_database_id) + .with(10) + + expect(importer) + .to receive(:update_search_data) + .with(10) + + importer.execute + end end end diff --git a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb index 6b3d18f20e9..b0f553dbef7 100644 --- a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb @@ -9,6 +9,12 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do let(:github_release_name) { 'Initial Release' } let(:created_at) { Time.new(2017, 1, 1, 12, 00) } let(:released_at) { Time.new(2017, 1, 1, 12, 00) } + let(:author) do + double( + login: 'User A', + id: 1 + ) + end let(:github_release) do double( @@ -17,11 +23,23 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do name: github_release_name, body: 'This is my release', created_at: created_at, - published_at: released_at + published_at: released_at, + author: author ) end + def stub_email_for_github_username(user_name = 'User A', user_email = 'user@example.com') + allow_next_instance_of(Gitlab::GithubImport::UserFinder) do |instance| + allow(instance).to receive(:email_for_github_username) + .with(user_name).and_return(user_email) + end + end + describe '#execute' do + before do + stub_email_for_github_username + end + it 'imports the releases in bulk' do release_hash = { tag_name: '1.0', @@ -45,7 +63,8 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do description: 'This is my release', created_at: created_at, updated_at: created_at, - published_at: nil + published_at: nil, + author: author ) expect(importer).to receive(:each_release).and_return([release_double]) @@ -61,6 +80,10 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do end describe '#build_releases' do + before do + stub_email_for_github_username + end + it 'returns an Array containing release rows' do expect(importer).to receive(:each_release).and_return([github_release]) @@ -108,11 +131,15 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do describe '#build' do let(:release_hash) { importer.build(github_release) } - it 'returns the attributes of the release as a Hash' do - expect(release_hash).to be_an_instance_of(Hash) - end - context 'the returned Hash' do + before do + stub_email_for_github_username + end + + it 'returns the attributes of the release as a Hash' do + expect(release_hash).to be_an_instance_of(Hash) + end + it 'includes the tag name' do expect(release_hash[:tag]).to eq('1.0') end @@ -137,6 +164,39 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do expect(release_hash[:name]).to eq(github_release_name) end end + + context 'author_id attribute' do + it 'returns the Gitlab user_id when Github release author is found' do + # Stub user email which matches a Gitlab user. + stub_email_for_github_username('User A', project.users.first.email) + + # Disable cache read as the redis cache key can be set by other specs. + # https://gitlab.com/gitlab-org/gitlab/-/blob/88bffda004e0aca9c4b9f2de86bdbcc0b49f2bc7/lib/gitlab/github_import/user_finder.rb#L75 + # Above line can return different user when read from cache. + allow(Gitlab::Cache::Import::Caching).to receive(:read).and_return(nil) + + expect(release_hash[:author_id]).to eq(project.users.first.id) + end + + it 'returns ghost user when author is empty in Github release' do + allow(github_release).to receive(:author).and_return(nil) + + expect(release_hash[:author_id]).to eq(Gitlab::GithubImport.ghost_user_id) + end + + context 'when Github author is not found in Gitlab' do + let(:author) { double(login: 'octocat', id: 1 ) } + + before do + # Stub user email which does not match a Gitlab user. + stub_email_for_github_username('octocat', 'octocat@example.com') + end + + it 'returns project creator as author' do + expect(release_hash[:author_id]).to eq(project.creator_id) + end + end + end end describe '#each_release' do |