diff --git a/app/mailers/domain_mailer.rb b/app/mailers/domain_mailer.rb index 06a18b426..b6cd9c309 100644 --- a/app/mailers/domain_mailer.rb +++ b/app/mailers/domain_mailer.rb @@ -1,8 +1,14 @@ class DomainMailer < ApplicationMailer include Que::Mailer - def pending_update_request_for_old_registrant(params) - compose_from(params) + def pending_update_request_for_old_registrant(domain:, registrant:) + @domain = DomainPresenter.new(domain: domain, view: view_context) + @registrar = RegistrarPresenter.new(registrar: domain.registrar, view: view_context) + @registrant = RegistrantPresenter.new(registrant: registrant, view: view_context) + @verification_url = registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) + + subject = default_i18n_subject(domain_name: domain.name) + mail(to: registrant.email, subject: subject) end def pending_update_notification_for_new_registrant(params) diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index 67ae93d68..af523a29e 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -1,17 +1,11 @@ class RegistrantPresenter + delegate :name, :ident, :email, to: :registrant + def initialize(registrant:, view:) @registrant = registrant @view = view end - def name - registrant.name - end - - def ident - registrant.ident - end - private attr_reader :registrant diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb index 9015a8945..4db2d2d9a 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb @@ -1,13 +1,21 @@ Tere

-Registrisse laekus taotlus domeeni <%= @params[:name] %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @params[:registrar_name] %> poole. +Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +

+ <%= @registrar.name %>
+ Email: <%= @registrar.email %>
+ Telefon: <%= @registrar.phone %>
+ Veebileht: <%= @registrar.url %> +

+

Uue registreerija andmed:
-Nimi: <%= @params[:registrant_name] %>
+Nimi: <%= @registrant.name %>
<% if @params[:registrant_priv] %> -Isikukood: <%= @params[:registrant_ident] %>
+Isikukood: <%= @registrant.ident %>
<% else %> -Äriregistrikood: <%= @params[:registrant_ident] %>
+Äriregistrikood: <%= @registrant.ident %>
<% end %> Tänav: <%= @params[:registrant_street] %>
Linn: <%= @params[:registrant_city] %>
@@ -17,7 +25,7 @@ Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatak

Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan:
-<%= link_to @params[:verification_url], @params[:verification_url] %> +<%= link_to @verification_url, @verification_url %>

Lugupidamisega
Eesti Interneti Sihtasutus @@ -26,14 +34,22 @@ Eesti Interneti Sihtasutus

Hi,

-Application for changing registrant of your domain <%= @params[:name] %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @params[:registrar_name] %> +Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar: + +

+ <%= @registrar.name %>
+ Email: <%= @registrar.email %>
+ Phone: <%= @registrar.phone %>
+ Website: <%= @registrar.url %> +

+

New registrant:
-Name: <%= @params[:registrant_name] %>
+Name: <%= @registrant.name %>
<% if @params[:registrant_priv] %> -Personal code: <%= @params[:registrant_ident] %>
+Personal code: <%= @registrant.ident %>
<% else %> -Business Registry code: <%= @params[:registrant_ident] %>
+Business Registry code: <%= @registrant.ident %>
<% end %> Street: <%= @params[:registrant_street] %>
City: <%= @params[:registrant_city] %>
@@ -42,7 +58,7 @@ Country: <%= @params[:registrant_country] %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before.

To confirm the update please visit this website, once again review the data and press approve:
-<%= link_to @params[:verification_url], @params[:verification_url] %> +<%= link_to @verification_url, @verification_url %>

