diff options
Diffstat (limited to 'spec/lib/gitlab/github_import/representation')
11 files changed, 172 insertions, 30 deletions
diff --git a/spec/lib/gitlab/github_import/representation/diff_notes/suggestion_formatter_spec.rb b/spec/lib/gitlab/github_import/representation/diff_notes/suggestion_formatter_spec.rb index bcb8575bdbf..5a24f929388 100644 --- a/spec/lib/gitlab/github_import/representation/diff_notes/suggestion_formatter_spec.rb +++ b/spec/lib/gitlab/github_import/representation/diff_notes/suggestion_formatter_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::DiffNotes::SuggestionFormatter do it 'does nothing when there is any text before the suggestion tag' do diff --git a/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb b/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb index d40be0e841c..43f0198704f 100644 --- a/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb +++ b/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb @@ -1,21 +1,41 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::ExposeAttribute do - it 'defines a getter method that returns an attribute value' do - klass = Class.new do + let(:klass) do + Class.new do include Gitlab::GithubImport::Representation::ExposeAttribute expose_attribute :number attr_reader :attributes - def initialize - @attributes = { number: 42 } + def initialize(attributes) + @attributes = attributes + end + end + end + + it 'defines a getter method that returns an attribute value' do + expect(klass.new({ number: 42 }).number).to eq(42) + end + + describe '#[]' do + it 'returns exposed attributes value using array notation' do + expect(klass.new({ number: 42 })[:number]).to eq(42) + end + + context 'when attribute does not exist' do + it 'returns nil' do + expect(klass.new({})[:number]).to eq(nil) end end - expect(klass.new.number).to eq(42) + context 'when attribute is not exposed' do + it 'returns nil' do + expect(klass.new({ not_exposed_attribute: 42 })[:not_exposed_attribute]).to eq(nil) + end + end end end diff --git a/spec/lib/gitlab/github_import/representation/issue_event_spec.rb b/spec/lib/gitlab/github_import/representation/issue_event_spec.rb index d3a98035e73..0256858ecf1 100644 --- a/spec/lib/gitlab/github_import/representation/issue_event_spec.rb +++ b/spec/lib/gitlab/github_import/representation/issue_event_spec.rb @@ -43,7 +43,7 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:with_actor) { false } it 'does not return such info' do - expect(issue_event.actor).to eq nil + expect(issue_event.actor).to be_nil end end @@ -57,7 +57,7 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:with_label) { false } it 'does not return such info' do - expect(issue_event.label_title).to eq nil + expect(issue_event.label_title).to be_nil end end @@ -72,8 +72,8 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:with_rename) { false } it 'does not return such info' do - expect(issue_event.old_title).to eq nil - expect(issue_event.new_title).to eq nil + expect(issue_event.old_title).to be_nil + expect(issue_event.new_title).to be_nil end end @@ -87,30 +87,47 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:with_milestone) { false } it 'does not return such info' do - expect(issue_event.milestone_title).to eq nil + expect(issue_event.milestone_title).to be_nil end end - context 'when assignee and assigner data is present' do - it 'includes assignee and assigner details' do + context 'when assignee data is present' do + it 'includes assignee details' do expect(issue_event.assignee) .to be_an_instance_of(Gitlab::GithubImport::Representation::User) expect(issue_event.assignee.id).to eq(5) expect(issue_event.assignee.login).to eq('tom') + end + end + + context 'when assignee data is empty' do + let(:with_assignee) { false } - expect(issue_event.assigner) + it 'does not return such info' do + expect(issue_event.assignee).to be_nil + end + end + + context 'when requested_reviewer and review_requester data is present' do + it 'includes requested_reviewer and review_requester details' do + expect(issue_event.requested_reviewer) .to be_an_instance_of(Gitlab::GithubImport::Representation::User) - expect(issue_event.assigner.id).to eq(6) - expect(issue_event.assigner.login).to eq('jerry') + expect(issue_event.requested_reviewer.id).to eq(6) + expect(issue_event.requested_reviewer.login).to eq('mickey') + + expect(issue_event.review_requester) + .to be_an_instance_of(Gitlab::GithubImport::Representation::User) + expect(issue_event.review_requester.id).to eq(7) + expect(issue_event.review_requester.login).to eq('minnie') end end - context 'when assignee and assigner data is empty' do - let(:with_assignee) { false } + context 'when requested_reviewer and review_requester data is empty' do + let(:with_reviewer) { false } it 'does not return such info' do - expect(issue_event.assignee).to eq nil - expect(issue_event.assigner).to eq nil + expect(issue_event.requested_reviewer).to be_nil + expect(issue_event.review_requester).to be_nil end end @@ -148,7 +165,8 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:response) do event_resource = Struct.new( :id, :node_id, :url, :actor, :event, :commit_id, :commit_url, :label, :rename, :milestone, - :source, :assignee, :assigner, :issue, :created_at, :performed_via_github_app, + :source, :assignee, :requested_reviewer, :review_requester, :issue, :created_at, + :performed_via_github_app, keyword_init: true ) user_resource = Struct.new(:id, :login, keyword_init: true) @@ -166,7 +184,8 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do milestone: with_milestone ? { title: 'milestone title' } : nil, source: { type: 'issue', id: 123456 }, assignee: with_assignee ? user_resource.new(id: 5, login: 'tom') : nil, - assigner: with_assignee ? user_resource.new(id: 6, login: 'jerry') : nil, + requested_reviewer: with_reviewer ? user_resource.new(id: 6, login: 'mickey') : nil, + review_requester: with_reviewer ? user_resource.new(id: 7, login: 'minnie') : nil, issue: { 'number' => 2, 'pull_request' => pull_request }, created_at: '2022-04-26 18:30:53 UTC', performed_via_github_app: nil @@ -178,6 +197,7 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:with_rename) { true } let(:with_milestone) { true } let(:with_assignee) { true } + let(:with_reviewer) { true } let(:pull_request) { nil } it_behaves_like 'an IssueEvent' do @@ -203,7 +223,8 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do 'milestone_title' => (with_milestone ? 'milestone title' : nil), 'source' => { 'type' => 'issue', 'id' => 123456 }, 'assignee' => (with_assignee ? { 'id' => 5, 'login' => 'tom' } : nil), - 'assigner' => (with_assignee ? { 'id' => 6, 'login' => 'jerry' } : nil), + 'requested_reviewer' => (with_reviewer ? { 'id' => 6, 'login' => 'mickey' } : nil), + 'review_requester' => (with_reviewer ? { 'id' => 7, 'login' => 'minnie' } : nil), 'issue' => { 'number' => 2, 'pull_request' => pull_request }, 'created_at' => '2022-04-26 18:30:53 UTC', 'performed_via_github_app' => nil @@ -215,6 +236,7 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do let(:with_rename) { true } let(:with_milestone) { true } let(:with_assignee) { true } + let(:with_reviewer) { true } let(:pull_request) { nil } let(:issue_event) { described_class.from_json_hash(hash) } diff --git a/spec/lib/gitlab/github_import/representation/lfs_object_spec.rb b/spec/lib/gitlab/github_import/representation/lfs_object_spec.rb index b59ea513436..6663a7366a5 100644 --- a/spec/lib/gitlab/github_import/representation/lfs_object_spec.rb +++ b/spec/lib/gitlab/github_import/representation/lfs_object_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::LfsObject do describe '#github_identifiers' do diff --git a/spec/lib/gitlab/github_import/representation/note_spec.rb b/spec/lib/gitlab/github_import/representation/note_spec.rb index 97addcc1c98..9f416eb3c02 100644 --- a/spec/lib/gitlab/github_import/representation/note_spec.rb +++ b/spec/lib/gitlab/github_import/representation/note_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::Note do let(:created_at) { Time.new(2017, 1, 1, 12, 00) } diff --git a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb new file mode 100644 index 00000000000..e762dc469c1 --- /dev/null +++ b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do + shared_examples 'a ProtectedBranch rule' do + it 'returns an instance of ProtectedBranch' do + expect(protected_branch).to be_an_instance_of(described_class) + end + + context 'with ProtectedBranch' do + it 'includes the protected branch ID (name)' do + expect(protected_branch.id).to eq 'main' + end + + it 'includes the protected branch allow_force_pushes' do + expect(protected_branch.allow_force_pushes).to eq true + end + end + end + + describe '.from_api_response' do + let(:response) do + response = Struct.new(:url, :allow_force_pushes, keyword_init: true) + allow_force_pushes = Struct.new(:enabled, keyword_init: true) + response.new( + url: 'https://example.com/branches/main/protection', + allow_force_pushes: allow_force_pushes.new( + enabled: true + ) + ) + end + + it_behaves_like 'a ProtectedBranch rule' do + let(:protected_branch) { described_class.from_api_response(response) } + end + end + + describe '.from_json_hash' do + it_behaves_like 'a ProtectedBranch rule' do + let(:hash) do + { + 'id' => 'main', + 'allow_force_pushes' => true + } + end + + let(:protected_branch) { described_class.from_json_hash(hash) } + end + end +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 f812fd85fbc..d6e7a8172f7 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 @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do let(:submitted_at) { Time.new(2017, 1, 1, 12, 00).utc } diff --git a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb index 925dba5b5a7..deb9535a845 100644 --- a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb +++ b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::PullRequest do let(:created_at) { Time.new(2017, 1, 1, 12, 00) } diff --git a/spec/lib/gitlab/github_import/representation/release_attachments_spec.rb b/spec/lib/gitlab/github_import/representation/release_attachments_spec.rb new file mode 100644 index 00000000000..0ef9dad6a13 --- /dev/null +++ b/spec/lib/gitlab/github_import/representation/release_attachments_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Representation::ReleaseAttachments do + shared_examples 'a Release attachments data' do + it 'returns an instance of ReleaseAttachments' do + expect(representation).to be_an_instance_of(described_class) + end + + it 'includes release DB id' do + expect(representation.release_db_id).to eq 42 + end + + it 'includes release description' do + expect(representation.description).to eq 'Some text here..' + end + end + + describe '.from_db_record' do + let(:release) { build_stubbed(:release, id: 42, description: 'Some text here..') } + + it_behaves_like 'a Release attachments data' do + let(:representation) { described_class.from_db_record(release) } + end + end + + describe '.from_json_hash' do + it_behaves_like 'a Release attachments data' do + let(:hash) do + { + 'release_db_id' => 42, + 'description' => 'Some text here..' + } + end + + let(:representation) { described_class.from_json_hash(hash) } + end + end + + describe '#github_identifiers' do + it 'returns a hash with needed identifiers' do + release_id = rand(100) + representation = described_class.new(release_db_id: release_id, description: 'text') + + expect(representation.github_identifiers).to eq({ db_id: release_id }) + end + end +end diff --git a/spec/lib/gitlab/github_import/representation/to_hash_spec.rb b/spec/lib/gitlab/github_import/representation/to_hash_spec.rb index 2770e5c5397..739c832025c 100644 --- a/spec/lib/gitlab/github_import/representation/to_hash_spec.rb +++ b/spec/lib/gitlab/github_import/representation/to_hash_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::ToHash do describe '#to_hash' do diff --git a/spec/lib/gitlab/github_import/representation/user_spec.rb b/spec/lib/gitlab/github_import/representation/user_spec.rb index 14204886e9b..d7219556ada 100644 --- a/spec/lib/gitlab/github_import/representation/user_spec.rb +++ b/spec/lib/gitlab/github_import/representation/user_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::User do shared_examples 'a User' do |