mirror of
https://github.com/internetee/registry.git
synced 2025-08-16 06:23:57 +02:00
parent
16afa00442
commit
95c0253a65
2 changed files with 29 additions and 4 deletions
|
@ -4,6 +4,13 @@ class DomainExpireEmailJob < Que::Job
|
||||||
|
|
||||||
return if domain.registered?
|
return if domain.registered?
|
||||||
|
|
||||||
|
log(domain)
|
||||||
DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now
|
DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def log(domain)
|
||||||
|
Rails.logger.info("Send DomainExpireMailer#expired email for domain ##{domain.id} to #{domain.primary_contact_emails.join(', ')}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,19 +8,34 @@ RSpec.describe DomainExpireEmailJob do
|
||||||
expect(Domain).to receive(:find).and_return(domain)
|
expect(Domain).to receive(:find).and_return(domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after :example do
|
||||||
|
described_class.enqueue(domain_id: 1)
|
||||||
|
end
|
||||||
|
|
||||||
context 'when domain is expired' do
|
context 'when domain is expired' do
|
||||||
let(:message) { instance_double(ActionMailer::MessageDelivery) }
|
let(:message) { instance_double(ActionMailer::MessageDelivery) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
allow(domain).to receive(:registrar).and_return('registrar')
|
allow(domain).to receive_messages(
|
||||||
allow(domain).to receive(:registered?).and_return(false)
|
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
|
end
|
||||||
|
|
||||||
it 'sends email notification' do
|
it 'sends email notification' do
|
||||||
expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar')
|
expect(DomainExpireMailer).to receive(:expired).with(domain: domain, registrar: 'registrar')
|
||||||
.and_return(message)
|
.and_return(message)
|
||||||
expect(message).to receive(:deliver_now)
|
expect(message).to receive(:deliver_now)
|
||||||
described_class.enqueue(domain_id: 1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,9 +44,12 @@ RSpec.describe DomainExpireEmailJob do
|
||||||
allow(domain).to receive(:registered?).and_return(true)
|
allow(domain).to receive(:registered?).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not create log record' do
|
||||||
|
expect(Rails.logger).to_not receive(:info)
|
||||||
|
end
|
||||||
|
|
||||||
it 'does not send email notification' do
|
it 'does not send email notification' do
|
||||||
expect(DomainExpireMailer).to_not receive(:expired)
|
expect(DomainExpireMailer).to_not receive(:expired)
|
||||||
described_class.enqueue(domain_id: 1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue