summaryrefslogtreecommitdiff
path: root/spec/mailers/notify_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mailers/notify_spec.rb')
-rw-r--r--spec/mailers/notify_spec.rb83
1 files changed, 79 insertions, 4 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 8b99cc41a53..e56cd488a52 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'email_spec'
-describe Notify do
+RSpec.describe Notify do
include EmailSpec::Helpers
include EmailSpec::Matchers
include EmailHelpers
@@ -105,6 +105,7 @@ describe Notify do
it 'contains a link to issue author' do
is_expected.to have_body_text(issue.author_name)
is_expected.to have_body_text 'created an issue'
+ is_expected.to have_link(issue.to_reference, href: project_issue_url(issue.project, issue))
end
it 'contains a link to the issue' do
@@ -467,6 +468,7 @@ describe Notify do
is_expected.to have_body_text(status)
is_expected.to have_body_text(current_user_sanitized)
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -497,6 +499,7 @@ describe Notify do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text('merged')
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -534,6 +537,7 @@ describe Notify do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
is_expected.to have_body_text('due to conflict.')
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -567,6 +571,7 @@ describe Notify do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text("#{push_user.name} pushed new commits")
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
+ is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
end
end
end
@@ -1175,9 +1180,7 @@ describe Notify do
context 'when note is not on text' do
before do
- allow_next_instance_of(DiffDiscussion) do |instance|
- allow(instance).to receive(:on_text?).and_return(false)
- end
+ allow(note.discussion).to receive(:on_text?).and_return(false)
end
it 'does not include diffs with character-level highlighting' do
@@ -1248,6 +1251,78 @@ describe Notify do
it_behaves_like 'appearance header and footer not enabled'
end
end
+
+ context 'for service desk issues' do
+ before do
+ issue.update!(service_desk_reply_to: 'service.desk@example.com')
+ end
+
+ def expect_sender(username)
+ sender = subject.header[:from].addrs[0]
+ expect(sender.display_name).to eq(username)
+ expect(sender.address).to eq(gitlab_sender)
+ end
+
+ describe 'thank you email' do
+ subject { described_class.service_desk_thank_you_email(issue.id) }
+
+ it_behaves_like 'an unsubscribeable thread'
+
+ it 'has the correct recipient' do
+ is_expected.to deliver_to('service.desk@example.com')
+ end
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, include_project: false, reply: true)
+ is_expected.to have_body_text("Thank you for your support request! We are tracking your request as ticket #{issue.to_reference}, and will respond as soon as we can.")
+ end
+ end
+
+ it 'uses service bot name by default' do
+ expect_sender(User.support_bot.name)
+ end
+
+ context 'when custom outgoing name is set' do
+ let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: 'some custom name') }
+
+ it 'uses custom name in "from" header' do
+ expect_sender('some custom name')
+ end
+ end
+
+ context 'when custom outgoing name is empty' do
+ let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: '') }
+
+ it 'uses service bot name' do
+ expect_sender(User.support_bot.name)
+ end
+ end
+ end
+
+ describe 'new note email' do
+ let_it_be(:first_note) { create(:discussion_note_on_issue, note: 'Hello world') }
+
+ subject { described_class.service_desk_new_note_email(issue.id, first_note.id) }
+
+ it_behaves_like 'an unsubscribeable thread'
+
+ it 'has the correct recipient' do
+ is_expected.to deliver_to('service.desk@example.com')
+ end
+
+ it 'uses author\'s name in "from" header' do
+ expect_sender(first_note.author.name)
+ end
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_referable_subject(issue, include_project: false, reply: true)
+ is_expected.to have_body_text(first_note.note)
+ end
+ end
+ end
+ end
end
context 'for a group' do