diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 9269a1102..9366174ef 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,15 @@ class ApplicationMailer < ActionMailer::Base append_view_path Rails.root.join('app', 'views', 'mailers') layout 'mailer' -end \ No newline at end of file + + def registrant_confirm_url(domain:, method:) + token = domain.registrant_verification_token + base_url = ENV['registrant_portal_verifications_base_url'] + + url = registrant_domain_delete_confirm_url(domain, token: token) if method == 'delete' + url ||= registrant_domain_update_confirm_url(domain, token: token) + return url if base_url.blank? + + "#{base_url}/confirms/#{domain.name_puny}/#{method}/#{token}" + end +end diff --git a/app/mailers/domain_delete_mailer.rb b/app/mailers/domain_delete_mailer.rb index 8e2b1a341..8c0e830b1 100644 --- a/app/mailers/domain_delete_mailer.rb +++ b/app/mailers/domain_delete_mailer.rb @@ -6,7 +6,7 @@ class DomainDeleteMailer < ApplicationMailer def confirmation_request(domain:, registrar:, registrant:) @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) - @confirmation_url = confirmation_url(domain) + @confirmation_url = registrant_confirm_url(domain: domain, method: 'delete') subject = default_i18n_subject(domain_name: domain.name) mail(to: registrant.email, subject: subject) @@ -52,15 +52,6 @@ class DomainDeleteMailer < ApplicationMailer private - def confirmation_url(domain) - base_url = ENV['registrant_portal_verifications_base_url'] - if base_url.blank? - registrant_domain_delete_confirm_url(domain, token: domain.registrant_verification_token) - else - "#{base_url}/confirmation/#{domain.name_puny}/delete/#{domain.registrant_verification_token}" - end - end - def forced_email_from ENV['action_mailer_force_delete_from'] || self.class.default[:from] end diff --git a/app/mailers/registrant_change_mailer.rb b/app/mailers/registrant_change_mailer.rb index 3e97f4b86..8f43f4ab5 100644 --- a/app/mailers/registrant_change_mailer.rb +++ b/app/mailers/registrant_change_mailer.rb @@ -5,7 +5,7 @@ class RegistrantChangeMailer < ApplicationMailer @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) @new_registrant = RegistrantPresenter.new(registrant: new_registrant, view: view_context) - @confirmation_url = confirmation_url(domain) + @confirmation_url = registrant_confirm_url(domain: domain, method: 'change') subject = default_i18n_subject(domain_name: domain.name) mail(to: current_registrant.email, subject: subject) @@ -49,15 +49,6 @@ class RegistrantChangeMailer < ApplicationMailer private - def confirmation_url(domain) - base_url = ENV['registrant_portal_verifications_base_url'] - if base_url.blank? - registrant_domain_update_confirm_url(domain, token: domain.registrant_verification_token) - else - "#{base_url}/confirmation/#{domain.name_puny}/change/#{domain.registrant_verification_token}" - end - end - def address_processing Contact.address_processing? end diff --git a/test/integration/api/registrant/registrant_api_verifications_test.rb b/test/integration/api/registrant/registrant_api_verifications_test.rb index b2333e560..821d0dee0 100644 --- a/test/integration/api/registrant/registrant_api_verifications_test.rb +++ b/test/integration/api/registrant/registrant_api_verifications_test.rb @@ -8,17 +8,22 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest @domain = domains(:hospital) @registrant = @domain.registrant @new_registrant = contacts(:jack) + @user = users(:api_bestnames) @token = 'verysecrettoken' - @domain.update(statuses: [DomainStatus::PENDING_UPDATE], + @domain.update!(statuses: [DomainStatus::PENDING_UPDATE], registrant_verification_asked_at: Time.zone.now - 1.day, registrant_verification_token: @token) end def test_fetches_registrant_change_request - pending_json = { new_registrant_id: @new_registrant.id } + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + @domain.update(pending_json: pending_json) @domain.reload @@ -46,31 +51,40 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest end def test_approves_registrant_change_request - pending_json = { new_registrant_id: @new_registrant.id } - @domain.update(pending_json: pending_json) + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + + @domain.update!(pending_json: pending_json) @domain.reload assert @domain.registrant_update_confirmable?(@token) - post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/confirmed" - assert_equal(200, response.status) + perform_enqueued_jobs do + post "/api/v1/registrant/confirms/#{@domain.name_puny}/change/#{@token}/confirmed" + assert_equal(200, response.status) - res = JSON.parse(response.body, symbolize_names: true) - expected_body = { - domain_name: @domain.name, - current_registrant: { - name: @new_registrant.name, - ident: @new_registrant.ident, - country: @new_registrant.ident_country_code - }, - status: 'confirmed' - } - - assert_equal expected_body, res + res = JSON.parse(response.body, symbolize_names: true) + expected_body = { + domain_name: @domain.name, + current_registrant: { + name: @new_registrant.name, + ident: @new_registrant.ident, + country: @new_registrant.ident_country_code + }, + status: 'confirmed' + } + assert_equal expected_body, res + end end def test_rejects_registrant_change_request - pending_json = { new_registrant_id: @new_registrant.id } + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + @domain.update(pending_json: pending_json) @domain.reload @@ -94,7 +108,11 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest end def test_registrant_change_requires_valid_attributes - pending_json = { new_registrant_id: @new_registrant.id } + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + @domain.update(pending_json: pending_json) @domain.reload @@ -109,7 +127,12 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest end def test_fetches_domain_delete_request - @domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + + @domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) @domain.reload assert @domain.registrant_delete_confirmable?(@token) @@ -131,8 +154,13 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest end def test_approves_domain_delete_request - @domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) - @domain.reload + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + + @domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) + @domain.reload assert @domain.registrant_delete_confirmable?(@token) @@ -154,8 +182,13 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest end def test_rejects_domain_delete_request - @domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) - @domain.reload + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + + @domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) + @domain.reload assert @domain.registrant_delete_confirmable?(@token) @@ -177,7 +210,12 @@ class RegistrantApiVerificationsTest < ApplicationIntegrationTest end def test_domain_delete_requires_valid_attributes - @domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::PENDING_DELETE]) + pending_json = { new_registrant_id: @new_registrant.id, + new_registrant_name: @new_registrant.name, + new_registrant_email: @new_registrant.email, + current_user_id: @user.id } + + @domain.update(pending_json: pending_json, statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION]) @domain.reload get "/api/v1/registrant/confirms/#{@domain.name_puny}/delete/123"