Update emails' content

Closes #1127
This commit is contained in:
Artur Beljajev 2019-03-26 22:42:40 +02:00
parent f35b2dc36c
commit 5d63feb0a5
43 changed files with 262 additions and 816 deletions

View file

@ -1,109 +0,0 @@
require 'rails_helper'
RSpec.describe DomainDeleteMailer do
describe '#confirm' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrar) { instance_spy(Registrar) }
let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
subject(:message) { described_class.confirm(domain: domain,
registrar: registrar,
registrant: registrant)
}
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 registrant\'s email as a recipient' do
expect(message.to).to match_array(['registrant@test.com'])
end
it 'has subject' do
subject = 'Kinnitustaotlus domeeni test.com kustutamiseks .ee registrist' \
' / Application for approval for deletion of test.com'
expect(message.subject).to eq(subject)
end
it 'has confirm url' do
allow(domain).to receive(:id).and_return(1)
expect(domain).to receive(:registrant_verification_token).and_return('test')
url = registrant_domain_delete_confirm_url(domain, token: 'test')
expect(message.body.parts.first.decoded).to include(url)
end
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
describe '#forced' do
let(:domain) { instance_spy(Domain, name: 'test.com') }
let(:registrant) { instance_spy(Registrant) }
let(:template_name) { 'removed_company' }
let(:domain_presenter) { instance_spy(DomainPresenter) }
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
let(:registrant_presenter) { instance_spy(RegistrantPresenter) }
subject(:message) { described_class.forced(domain: domain,
registrar: 'registrar',
registrant: registrant,
template_name: template_name)
}
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
expect(RegistrantPresenter).to receive(:new).and_return(registrant_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
subject = 'Domeen test.com on kustutusmenetluses' \
' / Domain test.com is in deletion process' \
' / Домен test.com в процессе удаления'
expect(message.subject).to eq(subject)
end
context 'when template is :death' do
let(:template_name) { 'death' }
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
context 'when registrant is private entity' do
let(:registrant) { build_stubbed(:registrant_private_entity) }
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
context 'when registrant is legal entity' do
let(:registrant) { build_stubbed(:registrant_legal_entity) }
it 'sends message' do
expect { message.deliver_now }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
end
end

View file

@ -1,71 +0,0 @@
require 'rails_helper'
RSpec.describe DomainExpireMailer do
describe '#expired' do
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: nil) }
before :example do
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
end
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 'logs valid emails' do
log_message = 'Send DomainExpireMailer#expired email for domain test.com (#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
context 'when some recipient is invalid' do
let(:recipient) { %w[invalid_email valid@test.com] }
before :example do
allow(described_class.logger).to receive(:info)
end
it 'does not deliver to invalid recipient' do
expect(message.to).to match_array(%w[valid@test.com])
end
it 'does not log invalid email in success message' do
log_message = 'Send DomainExpireMailer#expired email for domain test.com (#1) to valid@test.com'
expect(described_class.logger).to receive(:info).with(log_message)
message.deliver_now
end
it 'logs invalid email in error message' do
log_message = 'Unable to send DomainExpireMailer#expired email for domain test.com (#1) to' \
' invalid recipient invalid_email'
expect(described_class.logger).to receive(:info).with(log_message)
message.deliver_now
end
end
end
end

View file

@ -240,16 +240,6 @@ end
RSpec.describe Contact do
it { is_expected.to alias_attribute(:kind, :ident_type) }
describe '::names' do
before :example do
expect(described_class).to receive(:pluck).with(:name).and_return('names')
end
it 'returns names' do
expect(described_class.names).to eq('names')
end
end
describe '::emails' do
before :example do
expect(described_class).to receive(:pluck).with(:email).and_return('emails')

View file

@ -696,70 +696,6 @@ RSpec.describe Domain do
end
end
describe '#admin_contact_names' do
let(:domain) { described_class.new }
before :example do
expect(Contact).to receive(:names).and_return('names')
end
it 'returns admin contact names' do
expect(domain.admin_contact_names).to eq('names')
end
end
describe '#admin_contact_emails' do
let(:domain) { described_class.new }
before :example do
expect(Contact).to receive(:emails).and_return('emails')
end
it 'returns admin contact emails' do
expect(domain.admin_contact_emails).to eq('emails')
end
end
describe '#tech_contact_names' do
let(:domain) { described_class.new }
before :example do
expect(Contact).to receive(:names).and_return('names')
end
it 'returns technical contact names' do
expect(domain.tech_contact_names).to eq('names')
end
end
describe '#nameserver_hostnames' do
let(:domain) { described_class.new }
before :example do
expect(Nameserver).to receive(:hostnames).and_return('hostnames')
end
it 'returns name server hostnames' do
expect(domain.nameserver_hostnames).to eq('hostnames')
end
end
describe '#primary_contact_emails' do
let(:domain) { described_class.new }
before :example do
expect(domain).to receive(:registrant_email).and_return('registrant@test.com')
expect(domain).to receive(:admin_contact_emails).and_return(%w(admin.contact@test.com admin.contact@test.com))
end
it 'returns unique list of registrant and administrative contact emails' do
expect(domain.primary_contact_emails).to match_array(%w(
registrant@test.com
admin.contact@test.com
))
end
end
describe '#set_graceful_expired' do
let(:domain) { described_class.new }

View file

