diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/services/quick_actions/interpret_service_spec.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/services/quick_actions/interpret_service_spec.rb')
-rw-r--r-- | spec/services/quick_actions/interpret_service_spec.rb | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 1a102b125f6..bf35e72a037 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -1949,6 +1949,100 @@ RSpec.describe QuickActions::InterpretService do end end end + + context 'invite_email command' do + let_it_be(:issuable) { issue } + + it_behaves_like 'empty command', "No email participants were added. Either none were provided, or they already exist." do + let(:content) { '/invite_email' } + end + + context 'with existing email participant' do + let(:content) { '/invite_email a@gitlab.com' } + + before do + issuable.issue_email_participants.create!(email: "a@gitlab.com") + end + + it_behaves_like 'empty command', "No email participants were added. Either none were provided, or they already exist." + end + + context 'with new email participants' do + let(:content) { '/invite_email a@gitlab.com b@gitlab.com' } + + subject(:add_emails) { service.execute(content, issuable) } + + it 'returns message' do + _, _, message = add_emails + + expect(message).to eq('Added a@gitlab.com and b@gitlab.com.') + end + + it 'adds 2 participants' do + expect { add_emails }.to change { issue.issue_email_participants.count }.by(2) + end + + context 'with mixed case email' do + let(:content) { '/invite_email FirstLast@GitLab.com' } + + it 'returns correctly cased message' do + _, _, message = add_emails + + expect(message).to eq('Added FirstLast@GitLab.com.') + end + end + + context 'with invalid email' do + let(:content) { '/invite_email a@gitlab.com bad_email' } + + it 'only adds valid emails' do + expect { add_emails }.to change { issue.issue_email_participants.count }.by(1) + end + end + + context 'with existing email' do + let(:content) { '/invite_email a@gitlab.com existing@gitlab.com' } + + it 'only adds new emails' do + issue.issue_email_participants.create!(email: 'existing@gitlab.com') + + expect { add_emails }.to change { issue.issue_email_participants.count }.by(1) + end + + it 'only adds new (case insensitive) emails' do + issue.issue_email_participants.create!(email: 'EXISTING@gitlab.com') + + expect { add_emails }.to change { issue.issue_email_participants.count }.by(1) + end + end + + context 'with duplicate email' do + let(:content) { '/invite_email a@gitlab.com a@gitlab.com' } + + it 'only adds unique new emails' do + expect { add_emails }.to change { issue.issue_email_participants.count }.by(1) + end + end + + context 'with more than 6 emails' do + let(:content) { '/invite_email a@gitlab.com b@gitlab.com c@gitlab.com d@gitlab.com e@gitlab.com f@gitlab.com g@gitlab.com' } + + it 'only adds 6 new emails' do + expect { add_emails }.to change { issue.issue_email_participants.count }.by(6) + end + end + + context 'with feature flag disabled' do + before do + stub_feature_flags(issue_email_participants: false) + end + + it 'does not add any participants' do + expect { add_emails }.not_to change { issue.issue_email_participants.count } + end + end + end + end end describe '#explain' do |