From 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Feb 2021 10:34:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-9-stable-ee --- .../quick_actions/interpret_service_spec.rb | 194 +++++++++++---------- 1 file changed, 98 insertions(+), 96 deletions(-) (limited to 'spec/services/quick_actions') diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 21e294418a1..1a102b125f6 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -879,139 +879,123 @@ RSpec.describe QuickActions::InterpretService do let(:issuable) { issue } end - context 'when the merge_request_reviewers flag is enabled' do - describe 'assign_reviewer command' do - let(:content) { "/assign_reviewer @#{developer.username}" } - let(:issuable) { merge_request } + describe 'assign_reviewer command' do + let(:content) { "/assign_reviewer @#{developer.username}" } + let(:issuable) { merge_request } - context 'with one user' do - it_behaves_like 'assign_reviewer command' - end + context 'with one user' do + it_behaves_like 'assign_reviewer command' + end - context 'with an issue instead of a merge request' do - let(:issuable) { issue } + context 'with an issue instead of a merge request' do + let(:issuable) { issue } - it_behaves_like 'empty command' - end + it_behaves_like 'empty command' + end - # CE does not have multiple reviewers - context 'assign command with multiple assignees' do - before do - project.add_developer(developer2) - end + # CE does not have multiple reviewers + context 'assign command with multiple assignees' do + before do + project.add_developer(developer2) + end - # There's no guarantee that the reference extractor will preserve - # the order of the mentioned users since this is dependent on the - # order in which rows are returned. We just ensure that at least - # one of the mentioned users is assigned. - context 'assigns to one of the two users' do - let(:content) { "/assign_reviewer @#{developer.username} @#{developer2.username}" } + # There's no guarantee that the reference extractor will preserve + # the order of the mentioned users since this is dependent on the + # order in which rows are returned. We just ensure that at least + # one of the mentioned users is assigned. + context 'assigns to one of the two users' do + let(:content) { "/assign_reviewer @#{developer.username} @#{developer2.username}" } - it 'assigns to a single reviewer' do - _, updates, message = service.execute(content, issuable) + it 'assigns to a single reviewer' do + _, updates, message = service.execute(content, issuable) - expect(updates[:reviewer_ids].count).to eq(1) - reviewer = updates[:reviewer_ids].first - expect([developer.id, developer2.id]).to include(reviewer) + expect(updates[:reviewer_ids].count).to eq(1) + reviewer = updates[:reviewer_ids].first + expect([developer.id, developer2.id]).to include(reviewer) - user = reviewer == developer.id ? developer : developer2 + user = reviewer == developer.id ? developer : developer2 - expect(message).to match("Assigned #{user.to_reference} as reviewer.") - end + expect(message).to match("Assigned #{user.to_reference} as reviewer.") end end + end - context 'with "me" alias' do - let(:content) { '/assign_reviewer me' } + context 'with "me" alias' do + let(:content) { '/assign_reviewer me' } - it_behaves_like 'assign_reviewer command' - end + it_behaves_like 'assign_reviewer command' + end - context 'with an alias and whitespace' do - let(:content) { '/assign_reviewer me ' } + context 'with an alias and whitespace' do + let(:content) { '/assign_reviewer me ' } - it_behaves_like 'assign_reviewer command' - end + it_behaves_like 'assign_reviewer command' + end - context 'with an incorrect user' do - let(:content) { '/assign_reviewer @abcd1234' } + context 'with an incorrect user' do + let(:content) { '/assign_reviewer @abcd1234' } - it_behaves_like 'empty command', "Failed to assign a reviewer because no user was found." - end + it_behaves_like 'empty command', "Failed to assign a reviewer because no user was found." + end - context 'with the "reviewer" alias' do - let(:content) { "/reviewer @#{developer.username}" } + context 'with the "reviewer" alias' do + let(:content) { "/reviewer @#{developer.username}" } - it_behaves_like 'assign_reviewer command' - end + it_behaves_like 'assign_reviewer command' + end - context 'with no user' do - let(:content) { '/assign_reviewer' } + context 'with the "request_review" alias' do + let(:content) { "/request_review @#{developer.username}" } - it_behaves_like 'empty command', "Failed to assign a reviewer because no user was found." - end + it_behaves_like 'assign_reviewer command' + end - context 'includes only the user reference with extra text' do - let(:content) { "/assign_reviewer @#{developer.username} do it!" } + context 'with no user' do + let(:content) { '/assign_reviewer' } - it_behaves_like 'assign_reviewer command' - end + it_behaves_like 'empty command', "Failed to assign a reviewer because no user was found." end - describe 'unassign_reviewer command' do - # CE does not have multiple reviewers, so basically anything - # after /unassign_reviewer (including whitespace) will remove - # all the current reviewers. - let(:issuable) { create(:merge_request, reviewers: [developer]) } - let(:content) { "/unassign_reviewer @#{developer.username}" } + context 'includes only the user reference with extra text' do + let(:content) { "/assign_reviewer @#{developer.username} do it!" } - context 'with one user' do - it_behaves_like 'unassign_reviewer command' - end - - context 'with an issue instead of a merge request' do - let(:issuable) { issue } - - it_behaves_like 'empty command' - end + it_behaves_like 'assign_reviewer command' + end + end - context 'with anything after the command' do - let(:content) { '/unassign_reviewer supercalifragilisticexpialidocious' } + describe 'unassign_reviewer command' do + # CE does not have multiple reviewers, so basically anything + # after /unassign_reviewer (including whitespace) will remove + # all the current reviewers. + let(:issuable) { create(:merge_request, reviewers: [developer]) } + let(:content) { "/unassign_reviewer @#{developer.username}" } - it_behaves_like 'unassign_reviewer command' - end + context 'with one user' do + it_behaves_like 'unassign_reviewer command' + end - context 'with the "remove_reviewer" alias' do - let(:content) { "/remove_reviewer @#{developer.username}" } + context 'with an issue instead of a merge request' do + let(:issuable) { issue } - it_behaves_like 'unassign_reviewer command' - end + it_behaves_like 'empty command' + end - context 'with no user' do - let(:content) { '/unassign_reviewer' } + context 'with anything after the command' do + let(:content) { '/unassign_reviewer supercalifragilisticexpialidocious' } - it_behaves_like 'unassign_reviewer command' - end + it_behaves_like 'unassign_reviewer command' end - end - context 'when the merge_request_reviewers flag is disabled' do - before do - stub_feature_flags(merge_request_reviewers: false) - end + context 'with the "remove_reviewer" alias' do + let(:content) { "/remove_reviewer @#{developer.username}" } - describe 'assign_reviewer command' do - it_behaves_like 'empty command' do - let(:content) { "/assign_reviewer @#{developer.username}" } - let(:issuable) { merge_request } - end + it_behaves_like 'unassign_reviewer command' end - describe 'unassign_reviewer command' do - it_behaves_like 'empty command' do - let(:content) { "/unassign_reviewer @#{developer.username}" } - let(:issuable) { merge_request } - end + context 'with no user' do + let(:content) { '/unassign_reviewer' } + + it_behaves_like 'unassign_reviewer command' end end @@ -1787,6 +1771,24 @@ RSpec.describe QuickActions::InterpretService do expect(text).to eq(" - list\n\ntest") end + it 'tracks MAU for commands' do + content = "/shrug test\n/assign me\n/milestone %4" + + expect(Gitlab::UsageDataCounters::QuickActionActivityUniqueCounter) + .to receive(:track_unique_action) + .with('shrug', args: 'test', user: developer) + + expect(Gitlab::UsageDataCounters::QuickActionActivityUniqueCounter) + .to receive(:track_unique_action) + .with('assign', args: 'me', user: developer) + + expect(Gitlab::UsageDataCounters::QuickActionActivityUniqueCounter) + .to receive(:track_unique_action) + .with('milestone', args: '%4', user: developer) + + service.execute(content, issue) + end + context '/create_merge_request command' do let(:branch_name) { '1-feature' } let(:content) { "/create_merge_request #{branch_name}" } -- cgit v1.2.3