diff options
Diffstat (limited to 'spec/services/notes/create_service_spec.rb')
-rw-r--r-- | spec/services/notes/create_service_spec.rb | 94 |
1 files changed, 70 insertions, 24 deletions
diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 53b75a3c991..37318d76586 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -7,37 +7,74 @@ RSpec.describe Notes::CreateService do let_it_be(:issue) { create(:issue, project: project) } let_it_be(:user) { create(:user) } - let(:opts) do - { note: 'Awesome comment', noteable_type: 'Issue', noteable_id: issue.id, confidential: true } - end + let(:base_opts) { { note: 'Awesome comment', noteable_type: 'Issue', noteable_id: issue.id } } + let(:opts) { base_opts.merge(confidential: true) } describe '#execute' do + subject(:note) { described_class.new(project, user, opts).execute } + before do project.add_maintainer(user) end context "valid params" do it 'returns a valid note' do - note = described_class.new(project, user, opts).execute - expect(note).to be_valid end it 'returns a persisted note' do - note = described_class.new(project, user, opts).execute - expect(note).to be_persisted end - it 'note has valid content' do - note = described_class.new(project, user, opts).execute + context 'with internal parameter' do + context 'when confidential' do + let(:opts) { base_opts.merge(internal: true) } + + it 'returns a confidential note' do + expect(note).to be_confidential + end + end + + context 'when not confidential' do + let(:opts) { base_opts.merge(internal: false) } + + it 'returns a confidential note' do + expect(note).not_to be_confidential + end + end + end + + context 'with confidential parameter' do + context 'when confidential' do + let(:opts) { base_opts.merge(confidential: true) } + + it 'returns a confidential note' do + expect(note).to be_confidential + end + end + + context 'when not confidential' do + let(:opts) { base_opts.merge(confidential: false) } + it 'returns a confidential note' do + expect(note).not_to be_confidential + end + end + end + + context 'with confidential and internal parameter set' do + let(:opts) { base_opts.merge(internal: true, confidential: false) } + + it 'prefers the internal parameter' do + expect(note).to be_confidential + end + end + + it 'note has valid content' do expect(note.note).to eq(opts[:note]) end it 'note belongs to the correct project' do - note = described_class.new(project, user, opts).execute - expect(note.project).to eq(project) end @@ -60,8 +97,6 @@ RSpec.describe Notes::CreateService do end context 'issue is an incident' do - subject { described_class.new(project, user, opts).execute } - let(:issue) { create(:incident, project: project) } it_behaves_like 'an incident management tracked event', :incident_management_incident_comment do @@ -69,20 +104,31 @@ RSpec.describe Notes::CreateService do end end - it 'tracks issue comment usage data', :clean_gitlab_redis_shared_state do - event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_ADDED - counter = Gitlab::UsageDataCounters::HLLRedisCounter + describe 'event tracking', :snowplow do + let(:event) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_ADDED } + let(:execute_create_service) { described_class.new(project, user, opts).execute } - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_added_action).with(author: user).and_call_original - expect do - described_class.new(project, user, opts).execute - end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) - end + it 'tracks issue comment usage data', :clean_gitlab_redis_shared_state do + counter = Gitlab::UsageDataCounters::HLLRedisCounter + + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_comment_added_action) + .with(author: user, project: project) + .and_call_original + expect do + execute_create_service + end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) + end - it 'does not track merge request usage data' do - expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_create_comment_action) + it 'does not track merge request usage data' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_create_comment_action) - described_class.new(project, user, opts).execute + execute_create_service + end + + it_behaves_like 'issue_edit snowplow tracking' do + let(:property) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_ADDED } + subject(:service_action) { execute_create_service } + end end context 'in a merge request' do |