2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe IssueEntity do
|
2022-07-16 23:28:13 +05:30
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:resource) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:request) { double('request', current_user: user) }
|
|
|
|
|
|
|
|
subject { described_class.new(resource, request: request).as_json }
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
describe 'web_url' do
|
|
|
|
context 'when issue is of type task' do
|
|
|
|
let(:resource) { create(:issue, :task, project: project) }
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'when use_iid_in_work_items_path feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(use_iid_in_work_items_path: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
# This was already a path and not a url when the work items change was introduced
|
|
|
|
it 'has a work item path' do
|
|
|
|
expect(subject[:web_url]).to eq(project_work_items_path(project, resource.id))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a work item path with iid' do
|
|
|
|
expect(subject[:web_url]).to eq(project_work_items_path(project, resource.iid, iid_path: true))
|
2022-07-16 23:28:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
describe 'type' do
|
|
|
|
it 'has an issue type' do
|
|
|
|
expect(subject[:type]).to eq('ISSUE')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'has Issuable attributes' do
|
|
|
|
expect(subject).to include(:id, :iid, :author_id, :description, :lock_version, :milestone_id,
|
|
|
|
:title, :updated_by_id, :created_at, :updated_at, :milestone, :labels)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has time estimation attributes' do
|
|
|
|
expect(subject).to include(:time_estimate, :total_time_spent, :human_time_estimate, :human_total_time_spent)
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
describe 'current_user' do
|
|
|
|
it 'has the exprected permissions' do
|
|
|
|
expect(subject[:current_user]).to include(:can_create_note, :can_update, :can_set_issue_metadata,
|
|
|
|
:can_award_emoji)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
context 'when issue got moved' do
|
|
|
|
let(:public_project) { create(:project, :public) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:issue) { create(:issue, project: public_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(member)
|
|
|
|
public_project.add_developer(member)
|
2021-06-08 01:23:25 +05:30
|
|
|
Issues::MoveService.new(project: public_project, current_user: member).execute(issue, project)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read target project' do
|
|
|
|
it 'does not return moved_to_id' do
|
|
|
|
request = double('request', current_user: non_member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:moved_to_id]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read target project' do
|
|
|
|
it 'returns moved moved_to_id' do
|
|
|
|
request = double('request', current_user: member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:moved_to_id]).to eq(issue.moved_to_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
context 'when issue got duplicated' do
|
|
|
|
let(:private_project) { create(:project, :private) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:new_issue) { create(:issue, project: private_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Issues::DuplicateService
|
2021-06-08 01:23:25 +05:30
|
|
|
.new(project: project, current_user: member)
|
2019-12-04 20:38:33 +05:30
|
|
|
.execute(issue, new_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read new issue' do
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
|
|
|
|
it 'does not return duplicated_to_id' do
|
|
|
|
request = double('request', current_user: non_member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:duplicated_to_id]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read target project' do
|
|
|
|
before do
|
|
|
|
project.add_developer(member)
|
|
|
|
private_project.add_developer(member)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns duplicated duplicated_to_id' do
|
|
|
|
request = double('request', current_user: member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:duplicated_to_id]).to eq(issue.duplicated_to_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
context 'when issuable in active or archived project' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is active' do
|
|
|
|
it 'returns archived false' do
|
|
|
|
expect(subject[:is_project_archived]).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for archived project doc' do
|
|
|
|
response = described_class.new(resource, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:archived_project_docs_path]).to be nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is archived' do
|
|
|
|
before do
|
2020-11-24 15:15:51 +05:30
|
|
|
project.update!(archived: true)
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns archived true' do
|
|
|
|
expect(subject[:is_project_archived]).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns archived project doc' do
|
2022-08-13 15:12:31 +05:30
|
|
|
expect(subject[:archived_project_docs_path]).to eq('/help/user/project/settings/index.md#archive-a-project')
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
it_behaves_like 'issuable entity current_user properties'
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
context 'when issue has email participants' do
|
|
|
|
before do
|
|
|
|
resource.issue_email_participants.create!(email: 'any@email.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issue is confidential' do
|
|
|
|
it 'returns email participants' do
|
|
|
|
resource.update!(confidential: true)
|
|
|
|
|
|
|
|
expect(subject[:issue_email_participants]).to match_array([{ email: "any@email.com" }])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issue is not confidential' do
|
|
|
|
it 'returns empty array' do
|
|
|
|
expect(subject[:issue_email_participants]).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|