Skip to content

Commit

Permalink
Make sure what expired domain emails will not be sent to non-valid ad…
Browse files Browse the repository at this point in the history
…dreses
  • Loading branch information
yulgolem committed Mar 22, 2021
1 parent 91093b2 commit 29f7aa1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
9 changes: 7 additions & 2 deletions app/mailers/domain_expire_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def registrar_presenter(registrar:)

# Needed because there are invalid emails in the database, which have been imported from legacy app
def filter_invalid_emails(emails:, domain:)
emails.select do |email|
valid = EmailValidator.new(email).valid?
old_validation_type = Truemail.configure.default_validation_type
Truemail.configure.default_validation_type = :regex

results = emails.select do |email|
valid = Truemail.valid?(email)

unless valid
logger.info("Unable to send DomainExpireMailer#expired email for domain #{domain.name} (##{domain.id})" \
Expand All @@ -53,5 +56,7 @@ def filter_invalid_emails(emails:, domain:)

valid
end
Truemail.configure.default_validation_type = old_validation_type
results
end
end
2 changes: 1 addition & 1 deletion app/presenters/domain_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DomainPresenter
delegate :name, :transfer_code, :registrant, :registrant_id, to: :domain
delegate :name, :transfer_code, :registrant, :registrant_id, :id, to: :domain

def initialize(domain:, view:)
@domain = domain
Expand Down
15 changes: 0 additions & 15 deletions lib/validators/email_validator.rb

This file was deleted.

25 changes: 25 additions & 0 deletions test/mailers/domain_expire_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,29 @@ def test_delivers_domain_expiration_soft_email
assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name),
email.subject
end

def test_delivers_domain_expiration_soft_email_if_auto_fd
domain = domains(:shop)
assert_not domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
email = 'some@[email protected]'

Truemail.configure.default_validation_type = :regex

contact = domain.admin_contacts.first
contact.update_attribute(:email, email)
contact.email_verification.verify

assert contact.email_verification_failed?

domain.reload

assert domain.force_delete_scheduled?

email = DomainExpireMailer.expired_soft(domain: domain, registrar: domain.registrar).deliver_now

assert_emails 1
assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name),
email.subject
end
end

0 comments on commit 29f7aa1

Please sign in to comment.