Log DomainDelete#confirm, DomainDelete#forced, DomainExpire#expired, RegistrantChange#confirm emails sending

#186
This commit is contained in:
Artur Beljajev 2016-11-22 23:21:01 +02:00
parent 95c0253a65
commit 64be27fe53
8 changed files with 167 additions and 4 deletions

View file

@ -2,8 +2,20 @@ class DomainDeleteConfirmEmailJob < Que::Job
def run(domain_id)
domain = Domain.find(domain_id)
log(domain)
DomainDeleteMailer.confirm(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant).deliver_now
end
private
def log(domain)
message = "Send DomainDeleteMailer#confirm email for domain ##{domain.id} to #{domain.registrant_email}"
logger.info(message)
end
def logger
Rails.logger
end
end

View file

@ -2,8 +2,21 @@ class DomainDeleteForcedEmailJob < Que::Job
def run(domain_id)
domain = Domain.find(domain_id)
log(domain)
DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant).deliver_now
end
private
def log(domain)
message = "Send DomainDeleteMailer#forced email for domain ##{domain.id} to #{domain.primary_contact_emails
.join(', ')}"
logger.info(message)
end
def logger
Rails.logger
end
end

View file

@ -11,6 +11,11 @@ class DomainExpireEmailJob < Que::Job
private
def log(domain)
Rails.logger.info("Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}")
message = "Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}"
logger.info(message)
end
def logger
Rails.logger
end
end

View file

@ -3,9 +3,21 @@ class RegistrantChangeConfirmEmailJob < Que::Job
domain = Domain.find(domain_id)
new_registrant = Registrant.find(new_registrant_id)
log(domain)
RegistrantChangeMailer.confirm(domain: domain,
registrar: domain.registrar,
current_registrant: domain.registrant,
new_registrant: new_registrant).deliver_now
end
private
def log(domain)
message = "Send RegistrantChangeMailer#confirm email for domain ##{domain.id} to #{domain.registrant_email}"
logger.info(message)
end
def logger
Rails.logger
end
end

View file

@ -0,0 +1,39 @@
require 'rails_helper'
RSpec.describe DomainDeleteConfirmEmailJob do
describe '#run' do
let(:domain) { instance_double(Domain) }
let(:message) { instance_double(ActionMailer::MessageDelivery) }
before :example do
expect(Domain).to receive(:find).and_return(domain)
allow(domain).to receive_messages(
id: 1,
registrant_email: 'registrant@test.com',
registrar: 'registrar',
registrant: 'registrant')
end
after :example do
domain_id = 1
described_class.enqueue(domain_id)
end
it 'creates log record' do
log_message = 'Send DomainDeleteMailer#confirm email for domain #1 to registrant@test.com'
allow(DomainDeleteMailer).to receive(:confirm).and_return(message)
allow(message).to receive(:deliver_now)
expect(Rails.logger).to receive(:info).with(log_message)
end
it 'sends email' do
expect(DomainDeleteMailer).to receive(:confirm).with(domain: domain,
registrar: 'registrar',
registrant: 'registrant')
.and_return(message)
expect(message).to receive(:deliver_now)
end
end
end

View file

@ -0,0 +1,39 @@
require 'rails_helper'
RSpec.describe DomainDeleteForcedEmailJob do
describe '#run' do
let(:domain) { instance_double(Domain) }
let(:message) { instance_double(ActionMailer::MessageDelivery) }
before :example do
expect(Domain).to receive(:find).and_return(domain)
allow(domain).to receive_messages(
id: 1,
registrar: 'registrar',
registrant: 'registrant',
primary_contact_emails: %w(test@test.com test@test.com))
end
after :example do
domain_id = 1
described_class.enqueue(domain_id)
end
it 'creates log record' do
log_message = 'Send DomainDeleteMailer#forced email for domain #1 to test@test.com, test@test.com'
allow(DomainDeleteMailer).to receive(:forced).and_return(message)
allow(message).to receive(:deliver_now)
expect(Rails.logger).to receive(:info).with(log_message)
end
it 'sends email' do
expect(DomainDeleteMailer).to receive(:forced).with(domain: domain,
registrar: 'registrar',
registrant: 'registrant')
.and_return(message)
expect(message).to receive(:deliver_now)
end
end
end

View file

@ -9,7 +9,8 @@ RSpec.describe DomainExpireEmailJob do
end
after :example do
described_class.enqueue(domain_id: 1)
domain_id = 1
described_class.enqueue(domain_id)
end
context 'when domain is expired' do
@ -32,7 +33,7 @@ RSpec.describe DomainExpireEmailJob do
expect(Rails.logger).to receive(:info).with(log_message)
end
it 'sends email notification' do
it 'sends email' do
expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar')
.and_return(message)
expect(message).to receive(:deliver_now)
@ -48,7 +49,7 @@ RSpec.describe DomainExpireEmailJob do
expect(Rails.logger).to_not receive(:info)
end
it 'does not send email notification' do
it 'does not send email' do
expect(DomainExpireMailer).to_not receive(:expired)
end
end

View file

@ -0,0 +1,42 @@
require 'rails_helper'
RSpec.describe RegistrantChangeConfirmEmailJob do
describe '#run' do
let(:domain) { instance_double(Domain) }
let(:message) { instance_double(ActionMailer::MessageDelivery) }
before :example do
expect(Domain).to receive(:find).and_return(domain)
expect(Registrant).to receive(:find).and_return('new registrant')
allow(domain).to receive_messages(
id: 1,
registrant_email: 'registrant@test.com',
registrar: 'registrar',
registrant: 'registrant')
end
after :example do
domain_id = 1
new_registrant_id = 1
described_class.enqueue(domain_id, new_registrant_id)
end
it 'creates log record' do
log_message = 'Send RegistrantChangeMailer#confirm email for domain #1 to registrant@test.com'
allow(RegistrantChangeMailer).to receive(:confirm).and_return(message)
allow(message).to receive(:deliver_now)
expect(Rails.logger).to receive(:info).with(log_message)
end
it 'sends email' do
expect(RegistrantChangeMailer).to receive(:confirm).with(domain: domain,
registrar: 'registrar',
current_registrant: 'registrant',
new_registrant: 'new registrant')
.and_return(message)
expect(message).to receive(:deliver_now)
end
end
end