diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index 37d95dbe2..9bf31d1d7 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -32,7 +32,8 @@ class Registrar end def compose_notice_message(res) - notices = ["#{t('.replaced')}. #{t('.affected_domains')}: " \ + action_text = params[:old_hostname].blank? ? t('.added') : t('.replaced') + notices = ["#{action_text}. #{t('.affected_domains')}: " \ "#{res[:data][:affected_domains].join(', ')}"] notices << "#{t('.skipped_domains')}: #{res[:data][:skipped_domains].join(', ')}" if res[:data][:skipped_domains] @@ -42,7 +43,7 @@ class Registrar def csv_list_empty_guard notice = 'CSV scoped domain list seems empty. Make sure that domains are added and ' \ - '"domain_name" header is present.' + '"Domain" header is present.' redirect_to(registrar_domains_url, flash: { notice: notice }) end @@ -52,9 +53,9 @@ class Registrar domains = [] csv = CSV.read(params[:puny_file].path, headers: true) - return [] if csv['domain_name'].blank? + return [] if csv['Domain'].blank? - csv.map { |b| domains << b['domain_name'] } + csv.map { |b| domains << b['Domain'] } domains.compact rescue CSV::MalformedCSVError diff --git a/config/locales/registrar/bulk_change.en.yml b/config/locales/registrar/bulk_change.en.yml index f669f468f..8d5a6d9eb 100644 --- a/config/locales/registrar/bulk_change.en.yml +++ b/config/locales/registrar/bulk_change.en.yml @@ -34,7 +34,7 @@ en: nameserver_form: old_hostname: Old hostname (optional) ip_hint: One IP per line - replace_btn: Replace nameserver + replace_btn: Replace/Add nameserver help_btn: Toggle help help: >- Replace nameserver specified in the "old hostname" with the one in "new hostname" with diff --git a/config/locales/registrar/nameservers.en.yml b/config/locales/registrar/nameservers.en.yml index 9c1c2a70e..15a2623e9 100644 --- a/config/locales/registrar/nameservers.en.yml +++ b/config/locales/registrar/nameservers.en.yml @@ -3,5 +3,6 @@ en: nameservers: update: replaced: Nameserver have been successfully replaced + added: Nameserver have been successfully added affected_domains: Affected domains skipped_domains: Untouched domains diff --git a/test/fixtures/files/valid_domains_for_ns_replacement.csv b/test/fixtures/files/valid_domains_for_ns_replacement.csv index 122301ca8..3ff8ebfa2 100644 --- a/test/fixtures/files/valid_domains_for_ns_replacement.csv +++ b/test/fixtures/files/valid_domains_for_ns_replacement.csv @@ -1,2 +1,2 @@ -domain_name +Domain shop.test diff --git a/test/system/registrar_area/bulk_change/nameserver_test.rb b/test/system/registrar_area/bulk_change/nameserver_test.rb index 287265cdf..306c75424 100644 --- a/test/system/registrar_area/bulk_change/nameserver_test.rb +++ b/test/system/registrar_area/bulk_change/nameserver_test.rb @@ -31,7 +31,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase fill_in 'New hostname', with: 'new-ns.bestnames.test' fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' assert_requested request_stub assert_current_path registrar_domains_path @@ -52,7 +52,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase fill_in 'New hostname', with: 'new hostname' fill_in 'ipv4', with: 'ipv4' fill_in 'ipv6', with: 'ipv6' - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' assert_text 'epic fail' assert_field 'Old hostname', with: 'old hostname' @@ -63,7 +63,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase def test_replaces_nameservers_only_for_scoped_domains request_body = { data: { type: 'nameserver', - id: 'ns1.bestnames.test', + id: 'ns1.bestnames.test', domains: ['shop.test'], attributes: { hostname: 'new-ns.bestnames.test', ipv4: %w[192.0.2.55 192.0.2.56], @@ -87,7 +87,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_ns_replacement.csv').to_s - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' assert_requested request_stub assert_current_path registrar_domains_path @@ -109,10 +109,76 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'invalid_domains_for_ns_replacement.csv').to_s assert_no_changes -> { nameserver.hostname } do - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' end - assert_current_path registrar_domains_path - assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and "domain_name" header is present.' + assert_current_path registrar_domains_path + assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and "Domain" header is present.' + end + + def test_replaces_current_registrar_nameservers + request_body = { data: { type: 'nameserver', + id: '', + domains: [], + attributes: { hostname: 'new-ns2.bestnames.test', + ipv4: %w[192.0.2.55 192.0.2.56], + ipv6: %w[2001:db8::55 2001:db8::56] } } } + request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body, + headers: { 'Content-type' => Mime[:json] }, + basic_auth: ['test_goodnames', 'testtest']) + .to_return(body: { data: { + type: 'nameserver', + id: 'new-ns2.bestnames.test', + affected_domains: ["airport.test", "shop.test"], + skipped_domains: [] + } + }.to_json, status: 200) + + visit registrar_domains_url + click_link 'Bulk change' + click_link 'Nameserver' + + fill_in 'New hostname', with: 'new-ns2.bestnames.test' + fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" + fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" + click_on 'Replace/Add nameserver' + + assert_requested request_stub + assert_current_path registrar_domains_path + assert_text 'Nameserver have been successfully added' + assert_text 'Affected domains: airport.test, shop.test' + end + + def test_adding_nameservers_only_for_scoped_domains + request_body = { data: { type: 'nameserver', + id: '', + domains: ['shop.test'], + attributes: { hostname: 'new-ns1.bestnames.test', + ipv4: %w[192.0.2.55 192.0.2.56], + ipv6: %w[2001:db8::55 2001:db8::56] } } } + request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body, + headers: { 'Content-type' => Mime[:json] }, + basic_auth: ['test_goodnames', 'testtest']) + .to_return(body: { data: { + type: 'nameserver', + id: 'new-ns1.bestnames.test', + affected_domains: ["shop.test"], + skipped_domains: []}}.to_json, status: 200) + + visit registrar_domains_url + click_link 'Bulk change' + click_link 'Nameserver' + + fill_in 'New hostname', with: 'new-ns1.bestnames.test' + fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" + fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" + attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_ns_replacement.csv').to_s + + click_on 'Replace/Add nameserver' + + assert_requested request_stub + assert_current_path registrar_domains_path + assert_text 'Nameserver have been successfully added' + assert_text 'Affected domains: shop.test' end end