summaryrefslogtreecommitdiff
path: root/spec/services/notification_service_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/services/notification_service_spec.rb
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/services/notification_service_spec.rb')
-rw-r--r--spec/services/notification_service_spec.rb56
1 files changed, 54 insertions, 2 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 46c80a86639..3c1c3e2dfc3 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -243,11 +243,12 @@ describe NotificationService, :mailer do
describe '#unknown_sign_in' do
let_it_be(:user) { create(:user) }
let_it_be(:ip) { '127.0.0.1' }
+ let_it_be(:time) { Time.current }
- subject { notification.unknown_sign_in(user, ip) }
+ subject { notification.unknown_sign_in(user, ip, time) }
it 'sends email to the user' do
- expect { subject }.to have_enqueued_email(user, ip, mail: 'unknown_sign_in_email')
+ expect { subject }.to have_enqueued_email(user, ip, time, mail: 'unknown_sign_in_email')
end
end
@@ -2867,6 +2868,57 @@ describe NotificationService, :mailer do
end
end
+ describe '#new_review' do
+ let(:project) { create(:project, :repository) }
+ let(:user) { create(:user) }
+ let(:user2) { create(:user) }
+ let(:reviewer) { create(:user) }
+ let(:merge_request) { create(:merge_request, source_project: project, assignees: [user, user2], author: create(:user)) }
+ let(:review) { create(:review, merge_request: merge_request, project: project, author: reviewer) }
+ let(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, author: reviewer, review: review) }
+
+ before do
+ build_team(review.project)
+ add_users(review.project)
+ add_user_subscriptions(merge_request)
+ project.add_maintainer(merge_request.author)
+ project.add_maintainer(reviewer)
+ merge_request.assignees.each { |assignee| project.add_maintainer(assignee) }
+
+ create(:diff_note_on_merge_request,
+ project: project,
+ noteable: merge_request,
+ author: reviewer,
+ review: review,
+ note: "cc @mention")
+ end
+
+ it 'sends emails' do
+ expect(Notify).not_to receive(:new_review_email).with(review.author.id, review.id)
+ expect(Notify).not_to receive(:new_review_email).with(@unsubscriber.id, review.id)
+ merge_request.assignee_ids.each do |assignee_id|
+ expect(Notify).to receive(:new_review_email).with(assignee_id, review.id).and_call_original
+ end
+ expect(Notify).to receive(:new_review_email).with(merge_request.author.id, review.id).and_call_original
+ expect(Notify).to receive(:new_review_email).with(@u_watcher.id, review.id).and_call_original
+ expect(Notify).to receive(:new_review_email).with(@u_mentioned.id, review.id).and_call_original
+ expect(Notify).to receive(:new_review_email).with(@subscriber.id, review.id).and_call_original
+ expect(Notify).to receive(:new_review_email).with(@watcher_and_subscriber.id, review.id).and_call_original
+ expect(Notify).to receive(:new_review_email).with(@subscribed_participant.id, review.id).and_call_original
+
+ subject.new_review(review)
+ end
+
+ it_behaves_like 'project emails are disabled' do
+ let(:notification_target) { review }
+ let(:notification_trigger) { subject.new_review(review) }
+
+ around do |example|
+ perform_enqueued_jobs { example.run }
+ end
+ end
+ end
+
def build_team(project)
@u_watcher = create_global_setting_for(create(:user), :watch)
@u_participating = create_global_setting_for(create(:user), :participating)