2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe MergeRequests::AssignIssuesService, feature_category: :code_review_workflow do
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-11-03 12:29:30 +05:30
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:merge_request) { create(:merge_request, :simple, source_project: project, author: user, description: "fixes #{issue.to_reference}") }
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:service) { described_class.new(project: project, current_user: user, params: { merge_request: merge_request }) }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds unassigned issues fixed in merge request' do
|
|
|
|
expect(service.assignable_issues.map(&:id)).to include(issue.id)
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'ignores issues the user cannot update assignee on', :sidekiq_inline do
|
2017-08-17 22:00:37 +05:30
|
|
|
project.team.truncate
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
expect(service.assignable_issues).to be_empty
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'ignores issues already assigned to any user' do
|
|
|
|
issue.assignees = [create(:user)]
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
expect(service.assignable_issues).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores all issues unless current_user is merge_request.author' do
|
|
|
|
merge_request.update!(author: create(:user))
|
|
|
|
|
|
|
|
expect(service.assignable_issues).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts precomputed data for closes_issues' do
|
|
|
|
issue2 = create(:issue, project: project)
|
2023-07-09 08:55:56 +05:30
|
|
|
service2 = described_class.new(
|
|
|
|
project: project,
|
|
|
|
current_user: user,
|
|
|
|
params: {
|
|
|
|
merge_request: merge_request,
|
|
|
|
closes_issues: [issue, issue2]
|
|
|
|
}
|
|
|
|
)
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
expect(service2.assignable_issues.count).to eq 2
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns these to the merge request owner' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect { service.execute }.to change { issue.assignees.first }.to(user)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores external issues' do
|
|
|
|
external_issue = ExternalIssue.new('JIRA-123', project)
|
|
|
|
service = described_class.new(
|
2021-06-08 01:23:25 +05:30
|
|
|
project: project,
|
|
|
|
current_user: user,
|
|
|
|
params: {
|
|
|
|
merge_request: merge_request,
|
|
|
|
closes_issues: [external_issue]
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
expect(service.assignable_issues.count).to eq 0
|
|
|
|
end
|
|
|
|
end
|