mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
parent
97426e001b
commit
fa47eb3ab6
13 changed files with 129 additions and 43 deletions
|
@ -1,10 +1,10 @@
|
|||
class DomainExpirationEmailJob < Que::Job
|
||||
def run(domain_id:)
|
||||
def run(domain_id)
|
||||
domain = Domain.find(domain_id)
|
||||
|
||||
return if domain.registered?
|
||||
|
||||
DomainMailer.expiration(domain: domain).deliver
|
||||
DomainExpireMailer.expired(domain: domain, registrar: domain.registrar).deliver_now
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
|
9
app/mailers/domain_expire_mailer.rb
Normal file
9
app/mailers/domain_expire_mailer.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class DomainExpireMailer < ApplicationMailer
|
||||
def expired(domain:, registrar:)
|
||||
@domain = DomainPresenter.new(domain: domain, view: view_context)
|
||||
@registrar = RegistrarPresenter.new(registrar: registrar, view: view_context)
|
||||
|
||||
subject = default_i18n_subject(domain_name: domain.name)
|
||||
mail(to: domain.primary_contact_emails, subject: subject)
|
||||
end
|
||||
end
|
|
@ -83,14 +83,6 @@ class DomainMailer < ApplicationMailer
|
|||
mail(to: domain.primary_contact_emails)
|
||||
end
|
||||
|
||||
def expiration(domain:)
|
||||
@domain = DomainPresenter.new(domain: domain, view: view_context)
|
||||
@registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context)
|
||||
|
||||
subject = default_i18n_subject(domain_name: domain.name)
|
||||
mail(to: domain.primary_contact_emails, subject: subject)
|
||||
end
|
||||
|
||||
private
|
||||
# app/models/DomainMailModel provides the data for mail that can be composed_from
|
||||
# which ensures that values of objects are captured when they are valid, not later when this method is executed
|
||||
|
|
|
@ -49,7 +49,7 @@ class DomainCron
|
|||
saved = domain.save(validate: false)
|
||||
|
||||
if saved
|
||||
DomainExpirationEmailJob.enqueue(domain_id: domain.id, run_at: send_time)
|
||||
DomainExpirationEmailJob.enqueue(domain.id, run_at: send_time)
|
||||
marked += 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
en:
|
||||
delete_domain_mailer:
|
||||
pending:
|
||||
subject: Kinnitustaotlus domeeni %{domain_name} kustutamiseks .ee registrist / Application for approval for deletion of %{domain_name}
|
||||
domain_mailer:
|
||||
force_delete:
|
||||
subject: Kustutusmenetluse teade
|
||||
|
|
4
config/locales/mailers/domain_expire.en.yml
Normal file
4
config/locales/mailers/domain_expire.en.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
en:
|
||||
domain_expire_mailer:
|
||||
expired:
|
||||
subject: The %{domain_name} domain has expired
|
33
spec/mailers/domain_expire_mailer_spec.rb
Normal file
33
spec/mailers/domain_expire_mailer_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainExpireMailer do
|
||||
describe '#expired' do
|
||||
let(:domain) { instance_spy(Domain, name: 'test.com') }
|
||||
let(:registrar) { 'registrar' }
|
||||
let(:domain_presenter) { instance_spy(DomainPresenter) }
|
||||
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
|
||||
subject(:message) { described_class.expired(domain: domain, registrar: registrar) }
|
||||
|
||||
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'])
|
||||
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
|
||||
|
||||
it 'has subject' do
|
||||
expect(message.subject).to eq('The test.com domain has expired')
|
||||
end
|
||||
|
||||
it 'sends message' do
|
||||
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -31,33 +31,4 @@ RSpec.describe DomainMailer do
|
|||
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expiration' do
|
||||
let(:domain) { instance_spy(Domain, name: 'test.com') }
|
||||
let(:domain_presenter) { instance_spy(DomainPresenter) }
|
||||
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
|
||||
subject(:message) { described_class.expiration(domain: domain) }
|
||||
|
||||
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'])
|
||||
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
|
||||
|
||||
it 'has valid subject' do
|
||||
expect(message.subject).to eq('The test.com domain has expired')
|
||||
end
|
||||
|
||||
it 'sends message' do
|
||||
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
require 'rails_helper'
|
||||
require_relative 'expired_shared'
|
||||
|
||||
RSpec.describe 'mailers/domain_expire_mailer/expired.html.erb' do
|
||||
before :example do
|
||||
stub_template 'mailers/shared/registrar/_registrar.et.html' => 'test registrar estonian'
|
||||
stub_template 'mailers/shared/registrar/_registrar.en.html' => 'test registrar english'
|
||||
stub_template 'mailers/shared/registrar/_registrar.ru.html' => 'test registrar russian'
|
||||
end
|
||||
|
||||
include_examples 'domain expire mailer expired'
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
require 'rails_helper'
|
||||
require_relative 'expired_shared'
|
||||
|
||||
RSpec.describe 'mailers/domain_expire_mailer/expired.text.erb' do
|
||||
before :example do
|
||||
stub_template 'mailers/shared/registrar/_registrar.et.text' => 'test registrar estonian'
|
||||
stub_template 'mailers/shared/registrar/_registrar.en.text' => 'test registrar english'
|
||||
stub_template 'mailers/shared/registrar/_registrar.ru.text' => 'test registrar russian'
|
||||
end
|
||||
|
||||
include_examples 'domain expire mailer expired'
|
||||
end
|
53
spec/views/mailers/domain_expire_mailer/expired_shared.rb
Normal file
53
spec/views/mailers/domain_expire_mailer/expired_shared.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.shared_examples 'domain expire mailer expired' do
|
||||
let(:domain) { instance_spy(DomainPresenter) }
|
||||
let(:registrar) { instance_spy(RegistrarPresenter) }
|
||||
let(:registrant) { instance_spy(RegistrantPresenter) }
|
||||
let(:lang_count) { 3 }
|
||||
|
||||
before :example do
|
||||
assign(:domain, domain)
|
||||
assign(:registrar, registrar)
|
||||
assign(:registrant, registrant)
|
||||
end
|
||||
|
||||
it 'has registrar info in estonian' do
|
||||
render
|
||||
expect(rendered).to have_text('test registrar estonian')
|
||||
end
|
||||
|
||||
it 'has registrar info in english' do
|
||||
render
|
||||
expect(rendered).to have_text('test registrar english')
|
||||
end
|
||||
|
||||
it 'has registrar info in russian' do
|
||||
render
|
||||
expect(rendered).to have_text('test registrar russian')
|
||||
end
|
||||
|
||||
it 'has domain name' do
|
||||
mention_count = 4 * lang_count
|
||||
expect(domain).to receive(:name).exactly(mention_count).times.and_return('test domain name')
|
||||
render
|
||||
expect(rendered).to have_text('test domain name', count: mention_count)
|
||||
end
|
||||
|
||||
domain_attributes = %i(
|
||||
on_hold_date
|
||||
delete_date
|
||||
registrant_name
|
||||
admin_contact_names
|
||||
tech_contact_names
|
||||
nameserver_names
|
||||
)
|
||||
|
||||
domain_attributes.each do |attr_name|
|
||||
it "has domain #{attr_name}" do
|
||||
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return("test domain #{attr_name}")
|
||||
render
|
||||
expect(rendered).to have_text("test domain #{attr_name}", count: lang_count)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue