Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/github_import/representation')
-rw-r--r--spec/lib/gitlab/github_import/representation/diff_note_spec.rb9
-rw-r--r--spec/lib/gitlab/github_import/representation/issue_event_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/representation/issue_spec.rb17
-rw-r--r--spec/lib/gitlab/github_import/representation/note_spec.rb11
-rw-r--r--spec/lib/gitlab/github_import/representation/note_text_spec.rb80
-rw-r--r--spec/lib/gitlab/github_import/representation/protected_branch_spec.rb38
-rw-r--r--spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb11
-rw-r--r--spec/lib/gitlab/github_import/representation/pull_request_spec.rb33
-rw-r--r--spec/lib/gitlab/github_import/representation/release_attachments_spec.rb49
-rw-r--r--spec/lib/gitlab/github_import/representation/user_spec.rb2
10 files changed, 147 insertions, 105 deletions
diff --git a/spec/lib/gitlab/github_import/representation/diff_note_spec.rb b/spec/lib/gitlab/github_import/representation/diff_note_spec.rb
index fe3040c102b..a656cd0d056 100644
--- a/spec/lib/gitlab/github_import/representation/diff_note_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/diff_note_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote, :clean_gitlab_red
let(:start_line) { nil }
let(:end_line) { 23 }
let(:note_body) { 'Hello world' }
- let(:user_data) { { 'id' => 4, 'login' => 'alice' } }
+ let(:user_data) { { id: 4, login: 'alice' } }
let(:side) { 'RIGHT' }
let(:created_at) { Time.new(2017, 1, 1, 12, 00) }
let(:updated_at) { Time.new(2017, 1, 1, 12, 15) }
@@ -275,15 +275,14 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote, :clean_gitlab_red
describe '.from_api_response' do
it_behaves_like 'a DiffNote representation' do
let(:response) do
- double(
- :response,
+ {
id: note_id,
html_url: 'https://github.com/foo/bar/pull/42',
path: 'README.md',
commit_id: '123abc',
original_commit_id: 'original123abc',
side: side,
- user: user_data && double(:user, user_data),
+ user: user_data,
diff_hunk: hunk,
body: note_body,
created_at: created_at,
@@ -291,7 +290,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote, :clean_gitlab_red
line: end_line,
start_line: start_line,
in_reply_to_id: in_reply_to_id
- )
+ }
end
subject(:note) { described_class.from_api_response(response) }
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 0256858ecf1..0dd281cb3b0 100644
--- a/spec/lib/gitlab/github_import/representation/issue_event_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/issue_event_spec.rb
@@ -186,7 +186,7 @@ RSpec.describe Gitlab::GithubImport::Representation::IssueEvent do
assignee: with_assignee ? user_resource.new(id: 5, login: 'tom') : 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 },
+ issue: { number: 2, pull_request: pull_request },
created_at: '2022-04-26 18:30:53 UTC',
performed_via_github_app: nil
)
diff --git a/spec/lib/gitlab/github_import/representation/issue_spec.rb b/spec/lib/gitlab/github_import/representation/issue_spec.rb
index 5898518343a..263ef8b1708 100644
--- a/spec/lib/gitlab/github_import/representation/issue_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/issue_spec.rb
@@ -74,20 +74,19 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do
describe '.from_api_response' do
let(:response) do
- double(
- :response,
+ {
number: 42,
title: 'My Issue',
body: 'This is my issue',
- milestone: double(:milestone, number: 4),
+ milestone: { number: 4 },
state: 'open',
- assignees: [double(:user, id: 4, login: 'alice')],
- labels: [double(:label, name: 'bug')],
- user: double(:user, id: 4, login: 'alice'),
+ assignees: [{ id: 4, login: 'alice' }],
+ labels: [{ name: 'bug' }],
+ user: { id: 4, login: 'alice' },
created_at: created_at,
updated_at: updated_at,
pull_request: false
- )
+ }
end
let(:additional_data) { { work_item_type_id: work_item_type_id } }
@@ -97,9 +96,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do
end
it 'does not set the user if the response did not include a user' do
- allow(response)
- .to receive(:user)
- .and_return(nil)
+ response[:user] = nil
issue = described_class.from_api_response(response, additional_data)
diff --git a/spec/lib/gitlab/github_import/representation/note_spec.rb b/spec/lib/gitlab/github_import/representation/note_spec.rb
index 9f416eb3c02..49126dbe9c5 100644
--- a/spec/lib/gitlab/github_import/representation/note_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/note_spec.rb
@@ -48,15 +48,14 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
describe '.from_api_response' do
let(:response) do
- double(
- :response,
+ {
html_url: 'https://github.com/foo/bar/issues/42',
- user: double(:user, id: 4, login: 'alice'),
+ user: { id: 4, login: 'alice' },
body: 'Hello world',
created_at: created_at,
updated_at: updated_at,
id: 1
- )
+ }
end
it_behaves_like 'a Note' do
@@ -64,9 +63,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
end
it 'does not set the user if the response did not include a user' do
- allow(response)
- .to receive(:user)
- .and_return(nil)
+ response[:user] = nil
note = described_class.from_api_response(response)
diff --git a/spec/lib/gitlab/github_import/representation/note_text_spec.rb b/spec/lib/gitlab/github_import/representation/note_text_spec.rb
new file mode 100644
index 00000000000..8b57c9a0373
--- /dev/null
+++ b/spec/lib/gitlab/github_import/representation/note_text_spec.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Representation::NoteText do
+ shared_examples 'a Note text data' do |match_record_type|
+ it 'returns an instance of NoteText' do
+ expect(representation).to be_an_instance_of(described_class)
+ end
+
+ it 'includes record DB id' do
+ expect(representation.record_db_id).to eq 42
+ end
+
+ it 'includes record type' do
+ expect(representation.record_type).to eq match_record_type
+ end
+
+ it 'includes note text' do
+ expect(representation.text).to eq 'Some text here..'
+ end
+ end
+
+ describe '.from_db_record' do
+ context 'with Release' do
+ let(:record) { build_stubbed(:release, id: 42, description: 'Some text here..') }
+
+ it_behaves_like 'a Note text data', 'Release' do
+ let(:representation) { described_class.from_db_record(record) }
+ end
+ end
+
+ context 'with Issue' do
+ let(:record) { build_stubbed(:issue, id: 42, description: 'Some text here..') }
+
+ it_behaves_like 'a Note text data', 'Issue' do
+ let(:representation) { described_class.from_db_record(record) }
+ end
+ end
+
+ context 'with MergeRequest' do
+ let(:record) { build_stubbed(:merge_request, id: 42, description: 'Some text here..') }
+
+ it_behaves_like 'a Note text data', 'MergeRequest' do
+ let(:representation) { described_class.from_db_record(record) }
+ end
+ end
+
+ context 'with Note' do
+ let(:record) { build_stubbed(:note, id: 42, note: 'Some text here..') }
+
+ it_behaves_like 'a Note text data', 'Note' do
+ let(:representation) { described_class.from_db_record(record) }
+ end
+ end
+ end
+
+ describe '.from_json_hash' do
+ it_behaves_like 'a Note text data', 'Release' do
+ let(:hash) do
+ {
+ 'record_db_id' => 42,
+ 'record_type' => 'Release',
+ 'text' => '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
+ record_id = rand(100)
+ representation = described_class.new(record_db_id: record_id, text: 'text')
+
+ expect(representation.github_identifiers).to eq({ db_id: record_id })
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
index e762dc469c1..30b29659eee 100644
--- a/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/protected_branch_spec.rb
@@ -9,24 +9,47 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
end
context 'with ProtectedBranch' do
- it 'includes the protected branch ID (name)' do
+ it 'includes the protected branch ID (name) attribute' do
expect(protected_branch.id).to eq 'main'
end
- it 'includes the protected branch allow_force_pushes' do
+ it 'includes the protected branch allow_force_pushes attribute' do
expect(protected_branch.allow_force_pushes).to eq true
end
+
+ it 'includes the protected branch required_conversation_resolution attribute' do
+ expect(protected_branch.required_conversation_resolution).to eq true
+ end
+
+ it 'includes the protected branch required_pull_request_reviews' do
+ expect(protected_branch.required_pull_request_reviews).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 = Struct.new(
+ :url, :allow_force_pushes, :required_conversation_resolution, :required_signatures,
+ :required_pull_request_reviews,
+ keyword_init: true
+ )
+ enabled_setting = Struct.new(:enabled, keyword_init: true)
+ required_pull_request_reviews = Struct.new(:url, :dismissal_restrictions, keyword_init: true)
response.new(
url: 'https://example.com/branches/main/protection',
- allow_force_pushes: allow_force_pushes.new(
+ allow_force_pushes: enabled_setting.new(
+ enabled: true
+ ),
+ required_conversation_resolution: enabled_setting.new(
+ enabled: true
+ ),
+ required_signatures: enabled_setting.new(
enabled: true
+ ),
+ required_pull_request_reviews: required_pull_request_reviews.new(
+ url: 'https://example.com/branches/main/protection/required_pull_request_reviews',
+ dismissal_restrictions: {}
)
)
end
@@ -41,7 +64,10 @@ RSpec.describe Gitlab::GithubImport::Representation::ProtectedBranch do
let(:hash) do
{
'id' => 'main',
- 'allow_force_pushes' => true
+ 'allow_force_pushes' => true,
+ 'required_conversation_resolution' => true,
+ 'required_signatures' => true,
+ 'required_pull_request_reviews' => true
}
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 d6e7a8172f7..0203da9f4fb 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
@@ -21,15 +21,14 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
describe '.from_api_response' do
let(:response) do
- double(
- :response,
+ {
id: 999,
merge_request_id: 42,
body: 'note',
state: 'APPROVED',
- user: double(:user, id: 4, login: 'alice'),
+ user: { id: 4, login: 'alice' },
submitted_at: submitted_at
- )
+ }
end
it_behaves_like 'a PullRequest review' do
@@ -37,9 +36,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
end
it 'does not set the user if the response did not include a user' do
- allow(response)
- .to receive(:user)
- .and_return(nil)
+ response[:user] = nil
review = described_class.from_api_response(response)
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 deb9535a845..b8c1c67e07c 100644
--- a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb
@@ -93,33 +93,30 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequest do
describe '.from_api_response' do
let(:response) do
- double(
- :response,
+ {
number: 42,
title: 'My Pull Request',
body: 'This is my pull request',
state: 'closed',
- head: double(
- :head,
+ head: {
sha: '123abc',
ref: 'my-feature',
- repo: double(:repo, id: 400),
- user: double(:user, id: 4, login: 'alice')
- ),
- base: double(
- :base,
+ repo: { id: 400 },
+ user: { id: 4, login: 'alice' }
+ },
+ base: {
sha: '456def',
ref: 'master',
- repo: double(:repo, id: 200)
- ),
- milestone: double(:milestone, number: 4),
- user: double(:user, id: 4, login: 'alice'),
- assignee: double(:user, id: 4, login: 'alice'),
- merged_by: double(:user, id: 4, login: 'alice'),
+ repo: { id: 200 }
+ },
+ milestone: { number: 4 },
+ user: { id: 4, login: 'alice' },
+ assignee: { id: 4, login: 'alice' },
+ merged_by: { id: 4, login: 'alice' },
created_at: created_at,
updated_at: updated_at,
merged_at: merged_at
- )
+ }
end
it_behaves_like 'a PullRequest' do
@@ -127,9 +124,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequest do
end
it 'does not set the user if the response did not include a user' do
- allow(response)
- .to receive(:user)
- .and_return(nil)
+ response[:user] = nil
pr = described_class.from_api_response(response)
diff --git a/spec/lib/gitlab/github_import/representation/release_attachments_spec.rb b/spec/lib/gitlab/github_import/representation/release_attachments_spec.rb
deleted file mode 100644
index 0ef9dad6a13..00000000000
--- a/spec/lib/gitlab/github_import/representation/release_attachments_spec.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# 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/user_spec.rb b/spec/lib/gitlab/github_import/representation/user_spec.rb
index d7219556ada..ccada558f8b 100644
--- a/spec/lib/gitlab/github_import/representation/user_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/user_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe Gitlab::GithubImport::Representation::User do
describe '.from_api_response' do
it_behaves_like 'a User' do
- let(:response) { double(:response, id: 42, login: 'alice') }
+ let(:response) { { id: 42, login: 'alice' } }
let(:user) { described_class.from_api_response(response) }
end
end