debian-mirror-gitlab/spec/services/issues/reopen_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
4.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Issues::ReopenService, feature_category: :team_planning do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-09-29 09:46:39 +05:30
let(:issue) { create(:issue, :closed, project: project) }
2016-09-13 17:45:13 +05:30
describe '#execute' do
2016-09-29 09:46:39 +05:30
context 'when user is not authorized to reopen issue' do
2021-11-18 22:05:49 +05:30
it 'does not reopen the issue' do
2016-09-29 09:46:39 +05:30
guest = create(:user)
2018-03-17 18:26:18 +05:30
project.add_guest(guest)
2016-09-29 09:46:39 +05:30
2023-04-23 21:23:45 +05:30
described_class.new(container: project, current_user: guest).execute(issue)
2016-09-13 17:45:13 +05:30
2016-09-29 09:46:39 +05:30
expect(issue).to be_closed
end
2021-11-18 22:05:49 +05:30
context 'when skip_authorization is true' do
it 'does close the issue even if user is not authorized' do
non_authorized_user = create(:user)
2023-04-23 21:23:45 +05:30
service = described_class.new(container: project, current_user: non_authorized_user)
2021-11-18 22:05:49 +05:30
expect do
service.execute(issue, skip_authorization: true)
end.to change { issue.reload.state }.from('closed').to('opened')
end
end
2016-09-29 09:46:39 +05:30
end
2018-11-18 11:00:15 +05:30
context 'when user is authorized to reopen issue' do
2016-09-29 09:46:39 +05:30
let(:user) { create(:user) }
2023-04-23 21:23:45 +05:30
subject(:execute) { described_class.new(container: project, current_user: user).execute(issue) }
2022-08-13 15:12:31 +05:30
2016-09-29 09:46:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
it 'invalidates counter cache for assignees' do
issue.assignees << user
expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts)
2022-08-13 15:12:31 +05:30
execute
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'refreshes the number of opened issues' do
2021-11-11 11:23:49 +05:30
expect do
2022-08-13 15:12:31 +05:30
execute
2021-11-11 11:23:49 +05:30
BatchLoader::Executor.clear_current
end.to change { project.open_issues_count }.from(0).to(1)
2018-03-17 18:26:18 +05:30
end
2020-04-08 14:13:33 +05:30
it 'deletes milestone issue counters cache' do
2020-11-24 15:15:51 +05:30
issue.update!(milestone: create(:milestone, project: project))
2020-04-08 14:13:33 +05:30
expect_next_instance_of(Milestones::ClosedIssuesCountService, issue.milestone) do |service|
expect(service).to receive(:delete_cache).and_call_original
end
2022-08-13 15:12:31 +05:30
execute
end
it 'does not create timeline event' do
expect { execute }.not_to change { issue.incident_management_timeline_events.count }
2020-04-08 14:13:33 +05:30
end
2020-11-24 15:15:51 +05:30
context 'issue is incident type' do
let(:issue) { create(:incident, :closed, project: project) }
let(:current_user) { user }
it_behaves_like 'an incident management tracked event', :incident_management_incident_reopened
2022-08-13 15:12:31 +05:30
2023-03-04 22:38:38 +05:30
it_behaves_like 'Snowplow event tracking with RedisHLL context' do
let(:namespace) { issue.namespace }
let(:category) { described_class.to_s }
let(:action) { 'incident_management_incident_reopened' }
let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' }
end
2022-08-13 15:12:31 +05:30
it 'creates a timeline event' do
expect(IncidentManagement::TimelineEvents::CreateService)
.to receive(:reopen_incident)
.with(issue, current_user)
.and_call_original
expect { execute }.to change { issue.incident_management_timeline_events.count }.by(1)
end
2020-11-24 15:15:51 +05:30
end
2016-09-29 09:46:39 +05:30
context 'when issue is not confidential' do
2023-01-13 00:05:48 +05:30
let(:expected_payload) do
include(
event_type: 'issue',
object_kind: 'issue',
changes: {
closed_at: { current: nil, previous: kind_of(Time) },
state_id: { current: 1, previous: 2 },
updated_at: { current: kind_of(Time), previous: kind_of(Time) }
},
object_attributes: include(
state: 'opened',
action: 'reopen'
)
)
end
2016-09-29 09:46:39 +05:30
it 'executes issue hooks' do
2023-06-20 00:43:36 +05:30
expect(project.project_namespace).to receive(:execute_hooks).with(expected_payload, :issue_hooks)
expect(project.project_namespace).to receive(:execute_integrations).with(expected_payload, :issue_hooks)
2016-09-29 09:46:39 +05:30
2022-08-13 15:12:31 +05:30
execute
2016-09-29 09:46:39 +05:30
end
end
context 'when issue is confidential' do
2022-08-13 15:12:31 +05:30
let(:issue) { create(:issue, :confidential, :closed, project: project) }
2016-09-29 09:46:39 +05:30
2022-08-13 15:12:31 +05:30
it 'executes confidential issue hooks' do
2023-06-20 00:43:36 +05:30
issue_hooks = :confidential_issue_hooks
expect(project.project_namespace).to receive(:execute_hooks).with(an_instance_of(Hash), issue_hooks)
expect(project.project_namespace).to receive(:execute_integrations).with(an_instance_of(Hash), issue_hooks)
2016-09-29 09:46:39 +05:30
2022-08-13 15:12:31 +05:30
execute
2016-09-29 09:46:39 +05:30
end
2016-09-13 17:45:13 +05:30
end
end
end
end