diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-05 03:09:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-05 03:09:51 +0300 |
commit | dccf00df717d0ac62355d5139b8c9404aac224dd (patch) | |
tree | 09e5124507a4dac95e49f34c75bddbfe478fb2c9 /spec/mailers | |
parent | f79676861221c1b25a9721f220ab747de7b3f9d0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/emails/service_desk_spec.rb | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index ae676fcf8b1..857d95631be 100644 --- a/spec/mailers/emails/service_desk_spec.rb +++ b/spec/mailers/emails/service_desk_spec.rb @@ -26,6 +26,16 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do issue.issue_email_participants.create!(email: email) end + before do + # Because we use global project and custom email instances, make sure + # custom email is disabled in all regular cases to avoid flakiness. + unless service_desk_setting.custom_email_verification.started? + service_desk_setting.custom_email_verification.mark_as_started!(user) + end + + service_desk_setting.update!(custom_email_enabled: false) unless service_desk_setting.custom_email_enabled? + end + shared_examples 'a service desk notification email' do |attachments_count| it 'builds the email correctly' do aggregate_failures do @@ -42,6 +52,10 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do expect(subject.parts[1].content_type).to include('text/html') end end + + it 'uses system noreply address as Reply-To address' do + expect(subject.reply_to.first).to eq(Gitlab.config.gitlab.email_reply_to) + end end shared_examples 'a service desk notification email with template content' do |template_key, attachments_count| @@ -145,6 +159,41 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do end end + shared_examples 'a service desk notification email that uses custom email' do + before do + # Access via service_desk_setting to avoid flakiness + unless service_desk_setting.custom_email_verification.finished? + service_desk_setting.custom_email_verification.error = nil + service_desk_setting.custom_email_verification.mark_as_finished! + end + + # Reset because we access changed records through these objects + service_desk_setting.reset + project.reset + + service_desk_setting.update!(custom_email_enabled: true) unless service_desk_setting.custom_email_enabled? + end + + it 'uses SMTP delivery method and custom email settings' do + expect_service_desk_custom_email_delivery_options(service_desk_setting) + end + + it 'generates Reply-To address from custom email' do + reply_address = subject.reply_to.first + expected_reply_address = service_desk_setting.custom_email.sub('@', "+#{SentNotification.last.reply_key}@") + + expect(reply_address).to eq(expected_reply_address) + end + + context 'when feature flag service_desk_custom_email_reply is disabled' do + before do + stub_feature_flags(service_desk_custom_email_reply: false) + end + + it { is_expected.to have_header 'Reply-To', /<reply+(.*)@#{Gitlab.config.gitlab.host}>\Z/ } + end + end + describe '.service_desk_thank_you_email' do let_it_be(:reply_in_subject) { true } let_it_be(:expected_text) do @@ -234,6 +283,12 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do end end end + + context 'when custom email is enabled' do + subject { Notify.service_desk_thank_you_email(issue.id) } + + it_behaves_like 'a service desk notification email that uses custom email' + end end describe '.service_desk_new_note_email' do @@ -435,6 +490,12 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do it_behaves_like 'a service desk notification email with template content', 'new_note' end end + + context 'when custom email is enabled' do + subject { Notify.service_desk_new_note_email(issue.id, note.id, email) } + + it_behaves_like 'a service desk notification email that uses custom email' + end end describe '.service_desk_custom_email_verification_email' do @@ -474,7 +535,7 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do end it 'contains verification token' do - is_expected.to have_body_text("Verification token: #{verification.token}") + is_expected.to have_body_text("Verification token: #{service_desk_setting.custom_email_verification.token}") end end |