mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
parent
18010c6a2e
commit
2db401fd98
11 changed files with 197 additions and 11 deletions
|
@ -1,12 +1,12 @@
|
|||
require 'test_helper'
|
||||
|
||||
class APINameserversPatchTest < ActionDispatch::IntegrationTest
|
||||
class APINameserversPutTest < ActionDispatch::IntegrationTest
|
||||
def test_replaces_current_registrar_nameservers
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] } } }
|
||||
put '/repp/v1/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
new_nameserver = registrars(:bestnames).nameservers.find_by(hostname: 'ns55.bestnames.test')
|
||||
assert_nil registrars(:bestnames).nameservers.find_by(hostname: 'ns1.bestnames.test')
|
||||
|
@ -24,14 +24,14 @@ class APINameserversPatchTest < ActionDispatch::IntegrationTest
|
|||
def test_honors_optional_params
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
put '/repp/v1/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
def test_non_existent_nameserver_hostname
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'non-existent.test',
|
||||
attributes: { hostname: 'any.bestnames.test' } } }
|
||||
put '/repp/v1/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 404
|
||||
assert_equal ({ errors: [{ title: 'Hostname non-existent.test does not exist' }] }),
|
||||
|
@ -41,7 +41,7 @@ class APINameserversPatchTest < ActionDispatch::IntegrationTest
|
|||
def test_invalid_request_params
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: '' } } }
|
||||
put '/repp/v1/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 400
|
||||
assert_equal ({ errors: [{ title: 'Invalid params' }] }),
|
||||
|
@ -49,7 +49,7 @@ class APINameserversPatchTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_unauthenticated
|
||||
put '/repp/v1/nameservers'
|
||||
put '/repp/v1/registrar/nameservers'
|
||||
assert_response 401
|
||||
end
|
||||
|
49
test/integration/registrar/nameserver_replacement_test.rb
Normal file
49
test/integration/registrar/nameserver_replacement_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarNameserverReplacementTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
WebMock.reset!
|
||||
login_as users(:api_goodnames)
|
||||
end
|
||||
|
||||
def test_replaces_current_registrar_nameservers
|
||||
request_body = { data: { type: 'nameserver',
|
||||
id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'new-ns.bestnames.test',
|
||||
ipv4: %w[192.0.2.55 192.0.2.56],
|
||||
ipv6: %w[2001:db8::55 2001:db8::56] } } }
|
||||
request_stub = stub_request(:post, /registrar\/nameservers/).with(body: request_body,
|
||||
headers: { 'Content-type' => 'application/json' },
|
||||
basic_auth: ['test_goodnames', 'testtest'])
|
||||
.to_return(body: { data: [{
|
||||
type: 'nameserver',
|
||||
id: 'new-ns.bestnames.test'
|
||||
}] }.to_json, status: 200)
|
||||
|
||||
visit registrar_domains_url
|
||||
click_link 'Replace nameserver'
|
||||
|
||||
fill_in 'Old hostname', with: 'ns1.bestnames.test'
|
||||
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'
|
||||
|
||||
assert_requested request_stub
|
||||
assert_current_path registrar_domains_path
|
||||
assert_text 'Nameserver have been successfully replaced'
|
||||
end
|
||||
|
||||
def test_fails_gracefully
|
||||
stub_request(:post, /registrar\/nameservers/).to_return(status: 400,
|
||||
body: { errors: [{ title: 'epic fail' }] }.to_json,
|
||||
headers: { 'Content-type' => 'application/json' })
|
||||
|
||||
visit registrar_domains_url
|
||||
click_link 'Replace nameserver'
|
||||
|
||||
click_on 'Replace nameserver'
|
||||
|
||||
assert_text 'epic fail'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue