FIX: always send critical emails even when bounce score threshold has been reached

This commit is contained in:
Régis Hanol 2017-03-08 10:06:16 +01:00
parent 090236b15b
commit cf8bc4483f
2 changed files with 16 additions and 2 deletions

View File

@ -56,7 +56,7 @@ module Jobs
quoted quoted
} }
CRITICAL_EMAIL_TYPES = Set.new %i{ CRITICAL_EMAIL_TYPES ||= Set.new %w{
account_created account_created
admin_login admin_login
confirm_new_email confirm_new_email
@ -135,7 +135,7 @@ module Jobs
return skip_message(I18n.t('email_log.exceeded_emails_limit')) return skip_message(I18n.t('email_log.exceeded_emails_limit'))
end end
if !CRITICAL_EMAIL_TYPES.include?(type) && user.user_stat.bounce_score >= SiteSetting.bounce_score_threshold if !CRITICAL_EMAIL_TYPES.include?(type.to_s) && user.user_stat.bounce_score >= SiteSetting.bounce_score_threshold
return skip_message(I18n.t('email_log.exceeded_bounces_limit')) return skip_message(I18n.t('email_log.exceeded_bounces_limit'))
end end

View File

@ -35,6 +35,20 @@ describe Jobs::UserEmail do
Jobs::UserEmail.new.execute(type: :digest, user_id: staged.id) Jobs::UserEmail.new.execute(type: :digest, user_id: staged.id)
end end
context "bounce score" do
it "always sends critical emails when bounce score threshold has been reached" do
email_token = Fabricate(:email_token)
user.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold + 1)
Jobs::CriticalUserEmail.new.execute(type: "signup", user_id: user.id, email_token: email_token.token)
email_log = EmailLog.where(user_id: user.id).last
expect(email_log.email_type).to eq("signup")
expect(email_log.skipped).to eq(false)
end
end
context 'to_address' do context 'to_address' do
it 'overwrites a to_address when present' do it 'overwrites a to_address when present' do