diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/lib/gitlab/github_import | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import')
6 files changed, 95 insertions, 7 deletions
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb index 01d9edf0ba1..016f6e5377b 100644 --- a/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb @@ -8,13 +8,14 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle let(:project) { merge_request.project } let(:merged_at) { Time.new(2017, 1, 1, 12, 00).utc } let(:client_double) { double(user: double(id: 999, login: 'merger', email: 'merger@email.com')) } + let(:merger_user) { double(id: 999, login: 'merger') } let(:pull_request) do instance_double( Gitlab::GithubImport::Representation::PullRequest, iid: merge_request.iid, merged_at: merged_at, - merged_by: double(id: 999, login: 'merger') + merged_by: merger_user ) end @@ -48,4 +49,23 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle expect(last_note.author).to eq(project.creator) end end + + context 'when the merger user is not provided' do + let(:merger_user) { nil } + + it 'adds a note referencing the merger user' do + expect { subject.execute } + .to change(Note, :count).by(1) + .and not_change(merge_request, :updated_at) + + metrics = merge_request.metrics.reload + expect(metrics.merged_by).to be_nil + expect(metrics.merged_at).to eq(merged_at) + + last_note = merge_request.notes.last + expect(last_note.note).to eq("*Merged by: ghost at 2017-01-01 12:00:00 UTC*") + expect(last_note.created_at).to eq(merged_at) + expect(last_note.author).to eq(project.creator) + end + end end diff --git a/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb index fa8b5e6ccf0..a6da40f47f1 100644 --- a/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb @@ -167,6 +167,19 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestReviewImporter, :clean end end + context 'when the submitted_at is not provided' do + let(:review) { create_review(type: 'APPROVED', note: '', submitted_at: nil) } + + it 'creates a note for the review without the author information' do + expect { subject.execute }.to change(Note, :count).by(1) + + last_note = merge_request.notes.last + + expect(last_note.created_at) + .to be_within(1.second).of(merge_request.updated_at) + end + end + context 'when the review has a note text' do context 'when the review is "APPROVED"' do let(:review) { create_review(type: 'APPROVED') } @@ -215,13 +228,15 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestReviewImporter, :clean end end - def create_review(type:, note: 'note', author: { id: 999, login: 'author' }) + def create_review(type:, **extra) Gitlab::GithubImport::Representation::PullRequestReview.from_json_hash( - merge_request_id: merge_request.id, - review_type: type, - note: note, - submitted_at: submitted_at.to_s, - author: author + extra.reverse_merge( + author: { id: 999, login: 'author' }, + merge_request_id: merge_request.id, + review_type: type, + note: 'note', + submitted_at: submitted_at.to_s + ) ) end end diff --git a/spec/lib/gitlab/github_import/markdown_text_spec.rb b/spec/lib/gitlab/github_import/markdown_text_spec.rb index 22bf10f36d8..2d159580b5f 100644 --- a/spec/lib/gitlab/github_import/markdown_text_spec.rb +++ b/spec/lib/gitlab/github_import/markdown_text_spec.rb @@ -27,6 +27,13 @@ RSpec.describe Gitlab::GithubImport::MarkdownText do expect(text.to_s).to eq('Hello') end + it 'returns empty text when it receives nil' do + author = double(:author, login: nil) + text = described_class.new(nil, author, true) + + expect(text.to_s).to eq('') + end + it 'returns the text with an extra header when the author was not found' do author = double(:author, login: 'Alice') text = described_class.new('Hello', author) diff --git a/spec/lib/gitlab/github_import/object_counter_spec.rb b/spec/lib/gitlab/github_import/object_counter_spec.rb new file mode 100644 index 00000000000..668c11667b5 --- /dev/null +++ b/spec/lib/gitlab/github_import/object_counter_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::ObjectCounter, :clean_gitlab_redis_cache do + let_it_be(:project) { create(:project) } + + it 'validates the operation being incremented' do + expect { described_class.increment(project, :issue, :unknown) } + .to raise_error(ArgumentError, 'Operation must be fetched or imported') + end + + it 'increments the counter and saves the key to be listed in the summary later' do + expect(Gitlab::Metrics) + .to receive(:counter) + .twice + .with(:github_importer_fetched_issue, 'The number of fetched Github Issue') + .and_return(double(increment: true)) + + expect(Gitlab::Metrics) + .to receive(:counter) + .twice + .with(:github_importer_imported_issue, 'The number of imported Github Issue') + .and_return(double(increment: true)) + + described_class.increment(project, :issue, :fetched) + described_class.increment(project, :issue, :fetched) + described_class.increment(project, :issue, :imported) + described_class.increment(project, :issue, :imported) + + expect(described_class.summary(project)).to eq({ + 'fetched' => { 'issue' => 2 }, + 'imported' => { 'issue' => 2 } + }) + end +end diff --git a/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb b/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb index 1e31cd2f007..d56d4708385 100644 --- a/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb +++ b/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb @@ -11,6 +11,10 @@ RSpec.describe Gitlab::GithubImport::ParallelScheduling do Class end + def object_type + :dummy + end + def collection_method :issues end diff --git a/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb b/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb index f9763455468..cad9b13774e 100644 --- a/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb +++ b/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb @@ -68,5 +68,11 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do expect(review.author).to be_nil end + + it 'does not fail when submitted_at is blank' do + review = described_class.from_json_hash(hash.except('submitted_at')) + + expect(review.submitted_at).to be_nil + end end end |