debian-mirror-gitlab/spec/services/notes/destroy_service_spec.rb

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

110 lines
4.1 KiB
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Notes::DestroyService, feature_category: :team_planning do
2020-03-13 15:44:24 +05:30
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project) }
2021-09-30 23:02:18 +05:30
2018-03-17 18:26:18 +05:30
let(:user) { issue.author }
2016-06-02 11:05:42 +05:30
describe '#execute' do
it 'deletes a note' do
note = create(:note, project: project, noteable: issue)
2018-03-17 18:26:18 +05:30
described_class.new(project, user).execute(note)
2016-06-02 11:05:42 +05:30
expect(project.issues.find(issue.id).notes).not_to include(note)
end
2018-03-17 18:26:18 +05:30
it 'updates the todo counts for users with todos for the note' do
note = create(:note, project: project, noteable: issue)
create(:todo, note: note, target: issue, user: user, author: user, project: project)
expect { described_class.new(project, user).execute(note) }
.to change { user.todos_pending_count }.from(1).to(0)
end
2018-12-13 13:39:08 +05:30
2022-08-27 11:52:29 +05:30
describe 'comment removed event tracking', :snowplow do
let(:property) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_REMOVED }
let(:note) { create(:note, project: project, noteable: issue) }
let(:service_action) { described_class.new(project, user).execute(note) }
it 'tracks issue comment removal usage data', :clean_gitlab_redis_shared_state do
counter = Gitlab::UsageDataCounters::HLLRedisCounter
2021-01-29 00:20:46 +05:30
2022-08-27 11:52:29 +05:30
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_removed_action)
.with(author: user, project: project)
.and_call_original
expect do
service_action
2023-07-09 08:55:56 +05:30
end.to change {
counter.unique_events(event_names: property, start_date: Date.today.beginning_of_week, end_date: 1.week.from_now)
}.by(1)
2022-08-27 11:52:29 +05:30
end
it_behaves_like 'issue_edit snowplow tracking' do
subject(:execute_service_action) { service_action }
end
2021-01-29 00:20:46 +05:30
end
2021-03-08 18:12:59 +05:30
it 'tracks merge request usage data' do
mr = create(:merge_request, source_project: project)
note = create(:note, project: project, noteable: mr)
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).to receive(:track_remove_comment_action).with(note: note)
described_class.new(project, user).execute(note)
end
2021-01-29 00:20:46 +05:30
context 'in a merge request' do
let_it_be(:repo_project) { create(:project, :repository) }
let_it_be(:merge_request) do
2022-10-11 01:57:18 +05:30
create(:merge_request, source_project: repo_project, target_project: repo_project)
2018-12-13 13:39:08 +05:30
end
2021-01-29 00:20:46 +05:30
let_it_be(:note) do
2022-10-11 01:57:18 +05:30
create(:diff_note_on_merge_request, project: repo_project, noteable: merge_request)
2018-12-13 13:39:08 +05:30
end
2021-01-29 00:20:46 +05:30
it 'does not track issue comment removal usage data' do
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_removed_action)
2018-12-13 13:39:08 +05:30
described_class.new(repo_project, user).execute(note)
end
2021-01-29 00:20:46 +05:30
context 'noteable highlight cache clearing' do
before do
allow(note.position).to receive(:unfolded_diff?) { true }
end
it 'clears noteable diff cache when it was unfolded for the note position' do
expect(merge_request).to receive_message_chain(:diffs, :clear_cache)
described_class.new(repo_project, user).execute(note)
end
it 'does not clear cache when note is not the first of the discussion' do
2022-10-11 01:57:18 +05:30
reply_note = create(:diff_note_on_merge_request,
in_reply_to: note, project: repo_project, noteable: merge_request)
2018-12-13 13:39:08 +05:30
2021-01-29 00:20:46 +05:30
expect(merge_request).not_to receive(:diffs)
2018-12-13 13:39:08 +05:30
2021-01-29 00:20:46 +05:30
described_class.new(repo_project, user).execute(reply_note)
end
2018-12-13 13:39:08 +05:30
end
end
2023-04-23 21:23:45 +05:30
it 'tracks design comment removal' do
note = create(:note_on_design, project: project)
2023-07-09 08:55:56 +05:30
expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(
:track_issue_design_comment_removed_action
).with(
author: note.author,
project: project
)
2023-04-23 21:23:45 +05:30
described_class.new(project, user).execute(note)
end
2016-06-02 11:05:42 +05:30
end
end