Add affected domain parameter to REST API response

This commit is contained in:
Maciej Szlosarczyk 2018-07-05 17:24:32 +03:00
parent b5f07682f4
commit 3e81366cfc
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
6 changed files with 12 additions and 7 deletions

View file

@ -29,7 +29,7 @@ module Repp
} }
begin begin
current_user.registrar.replace_nameservers(hostname, new_attributes) affected_domains = current_user.registrar.replace_nameservers(hostname, new_attributes)
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
error!({ errors: e.record.errors.full_messages.map { |error| { title: error } } }, 400) error!({ errors: e.record.errors.full_messages.map { |error| { title: error } } }, 400)
end end
@ -37,7 +37,8 @@ module Repp
status 200 status 200
@response = { data: { type: 'nameserver', @response = { data: { type: 'nameserver',
id: params[:data][:attributes][:hostname], id: params[:data][:attributes][:hostname],
attributes: params[:data][:attributes] } } attributes: params[:data][:attributes],
affected_domains: affected_domains } }
end end
end end
end end

View file

@ -145,7 +145,7 @@ class Registrar < ActiveRecord::Base
original_nameserver.destroy! original_nameserver.destroy!
end end
domain_list domain_list.uniq.sort
end end
end end

View file

@ -35,6 +35,7 @@ Content-Type: application/json
"ipv4": ["192.0.2.1", "192.0.2.2"], "ipv4": ["192.0.2.1", "192.0.2.2"],
"ipv6": ["2001:db8::1", "2001:db8::2"] "ipv6": ["2001:db8::1", "2001:db8::2"]
}, },
"affected_domains": ["example.com", "example.org"]
} }
} }
``` ```

View file

@ -41,11 +41,12 @@ class APINameserversPutTest < ActionDispatch::IntegrationTest
assert_equal nameserver_hash, nameservers(:metro_ns1).reload.attributes assert_equal nameserver_hash, nameservers(:metro_ns1).reload.attributes
end end
def test_returns_new_nameserver_record def test_returns_new_nameserver_record_and_affected_domain
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test', request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test', attributes: { hostname: 'ns55.bestnames.test',
ipv4: ['192.0.2.55'], ipv4: ['192.0.2.55'],
ipv6: ['2001:db8::55'] } } } ipv6: ['2001:db8::55'] } } }
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200 assert_response 200
@ -53,7 +54,8 @@ class APINameserversPutTest < ActionDispatch::IntegrationTest
id: 'ns55.bestnames.test', id: 'ns55.bestnames.test',
attributes: { hostname: 'ns55.bestnames.test', attributes: { hostname: 'ns55.bestnames.test',
ipv4: ['192.0.2.55'], ipv4: ['192.0.2.55'],
ipv6: ['2001:db8::55'] } } }), ipv6: ['2001:db8::55'] },
affected_domains: ["airport.test", "shop.test"] } }),
JSON.parse(response.body, symbolize_names: true) JSON.parse(response.body, symbolize_names: true)
end end

View file

@ -16,7 +16,8 @@ class RegistrarAreaNameserverBulkChangeTest < ActionDispatch::IntegrationTest
basic_auth: ['test_goodnames', 'testtest']) basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{ .to_return(body: { data: [{
type: 'nameserver', type: 'nameserver',
id: 'new-ns.bestnames.test' id: 'new-ns.bestnames.test',
affected_domains: ["airport.test", "shop.test"]
}] }.to_json, status: 200) }] }.to_json, status: 200)
visit registrar_domains_url visit registrar_domains_url

View file

@ -5,7 +5,7 @@ class ReplaceNameserversTest < ActiveSupport::TestCase
@registrar = registrars(:bestnames) @registrar = registrars(:bestnames)
end end
def test_replace_nameservers_in_bulk_returns_domain_names def test_replace_nameservers_in_bulk_returns_sorted_domain_names
new_attributes = { hostname: 'ns-updated1.bestnames.test', ipv4: '192.0.3.1', new_attributes = { hostname: 'ns-updated1.bestnames.test', ipv4: '192.0.3.1',
ipv6: '2001:db8::2' } ipv6: '2001:db8::2' }
result = @registrar.replace_nameservers('ns1.bestnames.test', new_attributes) result = @registrar.replace_nameservers('ns1.bestnames.test', new_attributes)