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/services/jira_import')
-rw-r--r--spec/services/jira_import/cloud_users_mapper_service_spec.rb19
-rw-r--r--spec/services/jira_import/server_users_mapper_service_spec.rb19
-rw-r--r--spec/services/jira_import/users_importer_spec.rb117
-rw-r--r--spec/services/jira_import/users_mapper_spec.rb43
4 files changed, 122 insertions, 76 deletions
diff --git a/spec/services/jira_import/cloud_users_mapper_service_spec.rb b/spec/services/jira_import/cloud_users_mapper_service_spec.rb
new file mode 100644
index 00000000000..591f80f3efc
--- /dev/null
+++ b/spec/services/jira_import/cloud_users_mapper_service_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe JiraImport::CloudUsersMapperService do
+ let(:start_at) { 7 }
+ let(:url) { "/rest/api/2/users?maxResults=50&startAt=#{start_at}" }
+ let(:jira_users) do
+ [
+ { 'accountId' => 'abcd', 'displayName' => 'user1' },
+ { 'accountId' => 'efg' },
+ { 'accountId' => 'hij', 'displayName' => 'user3', 'emailAddress' => 'user3@example.com' }
+ ]
+ end
+
+ describe '#execute' do
+ it_behaves_like 'mapping jira users'
+ end
+end
diff --git a/spec/services/jira_import/server_users_mapper_service_spec.rb b/spec/services/jira_import/server_users_mapper_service_spec.rb
new file mode 100644
index 00000000000..22cb0327cc5
--- /dev/null
+++ b/spec/services/jira_import/server_users_mapper_service_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe JiraImport::ServerUsersMapperService do
+ let(:start_at) { 7 }
+ let(:url) { "/rest/api/2/user/search?username=''&maxResults=50&startAt=#{start_at}" }
+ let(:jira_users) do
+ [
+ { 'key' => 'abcd', 'name' => 'user1' },
+ { 'key' => 'efg' },
+ { 'key' => 'hij', 'name' => 'user3', 'emailAddress' => 'user3@example.com' }
+ ]
+ end
+
+ describe '#execute' do
+ it_behaves_like 'mapping jira users'
+ end
+end
diff --git a/spec/services/jira_import/users_importer_spec.rb b/spec/services/jira_import/users_importer_spec.rb
index 64cdc70f612..efb303dab9f 100644
--- a/spec/services/jira_import/users_importer_spec.rb
+++ b/spec/services/jira_import/users_importer_spec.rb
@@ -14,6 +14,27 @@ RSpec.describe JiraImport::UsersImporter do
subject { importer.execute }
describe '#execute' do
+ let(:mapped_users) do
+ [
+ {
+ jira_account_id: 'acc1',
+ jira_display_name: 'user1',
+ jira_email: 'sample@jira.com',
+ gitlab_id: nil,
+ gitlab_username: nil,
+ gitlab_name: nil
+ },
+ {
+ jira_account_id: 'acc2',
+ jira_display_name: 'user2',
+ jira_email: nil,
+ gitlab_id: nil,
+ gitlab_username: nil,
+ gitlab_name: nil
+ }
+ ]
+ end
+
before do
stub_jira_service_test
project.add_maintainer(user)
@@ -25,53 +46,83 @@ RSpec.describe JiraImport::UsersImporter do
end
end
- context 'when Jira import is configured correctly' do
- let_it_be(:jira_service) { create(:jira_service, project: project, active: true) }
- let(:client) { double }
+ RSpec.shared_examples 'maps jira users to gitlab users' do
+ context 'when Jira import is configured correctly' do
+ let_it_be(:jira_service) { create(:jira_service, project: project, active: true) }
+ let(:client) { double }
- before do
- expect(importer).to receive(:client).and_return(client)
- end
-
- context 'when jira client raises an error' do
- it 'returns an error response' do
- expect(client).to receive(:get).and_raise(Timeout::Error)
-
- expect(subject.error?).to be_truthy
- expect(subject.message).to include('There was an error when communicating to Jira')
- end
- end
-
- context 'when jira client returns result' do
before do
- allow(client).to receive(:get).with('/rest/api/2/users?maxResults=50&startAt=7')
- .and_return(jira_users)
+ expect(importer).to receive(:client).at_least(1).and_return(client)
+ allow(client).to receive_message_chain(:ServerInfo, :all, :deploymentType).and_return(deployment_type)
end
- context 'when jira client returns an empty array' do
- let(:jira_users) { [] }
+ context 'when jira client raises an error' do
+ it 'returns an error response' do
+ expect(client).to receive(:get).and_raise(Timeout::Error)
- it 'retturns nil payload' do
- expect(subject.success?).to be_truthy
- expect(subject.payload).to be_nil
+ expect(subject.error?).to be_truthy
+ expect(subject.message).to include('There was an error when communicating to Jira')
end
end
- context 'when jira client returns an results' do
- let(:jira_users) { [{ 'name' => 'user1' }, { 'name' => 'user2' }] }
- let(:mapped_users) { [{ jira_display_name: 'user1', gitlab_id: 5 }] }
+ context 'when jira client returns result' do
+ context 'when jira client returns an empty array' do
+ let(:jira_users) { [] }
- before do
- expect(JiraImport::UsersMapper).to receive(:new).with(project, jira_users)
- .and_return(double(execute: mapped_users))
+ it 'retturns nil payload' do
+ expect(subject.success?).to be_truthy
+ expect(subject.payload).to be_empty
+ end
end
- it 'returns the mapped users' do
- expect(subject.success?).to be_truthy
- expect(subject.payload).to eq(mapped_users)
+ context 'when jira client returns an results' do
+ it 'returns the mapped users' do
+ expect(subject.success?).to be_truthy
+ expect(subject.payload).to eq(mapped_users)
+ end
end
end
end
end
+
+ context 'when Jira instance is of Server deployment type' do
+ let(:deployment_type) { 'Server' }
+ let(:url) { "/rest/api/2/user/search?username=''&maxResults=50&startAt=#{start_at}" }
+ let(:jira_users) do
+ [
+ { 'key' => 'acc1', 'name' => 'user1', 'emailAddress' => 'sample@jira.com' },
+ { 'key' => 'acc2', 'name' => 'user2' }
+ ]
+ end
+
+ before do
+ allow_next_instance_of(JiraImport::ServerUsersMapperService) do |instance|
+ allow(instance).to receive(:client).and_return(client)
+ allow(client).to receive(:get).with(url).and_return(jira_users)
+ end
+ end
+
+ it_behaves_like 'maps jira users to gitlab users'
+ end
+
+ context 'when Jira instance is of Cloud deploymet type' do
+ let(:deployment_type) { 'Cloud' }
+ let(:url) { "/rest/api/2/users?maxResults=50&startAt=#{start_at}" }
+ let(:jira_users) do
+ [
+ { 'accountId' => 'acc1', 'displayName' => 'user1', 'emailAddress' => 'sample@jira.com' },
+ { 'accountId' => 'acc2', 'displayName' => 'user2' }
+ ]
+ end
+
+ before do
+ allow_next_instance_of(JiraImport::CloudUsersMapperService) do |instance|
+ allow(instance).to receive(:client).and_return(client)
+ allow(client).to receive(:get).with(url).and_return(jira_users)
+ end
+ end
+
+ it_behaves_like 'maps jira users to gitlab users'
+ end
end
end
diff --git a/spec/services/jira_import/users_mapper_spec.rb b/spec/services/jira_import/users_mapper_spec.rb
deleted file mode 100644
index e5e8279a6fb..00000000000
--- a/spec/services/jira_import/users_mapper_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe JiraImport::UsersMapper do
- let_it_be(:project) { create(:project) }
-
- subject { described_class.new(project, jira_users).execute }
-
- describe '#execute' do
- context 'jira_users is nil' do
- let(:jira_users) { nil }
-
- it 'returns an empty array' do
- expect(subject).to be_empty
- end
- end
-
- context 'when jira_users is present' do
- let(:jira_users) do
- [
- { 'accountId' => 'abcd', 'displayName' => 'user1' },
- { 'accountId' => 'efg' },
- { 'accountId' => 'hij', 'displayName' => 'user3', 'emailAddress' => 'user3@example.com' }
- ]
- end
-
- # TODO: now we only create an array in a proper format
- # mapping is tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/219023
- let(:mapped_users) do
- [
- { jira_account_id: 'abcd', jira_display_name: 'user1', jira_email: nil, gitlab_id: nil, gitlab_username: nil, gitlab_name: nil },
- { jira_account_id: 'efg', jira_display_name: nil, jira_email: nil, gitlab_id: nil, gitlab_username: nil, gitlab_name: nil },
- { jira_account_id: 'hij', jira_display_name: 'user3', jira_email: 'user3@example.com', gitlab_id: nil, gitlab_username: nil, gitlab_name: nil }
- ]
- end
-
- it 'returns users mapped to Gitlab' do
- expect(subject).to eq(mapped_users)
- end
- end
- end
-end