Best Regards,
Estonian Internet Foundation diff --git a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb index d2ee28479..863ef9fa4 100644 --- a/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb +++ b/app/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb @@ -1,13 +1,18 @@ Tere -Registrisse laekus taotlus domeeni <%= @params[:name] %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja <%= @params[:registrar_name] %> poole. +Registrisse laekus taotlus domeeni <%= @domain.name %> registreerija vahetuseks. Palun veenduge, et muudatus on korrektne ning probleemide korral pöörduge oma registripidaja poole: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Telefon: <%= @registrar.phone %> +Veebileht: <%= @registrar.url %> Uue registreerija andmed: -Nimi: <%= @params[:registrant_name] %> +Nimi: <%= @registrant.name %> <% if @params[:registrant_priv] %> -Isikukood: <%= @params[:registrant_ident] %> + Isikukood: <%= @registrant.ident %> <% else %> -Äriregistrikood: <%= @params[:registrant_ident] %> + Äriregistrikood: <%= @registrant.ident %> <% end %> Tänav: <%= @params[:registrant_street] %> Linn: <%= @params[:registrant_city] %> @@ -15,7 +20,7 @@ Riik: <%= @params[:registrant_country] %> Taotlus on aktiivne <%= Setting.expire_pending_confirmation %> tundi ja lükatakse automaatselt tagasi kui te seda enne ei kinnita või tagasi lükka. Muudatuse kinnitamiseks külastage palun allolevat lehekülge, kontrollige uuesti üle muudatuse andmed ning vajutage nuppu kinnitan: -<%= @params[:verification_url] %> +<%= @verification_url %> Lugupidamisega Eesti Interneti Sihtasutus @@ -24,14 +29,19 @@ Eesti Interneti Sihtasutus Hi, -Application for changing registrant of your domain <%= @params[:name] %> has been filed. Please make sure that the update and information are correct. Incase of problems please turn to your registrar. Your registrar is <%= @params[:registrar_name] %> +Application for changing registrant of your domain <%= @domain.name %> has been filed. Please make sure that the update and information are correct. In case of problems please turn to your registrar: + +<%= @registrar.name %> +Email: <%= @registrar.email %> +Phone: <%= @registrar.phone %> +Website: <%= @registrar.url %> New registrant: -Name: <%= @params[:registrant_name] %> +Name: <%= @registrant.name %> <% if @params[:registrant_priv] %> -Personal code: <%= @params[:registrant_ident] %> + Personal code: <%= @registrant.ident %> <% else %> -Business Registry code: <%= @params[:registrant_ident] %> + Business Registry code: <%= @registrant.ident %> <% end %> Street: <%= @params[:registrant_street] %> City: <%= @params[:registrant_city] %> @@ -39,7 +49,7 @@ Country: <%= @params[:registrant_country] %> The application will remain in pending status for <%= Setting.expire_pending_confirmation %> hrs and will be automaticcally rejected if it is not approved nor rejected before. To confirm the update please visit this website, once again review the data and press approve: -<%= @params[:verification_url] %> +<%= @verification_url %> Best Regards, Estonian Internet Foundation diff --git a/config/locales/en.yml b/config/locales/en.yml index cbc61b29c..725dfffc3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -339,7 +339,6 @@ en: contact_details: 'Contact details' ident: 'Ident' ident_type: 'Ident type' - address: 'Address' country: 'Country' city: 'City' street: 'Street' @@ -797,7 +796,6 @@ en: unimplemented_object_service: 'Unimplemented object service' contact_email_update_subject: 'Teie domeenide kontakt epostiaadress on muutunud / Contact e-mail addresses of your domains have changed' object_status_prohibits_operation: 'Object status prohibits operation' - pending_update_request_for_old_registrant_subject: "Kinnitustaotlus domeeni %{name} registreerija vahetuseks / Application for approval for registrant change of %{name}" pending_update_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetus protseduur on algatatud / %{name} registrant change" pending_update_rejected_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus tagasi lükatud / %{name} registrant change declined" pending_update_expired_notification_for_new_registrant_subject: "Domeeni %{name} registreerija vahetuse taotlus on tühistatud / %{name} registrant change cancelled" diff --git a/config/locales/mailers/domain.en.yml b/config/locales/mailers/domain.en.yml index c28ba6b00..f0d021f68 100644 --- a/config/locales/mailers/domain.en.yml +++ b/config/locales/mailers/domain.en.yml @@ -1,5 +1,7 @@ en: domain_mailer: + pending_update_request_for_old_registrant: + subject: Kinnitustaotlus domeeni %{domain_name} registreerija vahetuseks / Application for approval for registrant change of %{domain_name} expiration: subject: The %{domain_name} domain has expired force_delete: diff --git a/spec/mailers/domain_mailer_spec.rb b/spec/mailers/domain_mailer_spec.rb index 1edc35f6a..2363d57ea 100644 --- a/spec/mailers/domain_mailer_spec.rb +++ b/spec/mailers/domain_mailer_spec.rb @@ -1,6 +1,49 @@ require 'rails_helper' RSpec.describe DomainMailer do + describe '#pending_update_request_for_old_registrant' do + let(:domain) { instance_spy(Domain, name: 'test.com') } + let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } + let(:domain_presenter) { instance_spy(DomainPresenter) } + let(:registrar_presenter) { instance_spy(RegistrarPresenter) } + let(:registrant_presenter) { instance_spy(RegistrantPresenter) } + subject(:message) { described_class.pending_update_request_for_old_registrant(domain: domain, + registrant: registrant, + ) } + + 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 registrant email as a recipient' do + expect(message.to).to match_array(['registrant@test.com']) + end + + it 'has subject' do + subject = 'Kinnitustaotlus domeeni test.com registreerija vahetuseks' \ + ' / Application for approval for registrant change of test.com' + + expect(message.subject).to eq(subject) + end + + it 'has confirmation url' do + allow(domain).to receive(:id).and_return(1) + expect(domain).to receive(:registrant_verification_token).and_return('test') + url = registrant_domain_update_confirm_url(domain, token: 'test') + expect(message.body.parts.first.decoded).to include(url) + end + + it 'sends message' do + expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1) + end + end + describe '#pending_deleted' do let(:domain) { instance_spy(Domain, name: 'test.com') } let(:registrant) { instance_spy(Registrant, email: 'registrant@test.com') } diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 0cec65ff6..7e29196de 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -17,4 +17,11 @@ RSpec.describe RegistrantPresenter do expect(presenter.ident).to eq('test ident') end end + + describe '#email' do + it 'returns email' do + expect(registrant).to receive(:email).and_return('test email') + expect(presenter.email).to eq('test email') + end + end end diff --git a/spec/routing/registrant/domain_update_confirms_routing_spec.rb b/spec/routing/registrant/domain_update_confirms_routing_spec.rb new file mode 100644 index 000000000..9bc98c391 --- /dev/null +++ b/spec/routing/registrant/domain_update_confirms_routing_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Registrant::DomainUpdateConfirmsController do + describe 'routing' do + it 'routes to #show' do + expect(get: '/registrant/domain_update_confirms/1').to route_to('registrant/domain_update_confirms#show', id: '1') + end + end +end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb new file mode 100644 index 000000000..36a426bac --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb_spec.rb @@ -0,0 +1,61 @@ +require 'rails_helper' + +RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.html.erb' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 2 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + assign(:verification_url, 'test url') + end + + it 'has verification url' do + mention_count = 1 * lang_count + render + expect(rendered).to have_text('test url', count: mention_count) + end + + registrar_attributes = %i( + name + email + phone + url + ) + + registrar_attributes.each do |attr_name| + it "has registrar #{attr_name}" do + expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}") + render + expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count) + end + end + + domain_attributes = %i( + name + ) + + domain_attributes.each do |attr_name| + it "has :#{attr_name}" do + expect(domain).to receive(attr_name).exactly(lang_count).times.and_return(attr_name.to_s) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end + + registrant_attributes = %i( + name + ident + ) + + registrant_attributes.each do |attr_name| + it "has registrant #{attr_name}" do + expect(registrant).to receive(attr_name).exactly(lang_count).times.and_return("test registrant #{attr_name}") + render + expect(rendered).to have_text("test registrant #{attr_name}", count: lang_count) + end + end +end diff --git a/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb new file mode 100644 index 000000000..da9765873 --- /dev/null +++ b/spec/views/mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb_spec.rb @@ -0,0 +1,61 @@ +require 'rails_helper' + +RSpec.describe 'mailers/domain_mailer/pending_update_request_for_old_registrant.text.erb' do + let(:domain) { instance_spy(DomainPresenter) } + let(:registrar) { instance_spy(RegistrarPresenter) } + let(:registrant) { instance_spy(RegistrantPresenter) } + let(:lang_count) { 2 } + + before :example do + assign(:domain, domain) + assign(:registrar, registrar) + assign(:registrant, registrant) + assign(:verification_url, 'test url') + end + + it 'has verification url' do + mention_count = 1 * lang_count + render + expect(rendered).to have_text('test url', count: mention_count) + end + + registrar_attributes = %i( + name + email + phone + url + ) + + registrar_attributes.each do |attr_name| + it "has registrar #{attr_name}" do + expect(registrar).to receive(attr_name).exactly(lang_count).times.and_return("test registrar #{attr_name}") + render + expect(rendered).to have_text("test registrar #{attr_name}", count: lang_count) + end + end + + domain_attributes = %i( + name + ) + + domain_attributes.each do |attr_name| + it "has :#{attr_name}" do + expect(domain).to receive(attr_name).exactly(lang_count).times.and_return(attr_name.to_s) + render + expect(rendered).to have_text(attr_name.to_s, count: lang_count) + end + end + + registrant_attributes = %i( + name + ident + ) + + registrant_attributes.each do |attr_name| + it "has registrant #{attr_name}" do + expect(registrant).to receive(attr_name).exactly(lang_count).times.and_return("test registrant #{attr_name}") + render + expect(rendered).to have_text("test registrant #{attr_name}", count: lang_count) + end + end +end