0
0
Fork 0

Convert notification mailer spec shared examples to matchers (#32047)

This commit is contained in:
Matt Jankowski 2024-09-24 08:07:16 -04:00 committed by GitHub
parent 7c61533111
commit 780e2e9d66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 32 deletions

View file

@ -12,3 +12,32 @@ RSpec.shared_examples 'localized subject' do |*args, **kwrest|
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: I18n.default_locale))
end
end
RSpec::Matchers.define :have_thread_headers do
match(notify_expectation_failures: true) do |mail|
expect(mail)
.to be_present
.and(have_header('In-Reply-To', conversation_header_regex))
.and(have_header('References', conversation_header_regex))
end
def conversation_header_regex = /<conversation-\d+.\d\d\d\d-\d\d-\d\d@cb6e6126.ngrok.io>/
end
RSpec::Matchers.define :have_standard_headers do |type|
chain :for do |user|
@user = user
end
match(notify_expectation_failures: true) do |mail|
expect(mail)
.to be_present
.and(have_header('To', "#{@user.account.username} <#{@user.email}>"))
.and(have_header('List-ID', "<#{type}.#{@user.account.username}.#{Rails.configuration.x.local_domain}>"))
.and(have_header('List-Unsubscribe', %r{<https://#{Rails.configuration.x.local_domain}/unsubscribe\?token=.+>}))
.and(have_header('List-Unsubscribe', /&type=#{type}/))
.and(have_header('List-Unsubscribe-Post', 'List-Unsubscribe=One-Click'))
.and(deliver_to("#{@user.account.username} <#{@user.email}>"))
.and(deliver_from(Rails.configuration.action_mailer.default_options[:from]))
end
end