diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/jira_import | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/jira_import')
7 files changed, 34 insertions, 97 deletions
diff --git a/spec/lib/gitlab/jira_import/base_importer_spec.rb b/spec/lib/gitlab/jira_import/base_importer_spec.rb index cda491393e8..1470bad2c4c 100644 --- a/spec/lib/gitlab/jira_import/base_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/base_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::JiraImport::BaseImporter do +RSpec.describe Gitlab::JiraImport::BaseImporter do include JiraServiceHelper let(:project) { create(:project) } diff --git a/spec/lib/gitlab/jira_import/handle_labels_service_spec.rb b/spec/lib/gitlab/jira_import/handle_labels_service_spec.rb index 0eeff180575..4e2c5afb077 100644 --- a/spec/lib/gitlab/jira_import/handle_labels_service_spec.rb +++ b/spec/lib/gitlab/jira_import/handle_labels_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::JiraImport::HandleLabelsService do +RSpec.describe Gitlab::JiraImport::HandleLabelsService do describe '#execute' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } diff --git a/spec/lib/gitlab/jira_import/issue_serializer_spec.rb b/spec/lib/gitlab/jira_import/issue_serializer_spec.rb index ce38a1234cf..4adc4e4d22a 100644 --- a/spec/lib/gitlab/jira_import/issue_serializer_spec.rb +++ b/spec/lib/gitlab/jira_import/issue_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::JiraImport::IssueSerializer do +RSpec.describe Gitlab::JiraImport::IssueSerializer do describe '#execute' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } @@ -10,6 +10,7 @@ describe Gitlab::JiraImport::IssueSerializer do let_it_be(:other_project_label) { create(:label, project: project, title: 'feature') } let_it_be(:group_label) { create(:group_label, group: group, title: 'dev') } let_it_be(:current_user) { create(:user) } + let_it_be(:user) { create(:user) } let(:iid) { 5 } let(:key) { 'PROJECT-5' } @@ -17,8 +18,8 @@ describe Gitlab::JiraImport::IssueSerializer do let(:description) { 'basic description' } let(:created_at) { '2020-01-01 20:00:00' } let(:updated_at) { '2020-01-10 20:00:00' } - let(:assignee) { double(attrs: { 'displayName' => 'Solver', 'emailAddress' => 'assignee@example.com' }) } - let(:reporter) { double(attrs: { 'displayName' => 'Reporter', 'emailAddress' => 'reporter@example.com' }) } + let(:assignee) { nil } + let(:reporter) { nil } let(:jira_status) { 'new' } let(:parent_field) do @@ -109,11 +110,12 @@ describe Gitlab::JiraImport::IssueSerializer do end context 'author' do - context 'when reporter maps to a valid GitLab user' do - let!(:user) { create(:user, email: 'reporter@example.com') } + let(:reporter) { double(attrs: { 'displayName' => 'Solver', 'accountId' => 'abcd' }) } + context 'when reporter maps to a valid GitLab user' do it 'sets the issue author to the mapped user' do - project.add_developer(user) + expect(Gitlab::JiraImport).to receive(:get_user_mapping).with(project.id, 'abcd') + .and_return(user.id) expect(subject[:author_id]).to eq(user.id) end @@ -121,6 +123,9 @@ describe Gitlab::JiraImport::IssueSerializer do context 'when reporter does not map to a valid Gitlab user' do it 'defaults the issue author to project creator' do + expect(Gitlab::JiraImport).to receive(:get_user_mapping).with(project.id, 'abcd') + .and_return(nil) + expect(subject[:author_id]).to eq(current_user.id) end end @@ -129,25 +134,30 @@ describe Gitlab::JiraImport::IssueSerializer do let(:reporter) { nil } it 'defaults the issue author to project creator' do + expect(Gitlab::JiraImport).not_to receive(:get_user_mapping) + expect(subject[:author_id]).to eq(current_user.id) end end - context 'when reporter field is missing email address' do + context 'when reporter field is missing accountId' do let(:reporter) { double(attrs: { 'displayName' => 'Reporter' }) } it 'defaults the issue author to project creator' do + expect(Gitlab::JiraImport).not_to receive(:get_user_mapping) + expect(subject[:author_id]).to eq(current_user.id) end end end context 'assignee' do - context 'when assignee maps to a valid GitLab user' do - let!(:user) { create(:user, email: 'assignee@example.com') } + let(:assignee) { double(attrs: { 'displayName' => 'Solver', 'accountId' => '1234' }) } + context 'when assignee maps to a valid GitLab user' do it 'sets the issue assignees to the mapped user' do - project.add_developer(user) + expect(Gitlab::JiraImport).to receive(:get_user_mapping).with(project.id, '1234') + .and_return(user.id) expect(subject[:assignee_ids]).to eq([user.id]) end @@ -155,6 +165,9 @@ describe Gitlab::JiraImport::IssueSerializer do context 'when assignee does not map to a valid GitLab user' do it 'leaves the assignee empty' do + expect(Gitlab::JiraImport).to receive(:get_user_mapping).with(project.id, '1234') + .and_return(nil) + expect(subject[:assignee_ids]).to be_nil end end @@ -163,14 +176,18 @@ describe Gitlab::JiraImport::IssueSerializer do let(:assignee) { nil } it 'leaves the assignee empty' do + expect(Gitlab::JiraImport).not_to receive(:get_user_mapping) + expect(subject[:assignee_ids]).to be_nil end end - context 'when assginee field is missing email address' do - let(:assignee) { double(attrs: { 'displayName' => 'Reporter' }) } + context 'when assginee field is missing accountId' do + let(:assignee) { double(attrs: { 'displayName' => 'Solver' }) } it 'leaves the assignee empty' do + expect(Gitlab::JiraImport).not_to receive(:get_user_mapping) + expect(subject[:assignee_ids]).to be_nil end end diff --git a/spec/lib/gitlab/jira_import/issues_importer_spec.rb b/spec/lib/gitlab/jira_import/issues_importer_spec.rb index 0d790f49450..4a32f0fd3a9 100644 --- a/spec/lib/gitlab/jira_import/issues_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/issues_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::JiraImport::IssuesImporter do +RSpec.describe Gitlab::JiraImport::IssuesImporter do include JiraServiceHelper let_it_be(:user) { create(:user) } diff --git a/spec/lib/gitlab/jira_import/labels_importer_spec.rb b/spec/lib/gitlab/jira_import/labels_importer_spec.rb index 19661ff4e73..db98a83cb3c 100644 --- a/spec/lib/gitlab/jira_import/labels_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/labels_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::JiraImport::LabelsImporter do +RSpec.describe Gitlab::JiraImport::LabelsImporter do include JiraServiceHelper let_it_be(:user) { create(:user) } diff --git a/spec/lib/gitlab/jira_import/metadata_collector_spec.rb b/spec/lib/gitlab/jira_import/metadata_collector_spec.rb index af479810df0..86863d67f25 100644 --- a/spec/lib/gitlab/jira_import/metadata_collector_spec.rb +++ b/spec/lib/gitlab/jira_import/metadata_collector_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::JiraImport::MetadataCollector do +RSpec.describe Gitlab::JiraImport::MetadataCollector do describe '#execute' do let(:key) { 'PROJECT-5' } let(:summary) { 'some title' } diff --git a/spec/lib/gitlab/jira_import/user_mapper_spec.rb b/spec/lib/gitlab/jira_import/user_mapper_spec.rb deleted file mode 100644 index c8c8bd3c5b0..00000000000 --- a/spec/lib/gitlab/jira_import/user_mapper_spec.rb +++ /dev/null @@ -1,80 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::JiraImport::UserMapper do - let_it_be(:group) { create(:group) } - let_it_be(:project) { create(:project, group: group) } - let_it_be(:user) { create(:user, email: 'user@example.com') } - let_it_be(:email) { create(:email, user: user, email: 'second_email@example.com', confirmed_at: nil) } - - let(:jira_user) { { 'acountId' => '1a2b', 'emailAddress' => 'user@example.com' } } - - describe '#execute' do - subject { described_class.new(project, jira_user).execute } - - context 'when jira_user is nil' do - let(:jira_user) { nil } - - it 'returns nil' do - expect(subject).to be_nil - end - end - - context 'when Gitlab user is not found by email' do - let(:jira_user) { { 'acountId' => '1a2b', 'emailAddress' => 'other@example.com' } } - - it 'returns nil' do - expect(subject).to be_nil - end - end - - context 'when jira_user emailAddress is nil' do - let(:jira_user) { { 'acountId' => '1a2b', 'emailAddress' => nil } } - - it 'returns nil' do - expect(subject).to be_nil - end - end - - context 'when jira_user emailAddress key is missing' do - let(:jira_user) { { 'acountId' => '1a2b' } } - - it 'returns nil' do - expect(subject).to be_nil - end - end - - context 'when found user is not a project member' do - it 'returns nil' do - expect(subject).to be_nil - end - end - - context 'when found user is a project member' do - it 'returns the found user' do - project.add_developer(user) - - expect(subject).to eq(user) - end - end - - context 'when user found by unconfirmd secondary address is a project member' do - let(:jira_user) { { 'acountId' => '1a2b', 'emailAddress' => 'second_email@example.com' } } - - it 'returns the found user' do - project.add_developer(user) - - expect(subject).to eq(user) - end - end - - context 'when user is a group member' do - it 'returns the found user' do - group.add_developer(user) - - expect(subject).to eq(user) - end - end - end -end |