diff options
Diffstat (limited to 'spec/lib/gitlab/jira_import/issue_serializer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/jira_import/issue_serializer_spec.rb | 116 |
1 files changed, 100 insertions, 16 deletions
diff --git a/spec/lib/gitlab/jira_import/issue_serializer_spec.rb b/spec/lib/gitlab/jira_import/issue_serializer_spec.rb index 5c84556ab25..f24a83994f7 100644 --- a/spec/lib/gitlab/jira_import/issue_serializer_spec.rb +++ b/spec/lib/gitlab/jira_import/issue_serializer_spec.rb @@ -16,7 +16,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(displayName: 'Solver') } + let(:assignee) { double(displayName: 'Solver', emailAddress: 'assignee@example.com') } + let(:reporter) { double(displayName: 'Reporter', emailAddress: 'reporter@example.com') } let(:jira_status) { 'new' } let(:parent_field) do @@ -42,7 +43,7 @@ describe Gitlab::JiraImport::IssueSerializer do created: created_at, updated: updated_at, assignee: assignee, - reporter: double(displayName: 'Reporter'), + reporter: reporter, status: double(statusCategory: { 'key' => jira_status }), fields: fields ) @@ -54,10 +55,6 @@ describe Gitlab::JiraImport::IssueSerializer do let(:expected_description) do <<~MD - *Created by: Reporter* - - *Assigned to: Solver* - basic description --- @@ -80,6 +77,7 @@ describe Gitlab::JiraImport::IssueSerializer do updated_at: updated_at, created_at: created_at, author_id: project.creator_id, + assignee_ids: nil, label_ids: [project_label.id, group_label.id] + Label.reorder(id: :asc).last(2).pluck(:id) ) end @@ -88,22 +86,108 @@ describe Gitlab::JiraImport::IssueSerializer do expect(Issue.new(subject)).to be_valid end - it 'creates all missing labels (on project level)' do - expect { subject }.to change { Label.count }.from(3).to(5) + context 'labels' do + it 'creates all missing labels (on project level)' do + expect { subject }.to change { Label.count }.from(3).to(5) + + expect(Label.find_by(title: 'frontend').project).to eq(project) + expect(Label.find_by(title: 'backend').project).to eq(project) + end + + context 'when there are no new labels' do + let(:labels_field) { %w(bug dev) } - expect(Label.find_by(title: 'frontend').project).to eq(project) - expect(Label.find_by(title: 'backend').project).to eq(project) + it 'assigns the labels to the Issue hash' do + expect(subject[:label_ids]).to match_array([project_label.id, group_label.id]) + end + + it 'does not create new labels' do + expect { subject }.not_to change { Label.count }.from(3) + end + end end - context 'when there are no new labels' do - let(:labels_field) { %w(bug dev) } + context 'author' do + context 'when reporter maps to a GitLab user who is a project member' do + let!(:user) { create(:user, email: 'reporter@example.com') } - it 'assigns the labels to the Issue hash' do - expect(subject[:label_ids]).to match_array([project_label.id, group_label.id]) + it 'sets the issue author to the mapped user' do + project.add_developer(user) + + expect(subject[:author_id]).to eq(user.id) + end end - it 'does not create new labels' do - expect { subject }.not_to change { Label.count }.from(3) + context 'when reporter maps to a GitLab user who is not a project member' do + let!(:user) { create(:user, email: 'reporter@example.com') } + + it 'defaults the issue author to project creator' do + expect(subject[:author_id]).to eq(project.creator.id) + end + end + + context 'when reporter does not map to a GitLab user' do + it 'defaults the issue author to project creator' do + expect(subject[:author_id]).to eq(project.creator.id) + end + end + + context 'when reporter field is empty' do + let(:reporter) { nil } + + it 'defaults the issue author to project creator' do + expect(subject[:author_id]).to eq(project.creator.id) + end + end + + context 'when reporter field is missing email address' do + let(:reporter) { double(name: 'Reporter', emailAddress: nil) } + + it 'defaults the issue author to project creator' do + expect(subject[:author_id]).to eq(project.creator.id) + end + end + end + + context 'assignee' do + context 'when assignee maps to a GitLab user who is a project member' do + let!(:user) { create(:user, email: 'assignee@example.com') } + + it 'sets the issue assignees to the mapped user' do + project.add_developer(user) + + expect(subject[:assignee_ids]).to eq([user.id]) + end + end + + context 'when assignee maps to a GitLab user who is not a project member' do + let!(:user) { create(:user, email: 'assignee@example.com') } + + it 'leaves the assignee empty' do + expect(subject[:assignee_ids]).to be_nil + end + end + + context 'when assignee does not map to a GitLab user' do + it 'leaves the assignee empty' do + expect(subject[:assignee_ids]).to be_nil + end + end + + context 'when assginee field is empty' do + let(:assignee) { nil } + + it 'leaves the assignee empty' do + expect(subject[:assignee_ids]).to be_nil + end + end + + context 'when assginee field is missing email address' do + let(:assignee) { double(name: 'Assignee', emailAddress: nil) } + + it 'leaves the assignee empty' do + expect(subject[:assignee_ids]).to be_nil + end end end end |