summaryrefslogtreecommitdiff
path: root/spec/mailers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/mailers
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/devise_mailer_spec.rb4
-rw-r--r--spec/mailers/emails/imports_spec.rb29
-rw-r--r--spec/mailers/emails/profile_spec.rb10
-rw-r--r--spec/mailers/emails/service_desk_spec.rb106
4 files changed, 137 insertions, 12 deletions
diff --git a/spec/mailers/devise_mailer_spec.rb b/spec/mailers/devise_mailer_spec.rb
index b8e768b7a5f..6eb0e817803 100644
--- a/spec/mailers/devise_mailer_spec.rb
+++ b/spec/mailers/devise_mailer_spec.rb
@@ -131,6 +131,10 @@ RSpec.describe DeviseMailer do
it 'includes a link to reset the password' do
is_expected.to have_link("Reset password", href: "#{Gitlab.config.gitlab.url}/users/password/edit?reset_password_token=faketoken")
end
+
+ it 'has the mailgun suppression bypass header' do
+ is_expected.to have_header 'X-Mailgun-Suppressions-Bypass', 'true'
+ end
end
describe '#email_changed' do
diff --git a/spec/mailers/emails/imports_spec.rb b/spec/mailers/emails/imports_spec.rb
new file mode 100644
index 00000000000..039113d3098
--- /dev/null
+++ b/spec/mailers/emails/imports_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'email_spec'
+
+RSpec.describe Emails::Imports, feature_category: :importers do
+ include EmailSpec::Matchers
+
+ let(:errors) { { 'gist_id1' => "Title can't be blank", 'gist_id2' => 'Snippet maximum file count exceeded' } }
+ let(:user) { build_stubbed(:user) }
+
+ describe '#github_gists_import_errors_email' do
+ subject { Notify.github_gists_import_errors_email('user_id', errors) }
+
+ before do
+ allow(User).to receive(:find).and_return(user)
+ end
+
+ it 'sends success email' do
+ expect(subject).to have_subject('GitHub Gists import finished with errors')
+ expect(subject).to have_content('GitHub gists that were not imported:')
+ expect(subject).to have_content("Gist with id gist_id1 failed due to error: Title can't be blank.")
+ expect(subject).to have_content('Gist with id gist_id2 failed due to error: Snippet maximum file count exceeded.')
+ end
+
+ it_behaves_like 'appearance header and footer enabled'
+ it_behaves_like 'appearance header and footer not enabled'
+ end
+end
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb
index cdc298d685e..1fd2a92866d 100644
--- a/spec/mailers/emails/profile_spec.rb
+++ b/spec/mailers/emails/profile_spec.rb
@@ -198,9 +198,10 @@ RSpec.describe Emails::Profile do
describe 'user personal access token has expired' do
let_it_be(:user) { create(:user) }
+ let_it_be(:pat) { create(:personal_access_token, user: user) }
context 'when valid' do
- subject { Notify.access_token_expired_email(user) }
+ subject { Notify.access_token_expired_email(user, [pat.name]) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
@@ -211,11 +212,12 @@ RSpec.describe Emails::Profile do
end
it 'has the correct subject' do
- is_expected.to have_subject /Your personal access token has expired/
+ is_expected.to have_subject /Your personal access tokens have expired/
end
it 'mentions the access token has expired' do
- is_expected.to have_body_text /One or more of your personal access tokens has expired/
+ is_expected.to have_body_text /The following personal access tokens have expired:/
+ is_expected.to have_body_text /#{pat.name}/
end
it 'includes a link to personal access tokens page' do
@@ -279,7 +281,7 @@ RSpec.describe Emails::Profile do
end
context 'when source is provided' do
- subject { Notify.access_token_revoked_email(user, token.name, 'secret_detection') }
+ subject { Notify.access_token_revoked_email(user, token.name, :secret_detection) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb
index 1523d9b986b..e753bf2c76c 100644
--- a/spec/mailers/emails/service_desk_spec.rb
+++ b/spec/mailers/emails/service_desk_spec.rb
@@ -58,7 +58,7 @@ RSpec.describe Emails::ServiceDesk do
end
end
- shared_examples 'handle template content' do |template_key|
+ shared_examples 'handle template content' do |template_key, attachments_count|
before do
expect(Gitlab::Template::ServiceDeskTemplate).to receive(:find)
.with(template_key, issue.project)
@@ -69,6 +69,7 @@ RSpec.describe Emails::ServiceDesk do
aggregate_failures 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')
end
end
@@ -195,13 +196,102 @@ RSpec.describe Emails::ServiceDesk do
end
context 'with upload link in the note' do
- let_it_be(:upload_path) { '/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg' }
- let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "a new comment with [file](#{upload_path})") }
-
- let(:template_content) { 'some text %{ NOTE_TEXT }' }
- let(:expected_body) { %Q(some text a new comment with <a href="#{project.web_url}#{upload_path}" data-canonical-src="#{upload_path}" data-link="true" class="gfm">file</a>) }
-
- it_behaves_like 'handle template content', 'new_note'
+ let_it_be(:secret) { 'e90decf88d8f96fe9e1389afc2e4a91f' }
+ let_it_be(:filename) { 'test.jpg' }
+ let_it_be(:path) { "#{secret}/#{filename}" }
+ let_it_be(:upload_path) { "/uploads/#{path}" }
+ let_it_be(:template_content) { 'some text %{ NOTE_TEXT }' }
+ let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "a new comment with [#{filename}](#{upload_path})") }
+ let!(:upload) { create(:upload, :issuable_upload, :with_file, model: note.project, path: path, secret: secret) }
+
+ context 'when total uploads size is more than 10mb' do
+ before do
+ allow_next_instance_of(FileUploader) do |instance|
+ allow(instance).to receive(:size).and_return(10.1.megabytes)
+ end
+ end
+
+ let_it_be(:expected_body) { %Q(some text a new comment with <a href="#{project.web_url}#{upload_path}" data-canonical-src="#{upload_path}" data-link="true" class="gfm">#{filename}</a>) }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
+
+ context 'when total uploads size is less or equal 10mb' do
+ context 'when it has only one upload' do
+ before do
+ allow_next_instance_of(FileUploader) do |instance|
+ allow(instance).to receive(:size).and_return(10.megabytes)
+ end
+ end
+
+ context 'when upload name is not changed in markdown' do
+ let_it_be(:expected_body) { %Q(some text a new comment with <strong>#{filename}</strong>) }
+
+ it_behaves_like 'handle template content', 'new_note', 1
+ end
+
+ context 'when upload name is changed in markdown' do
+ let_it_be(:upload_name_in_markdown) { 'Custom name' }
+ let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "a new comment with [#{upload_name_in_markdown}](#{upload_path})") }
+ let_it_be(:expected_body) { %Q(some text a new comment with <strong>#{upload_name_in_markdown} (#{filename})</strong>) }
+
+ it_behaves_like 'handle template content', 'new_note', 1
+ end
+ end
+
+ context 'when it has more than one upload' do
+ before do
+ allow_next_instance_of(FileUploader) do |instance|
+ allow(instance).to receive(:size).and_return(5.megabytes)
+ end
+ end
+
+ let_it_be(:secret_1) { '17817c73e368777e6f743392e334fb8a' }
+ let_it_be(:filename_1) { 'test1.jpg' }
+ let_it_be(:path_1) { "#{secret_1}/#{filename_1}" }
+ let_it_be(:upload_path_1) { "/uploads/#{path_1}" }
+ let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "a new comment with [#{filename}](#{upload_path}) [#{filename_1}](#{upload_path_1})") }
+
+ context 'when all uploads processed correct' do
+ let_it_be(:upload_1) { create(:upload, :issuable_upload, :with_file, model: note.project, path: path_1, secret: secret_1) }
+ let_it_be(:expected_body) { %Q(some text a new comment with <strong>#{filename}</strong> <strong>#{filename_1}</strong>) }
+
+ it_behaves_like 'handle template content', 'new_note', 2
+ end
+
+ context 'when not all uploads processed correct' do
+ let_it_be(:expected_body) { %Q(some text a new comment with <strong>#{filename}</strong> <a href="#{project.web_url}#{upload_path_1}" data-canonical-src="#{upload_path_1}" data-link="true" class="gfm">#{filename_1}</a>) }
+
+ it_behaves_like 'handle template content', 'new_note', 1
+ end
+ end
+ end
+
+ context 'when UploaderFinder is raising error' do
+ before do
+ allow_next_instance_of(UploaderFinder) do |instance|
+ allow(instance).to receive(:execute).and_raise(StandardError)
+ end
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(StandardError, project_id: note.project_id)
+ end
+
+ let_it_be(:expected_body) { %Q(some text a new comment with <a href="#{project.web_url}#{upload_path}" data-canonical-src="#{upload_path}" data-link="true" class="gfm">#{filename}</a>) }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
+
+ context 'when FileUploader is raising error' do
+ before do
+ allow_next_instance_of(FileUploader) do |instance|
+ allow(instance).to receive(:read).and_raise(StandardError)
+ end
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(StandardError, project_id: note.project_id)
+ end
+
+ let_it_be(:expected_body) { %Q(some text a new comment with <a href="#{project.web_url}#{upload_path}" data-canonical-src="#{upload_path}" data-link="true" class="gfm">#{filename}</a>) }
+
+ it_behaves_like 'handle template content', 'new_note'
+ end
end
context 'with all-user reference in a an external author comment' do