diff options
Diffstat (limited to 'spec/mailers/emails')
-rw-r--r-- | spec/mailers/emails/profile_spec.rb | 6 | ||||
-rw-r--r-- | spec/mailers/emails/service_desk_spec.rb | 89 |
2 files changed, 48 insertions, 47 deletions
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb index 1fd2a92866d..f5fce559778 100644 --- a/spec/mailers/emails/profile_spec.rb +++ b/spec/mailers/emails/profile_spec.rb @@ -438,7 +438,7 @@ RSpec.describe Emails::Profile do end it 'includes a link to the change password documentation' do - is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/user_passwords.html#change-your-password' + is_expected.to have_body_text help_page_url('user/profile/user_passwords', anchor: 'change-your-password') end it 'mentions two factor authentication when two factor is not enabled' do @@ -446,7 +446,7 @@ RSpec.describe Emails::Profile do end it 'includes a link to two-factor authentication documentation' do - is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html' + is_expected.to have_body_text help_page_url('user/profile/account/two_factor_authentication') end context 'when two factor authentication is enabled' do @@ -488,7 +488,7 @@ RSpec.describe Emails::Profile do end it 'includes a link to the change password documentation' do - is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/user_passwords.html#change-your-password' + is_expected.to have_body_text help_page_url('user/profile/user_passwords', anchor: 'change-your-password') end end diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index e753bf2c76c..25afa8b48ce 100644 --- a/spec/mailers/emails/service_desk_spec.rb +++ b/spec/mailers/emails/service_desk_spec.rb @@ -9,11 +9,13 @@ RSpec.describe Emails::ServiceDesk do include EmailHelpers include_context 'gitlab email notification' + include_context 'with service desk mailer' let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:issue) { create(:issue, project: project) } let_it_be(:email) { 'someone@gitlab.com' } + let_it_be(:expected_unsubscribe_url) { unsubscribe_sent_notification_url('b7721fc7e8419911a8bea145236a0519') } let(:template) { double(content: template_content) } @@ -21,43 +23,6 @@ RSpec.describe Emails::ServiceDesk do issue.issue_email_participants.create!(email: email) end - before do - stub_const('ServiceEmailClass', Class.new(ApplicationMailer)) - - ServiceEmailClass.class_eval do - include GitlabRoutingHelper - include EmailsHelper - include Emails::ServiceDesk - - helper GitlabRoutingHelper - helper EmailsHelper - - # this method is implemented in Notify class, we don't need to test it - def reply_key - 'test-key' - end - - # this method is implemented in Notify class, we don't need to test it - def sender(author_id, params = {}) - author_id - end - - # this method is implemented in Notify class - # - # We do not need to test the Notify method, it is already tested in notify_spec - def mail_new_thread(issue, options) - # we need to rewrite this in order to look up templates in the correct directory - self.class.mailer_name = 'notify' - - # this is needed for default layout - @unsubscribe_url = 'http://unsubscribe.example.com' - - mail(options) - end - alias_method :mail_answer_thread, :mail_new_thread - end - end - shared_examples 'handle template content' do |template_key, attachments_count| before do expect(Gitlab::Template::ServiceDeskTemplate).to receive(:find) @@ -70,7 +35,7 @@ RSpec.describe Emails::ServiceDesk do is_expected.to have_referable_subject(issue, include_project: false, reply: reply_in_subject) is_expected.to have_body_text(expected_body) expect(subject.attachments.count).to eq(attachments_count.to_i) - expect(subject.content_type).to include('text/html') + expect(subject.content_type).to include(attachments_count.to_i > 0 ? 'multipart/mixed' : 'text/html') end end end @@ -134,13 +99,31 @@ RSpec.describe Emails::ServiceDesk do it_behaves_like 'handle template content', 'thank_you' end - context 'with an issue id and issue path placeholders' do - let(:template_content) { 'thank you, **your new issue:** %{ISSUE_ID}, path: %{ISSUE_PATH}' } - let(:expected_body) { "thank you, <strong>your new issue:</strong> ##{issue.iid}, path: #{project.full_path}##{issue.iid}" } + context 'with an issue id, issue path and unsubscribe url placeholders' do + let(:template_content) do + 'thank you, **your new issue:** %{ISSUE_ID}, path: %{ISSUE_PATH}' \ + '[Unsubscribe](%{UNSUBSCRIBE_URL})' + end + + let(:expected_body) do + "<p dir=\"auto\">thank you, <strong>your new issue:</strong> ##{issue.iid}, path: #{project.full_path}##{issue.iid}" \ + "<a href=\"#{expected_unsubscribe_url}\">Unsubscribe</a></p>" + end it_behaves_like 'handle template content', 'thank_you' end + context 'with header and footer placeholders' do + let(:template_content) do + '%{SYSTEM_HEADER}' \ + 'thank you, **your new issue** has been created.' \ + '%{SYSTEM_FOOTER}' + end + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + end + context 'with an issue id placeholder with whitespace' do let(:template_content) { 'thank you, **your new issue:** %{ ISSUE_ID}' } let(:expected_body) { "thank you, <strong>your new issue:</strong> ##{issue.iid}" } @@ -174,13 +157,31 @@ RSpec.describe Emails::ServiceDesk do it_behaves_like 'handle template content', 'new_note' end - context 'with an issue id, issue path and note placeholders' do - let(:template_content) { 'thank you, **new note on issue:** %{ISSUE_ID}, path: %{ISSUE_PATH}: %{NOTE_TEXT}' } - let(:expected_body) { "thank you, <strong>new note on issue:</strong> ##{issue.iid}, path: #{project.full_path}##{issue.iid}: #{note.note}" } + context 'with an issue id, issue path, note and unsubscribe url placeholders' do + let(:template_content) do + 'thank you, **new note on issue:** %{ISSUE_ID}, path: %{ISSUE_PATH}: %{NOTE_TEXT}' \ + '[Unsubscribe](%{UNSUBSCRIBE_URL})' + end + + let(:expected_body) do + "<p dir=\"auto\">thank you, <strong>new note on issue:</strong> ##{issue.iid}, path: #{project.full_path}##{issue.iid}: #{note.note}" \ + "<a href=\"#{expected_unsubscribe_url}\">Unsubscribe</a></p>" + end it_behaves_like 'handle template content', 'new_note' end + context 'with header and footer placeholders' do + let(:template_content) do + '%{SYSTEM_HEADER}' \ + 'thank you, **your new issue** has been created.' \ + '%{SYSTEM_FOOTER}' + end + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + end + context 'with an issue id placeholder with whitespace' do let(:template_content) { 'thank you, **new note on issue:** %{ ISSUE_ID}: %{ NOTE_TEXT }' } let(:expected_body) { "thank you, <strong>new note on issue:</strong> ##{issue.iid}: #{note.note}" } |