diff options
Diffstat (limited to 'spec/services/jira_import')
3 files changed, 84 insertions, 20 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 index 591f80f3efc..6b06a982a80 100644 --- a/spec/services/jira_import/cloud_users_mapper_service_spec.rb +++ b/spec/services/jira_import/cloud_users_mapper_service_spec.rb @@ -5,15 +5,44 @@ require 'spec_helper' RSpec.describe JiraImport::CloudUsersMapperService do let(:start_at) { 7 } let(:url) { "/rest/api/2/users?maxResults=50&startAt=#{start_at}" } + + let_it_be(:user_1) { create(:user, username: 'randomuser', name: 'USER-name1', email: 'uji@example.com') } + let_it_be(:user_2) { create(:user, username: 'username-2') } + let_it_be(:user_5) { create(:user, username: 'username-5') } + let_it_be(:user_4) { create(:user, email: 'user-4@example.com') } + let_it_be(:user_6) { create(:user, email: 'user-6@example.com') } + let_it_be(:user_7) { create(:user, username: 'username-7') } + let_it_be(:user_8) do + create(:user).tap { |user| create(:email, user: user, email: 'user8_email@example.com') } + end + + let_it_be(:current_user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let(:jira_users) do [ - { 'accountId' => 'abcd', 'displayName' => 'user1' }, - { 'accountId' => 'efg' }, - { 'accountId' => 'hij', 'displayName' => 'user3', 'emailAddress' => 'user3@example.com' } + { 'accountId' => 'abcd', 'displayName' => 'User-Name1' }, # matched by name + { 'accountId' => 'efg', 'displayName' => 'username-2' }, # matcher by username + { 'accountId' => 'hij' }, # no match + { 'accountId' => '123', 'displayName' => 'user-4', 'emailAddress' => 'user-4@example.com' }, # matched by email + { 'accountId' => '456', 'displayName' => 'username5foo', 'emailAddress' => 'user-5@example.com' }, # no match + { 'accountId' => '789', 'displayName' => 'user-6', 'emailAddress' => 'user-6@example.com' }, # matched by email, no project member + { 'accountId' => 'xyz', 'displayName' => 'username-7', 'emailAddress' => 'user-7@example.com' }, # matched by username, no project member + { 'accountId' => 'vhk', 'displayName' => 'user-8', 'emailAddress' => 'user8_email@example.com' }, # matched by secondary email + { 'accountId' => 'uji', 'displayName' => 'user-9', 'emailAddress' => 'uji@example.com' } # matched by email, same as user_1 ] end describe '#execute' do + before do + project.add_developer(current_user) + project.add_developer(user_1) + project.add_developer(user_2) + group.add_developer(user_4) + group.add_guest(user_8) + end + 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 index 22cb0327cc5..71cb8aea0be 100644 --- a/spec/services/jira_import/server_users_mapper_service_spec.rb +++ b/spec/services/jira_import/server_users_mapper_service_spec.rb @@ -5,15 +5,44 @@ 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_it_be(:user_1) { create(:user, username: 'randomuser', name: 'USER-name1', email: 'uji@example.com') } + let_it_be(:user_2) { create(:user, username: 'username-2') } + let_it_be(:user_5) { create(:user, username: 'username-5') } + let_it_be(:user_4) { create(:user, email: 'user-4@example.com') } + let_it_be(:user_6) { create(:user, email: 'user-6@example.com') } + let_it_be(:user_7) { create(:user, username: 'username-7') } + let_it_be(:user_8) do + create(:user).tap { |user| create(:email, user: user, email: 'user8_email@example.com') } + end + + let_it_be(:current_user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let(:jira_users) do [ - { 'key' => 'abcd', 'name' => 'user1' }, - { 'key' => 'efg' }, - { 'key' => 'hij', 'name' => 'user3', 'emailAddress' => 'user3@example.com' } + { 'key' => 'abcd', 'name' => 'User-Name1' }, # matched by name + { 'key' => 'efg', 'name' => 'username-2' }, # matcher by username + { 'key' => 'hij' }, # no match + { 'key' => '123', 'name' => 'user-4', 'emailAddress' => 'user-4@example.com' }, # matched by email + { 'key' => '456', 'name' => 'username5foo', 'emailAddress' => 'user-5@example.com' }, # no match + { 'key' => '789', 'name' => 'user-6', 'emailAddress' => 'user-6@example.com' }, # matched by email, no project member + { 'key' => 'xyz', 'name' => 'username-7', 'emailAddress' => 'user-7@example.com' }, # matched by username, no project member + { 'key' => 'vhk', 'name' => 'user-8', 'emailAddress' => 'user8_email@example.com' }, # matched by secondary email + { 'key' => 'uji', 'name' => 'user-9', 'emailAddress' => 'uji@example.com' } # matched by email, same as user_1 ] end describe '#execute' do + before do + project.add_developer(current_user) + project.add_developer(user_1) + project.add_developer(user_2) + group.add_developer(user_4) + group.add_guest(user_8) + end + 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 efb303dab9f..7112443502c 100644 --- a/spec/services/jira_import/users_importer_spec.rb +++ b/spec/services/jira_import/users_importer_spec.rb @@ -6,7 +6,8 @@ RSpec.describe JiraImport::UsersImporter do include JiraServiceHelper let_it_be(:user) { create(:user) } - let_it_be(:project, reload: true) { create(:project) } + let_it_be(:group) { create(:group) } + let_it_be(:project, reload: true) { create(:project, group: group) } let_it_be(:start_at) { 7 } let(:importer) { described_class.new(user, project, start_at) } @@ -18,19 +19,15 @@ RSpec.describe JiraImport::UsersImporter do [ { jira_account_id: 'acc1', - jira_display_name: 'user1', + jira_display_name: 'user-name1', jira_email: 'sample@jira.com', - gitlab_id: nil, - gitlab_username: nil, - gitlab_name: nil + gitlab_id: project_member.id }, { jira_account_id: 'acc2', - jira_display_name: 'user2', + jira_display_name: 'user-name2', jira_email: nil, - gitlab_id: nil, - gitlab_username: nil, - gitlab_name: nil + gitlab_id: group_member.id } ] end @@ -69,13 +66,22 @@ RSpec.describe JiraImport::UsersImporter do context 'when jira client returns an empty array' do let(:jira_users) { [] } - it 'retturns nil payload' do + it 'returns nil payload' do expect(subject.success?).to be_truthy expect(subject.payload).to be_empty end end context 'when jira client returns an results' do + let_it_be(:project_member) { create(:user, email: 'sample@jira.com') } + let_it_be(:group_member) { create(:user, name: 'user-name2') } + let_it_be(:other_user) { create(:user) } + + before do + project.add_developer(project_member) + group.add_developer(group_member) + end + it 'returns the mapped users' do expect(subject.success?).to be_truthy expect(subject.payload).to eq(mapped_users) @@ -90,8 +96,8 @@ RSpec.describe JiraImport::UsersImporter do 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' } + { 'key' => 'acc1', 'name' => 'user-name1', 'emailAddress' => 'sample@jira.com' }, + { 'key' => 'acc2', 'name' => 'user-name2' } ] end @@ -110,8 +116,8 @@ RSpec.describe JiraImport::UsersImporter do 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' } + { 'accountId' => 'acc1', 'displayName' => 'user-name1', 'emailAddress' => 'sample@jira.com' }, + { 'accountId' => 'acc2', 'displayName' => 'user-name2' } ] end |