@ -78,42 +78,6 @@ RSpec.describe DomainPresenter do
end
end
describe '#admin_contact_names' do
let(:domain) { instance_double(Domain) }
before :example do
expect(domain).to receive(:admin_contact_names).and_return(%w(test1 test2 test3))
end
it 'returns admin contact names' do
expect(presenter.admin_contact_names).to eq('test1, test2, test3')
end
end
describe '#tech_contact_names' do
let(:domain) { instance_double(Domain) }
before :example do
expect(domain).to receive(:tech_contact_names).and_return(%w(test1 test2 test3))
end
it 'returns technical contact names' do
expect(presenter.tech_contact_names).to eq('test1, test2, test3')
end
end
describe '#nameserver_names' do
let(:domain) { instance_double(Domain) }
before :example do
expect(domain).to receive(:nameserver_hostnames).and_return(%w(test1 test2 test3))
end
it 'returns nameserver names' do
expect(presenter.nameserver_names).to eq('test1, test2, test3')
end
end
domain_delegatable_attributes = %i(
name
transfer_code

View file

@ -1,12 +0,0 @@
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

View file

@ -1,12 +0,0 @@
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

View file

@ -1,53 +0,0 @@
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

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.en.html.erb' do
include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.en.html.erb'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.en.text.erb' do
include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.en.text.erb'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.et.html.erb' do
include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.et.html.erb'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrant_shared'
RSpec.describe 'mailers/shared/registrant/_registrant.et.text.erb' do
include_examples 'domain mailer registrant info', 'mailers/shared/registrant/_registrant.et.text.erb'
end

View file

@ -1,87 +0,0 @@
require 'rails_helper'
RSpec.shared_examples 'domain mailer registrant info' do |template_path|
let(:template_path) { template_path }
let(:registrant) { instance_spy(RegistrantPresenter) }
before :example do
without_partial_double_verification do
allow(view).to receive(:registrant).and_return(registrant)
allow(view).to receive(:address_processing)
end
end
it 'has name' do
allow(registrant).to receive(:name).and_return('test name')
render template: template_path
expect(rendered).to have_text('test name')
end
it 'has ident' do
allow(registrant).to receive(:ident).and_return('test ident')
render template: template_path
expect(rendered).to have_text('test ident')
end
context 'when :with_phone is true' do
it 'has phone' do
allow(registrant).to receive(:phone).and_return('test phone')
render template: template_path, locals: { with_phone: true }
expect(rendered).to have_text('test phone')
end
end
context 'when :with_phone is false' do
it 'has no phone' do
allow(registrant).to receive(:phone).and_return('test phone')
render template: template_path, locals: { with_phone: false }
expect(rendered).to_not have_text('test phone')
end
end
address_attributes = %i[street city state zip country]
context 'when address processing is enabled' do
before :example do
without_partial_double_verification do
allow(view).to receive(:address_processing).and_return(true)
end
end
address_attributes.each do |attr_name|
it "has #{attr_name}" do
allow(registrant).to receive(attr_name).and_return("test #{attr_name}")
render template: template_path
expect(rendered).to have_text("test #{attr_name}")
end
end
it 'has no ident country' do
allow(registrant).to receive(:ident_country).and_return('test ident country')
render template: template_path
expect(rendered).to_not have_text('test ident country')
end
end
context 'when address processing is disabled' do
before :example do
without_partial_double_verification do
allow(view).to receive(:address_processing).and_return(false)
end
end
address_attributes.each do |attr_name|
it "has no #{attr_name}" do
allow(registrant).to receive(attr_name).and_return("test #{attr_name}")
render template: template_path
expect(rendered).to_not have_text("test #{attr_name}")
end
end
it 'has ident country' do
allow(registrant).to receive(:ident_country).and_return('test ident country')
render template: template_path
expect(rendered).to have_text('test ident country')
end
end
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrar_shared'
RSpec.describe 'mailers/shared/registrar/_registrar.en.html.erb' do
include_examples 'domain mailer registrar info'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrar_shared'
RSpec.describe 'mailers/shared/registrar/_registrar.en.text.erb' do
include_examples 'domain mailer registrar info'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrar_shared'
RSpec.describe 'mailers/shared/registrar/_registrar.et.html.erb' do
include_examples 'domain mailer registrar info'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrar_shared'
RSpec.describe 'mailers/shared/registrar/_registrar.et.text.erb' do
include_examples 'domain mailer registrar info'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrar_shared'
RSpec.describe 'mailers/shared/registrar/_registrar.ru.html.erb' do
include_examples 'domain mailer registrar info'
end

View file

@ -1,6 +0,0 @@
require 'rails_helper'
require_relative 'registrar_shared'
RSpec.describe 'mailers/shared/registrar/_registrar.ru.text.erb' do
include_examples 'domain mailer registrar info'
end

View file

@ -1,26 +0,0 @@
require 'rails_helper'
RSpec.shared_examples 'domain mailer registrar info' do
let(:registrar) { instance_spy(RegistrarPresenter) }
before :example do
without_partial_double_verification do
allow(view).to receive(:registrar).and_return(registrar)
end
end
attributes = %i(
name
email
phone
website
)
attributes.each do |attr_name|
it "has #{attr_name}" do
expect(registrar).to receive(attr_name).and_return("test #{attr_name}")
render
expect(rendered).to have_text("test #{attr_name}")
end
end
end