mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Handle invalid emails in DomainExpireMailer#expired, move logging from job to mailer
#186
This commit is contained in:
parent
a5c0333a5d
commit
e6e3ab9e1e
4 changed files with 78 additions and 43 deletions
|
@ -18,21 +18,11 @@ RSpec.describe DomainExpireEmailJob do
|
|||
|
||||
before :example do
|
||||
allow(domain).to receive_messages(
|
||||
id: 1,
|
||||
registrar: 'registrar',
|
||||
registered?: false,
|
||||
primary_contact_emails: %w(test@test.com test@test.com))
|
||||
end
|
||||
|
||||
it 'creates log record' do
|
||||
log_message = 'Send DomainExpireMailer#expired email for domain #1 to test@test.com, test@test.com'
|
||||
|
||||
allow(DomainExpireMailer).to receive(:expired).and_return(message)
|
||||
allow(message).to receive(:deliver_now)
|
||||
|
||||
expect(Rails.logger).to receive(:info).with(log_message)
|
||||
end
|
||||
|
||||
it 'sends email' do
|
||||
expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar')
|
||||
.and_return(message)
|
||||
|
@ -45,10 +35,6 @@ RSpec.describe DomainExpireEmailJob do
|
|||
allow(domain).to receive(:registered?).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not create log record' do
|
||||
expect(Rails.logger).to_not receive(:info)
|
||||
end
|
||||
|
||||
it 'does not send email' do
|
||||
expect(DomainExpireMailer).to_not receive(:expired)
|
||||
end
|
||||
|
|
|
@ -2,32 +2,64 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe DomainExpireMailer do
|
||||
describe '#expired' do
|
||||
let(:domain) { instance_spy(Domain, name: 'test.com') }
|
||||
let(:registrar) { 'registrar' }
|
||||
let(:domain) { instance_spy(Domain,
|
||||
id: 1,
|
||||
name: 'test.com',
|
||||
primary_contact_emails: recipient)
|
||||
}
|
||||
let(:domain_presenter) { instance_spy(DomainPresenter) }
|
||||
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
|
||||
subject(:message) { described_class.expired(domain: domain, registrar: registrar) }
|
||||
subject(:message) { described_class.expired(domain: domain, registrar: nil) }
|
||||
|
||||
before :example do
|
||||
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
|
||||
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
|
||||
end
|
||||
|
||||
it 'has sender' do
|
||||
expect(message.from).to eq(['noreply@internet.ee'])
|
||||
context 'when all recipients are valid' do
|
||||
let(:recipient) { %w[recipient@test.com recipient@test.com] }
|
||||
|
||||
it 'has sender' do
|
||||
expect(message.from).to eq(['noreply@internet.ee'])
|
||||
end
|
||||
|
||||
it 'delivers to all recipients' do
|
||||
expect(message.to).to match_array(%w[recipient@test.com recipient@test.com])
|
||||
end
|
||||
|
||||
it 'has subject' do
|
||||
expect(message.subject).to eq('The test.com domain has expired')
|
||||
end
|
||||
|
||||
it 'creates log record' do
|
||||
log_message = 'Send DomainExpireMailer#expired email for domain #1 to recipient@test.com,' \
|
||||
' recipient@test.com'
|
||||
expect(described_class.logger).to receive(:info).with(log_message)
|
||||
message.deliver_now
|
||||
end
|
||||
|
||||
it 'sends message' do
|
||||
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'has recipient' do
|
||||
expect(domain).to receive(:primary_contact_emails).and_return(['recipient@test.com'])
|
||||
expect(message.to).to match_array(['recipient@test.com'])
|
||||
end
|
||||
context 'when some recipient is invalid' do
|
||||
let(:recipient) { %w[invalid_email valid@test.com] }
|
||||
|
||||
it 'has subject' do
|
||||
expect(message.subject).to eq('The test.com domain has expired')
|
||||
end
|
||||
before :example do
|
||||
allow(described_class.logger).to receive(:info)
|
||||
end
|
||||
|
||||
it 'sends message' do
|
||||
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
it 'does not deliver to invalid recipient' do
|
||||
expect(message.to).to match_array(%w[valid@test.com])
|
||||
end
|
||||
|
||||
it 'creates log record' do
|
||||
log_message = 'Unable to send DomainExpireMailer#expired email for domain #1 to' \
|
||||
' invalid recipient invalid_email'
|
||||
expect(described_class.logger).to receive(:info).with(log_message)
|
||||
message.deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue