diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-14 15:07:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-14 15:07:42 +0300 |
commit | cacc3815006ab7d3828ebe8903f95154b27a6e21 (patch) | |
tree | 5adc693664d1ca383d19f8f165b37eea2318387f /spec/mailers | |
parent | ce684df4733d86a49126792721f549612a778590 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/emails/service_desk_spec.rb | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index 1f55aabc535..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) @@ -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}" } |