mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 15:44:45 +02:00
Fix tests
This commit is contained in:
parent
27774cc275
commit
a6f7af0f03
8 changed files with 35 additions and 26 deletions
|
@ -15,12 +15,12 @@ class Registrar
|
||||||
csv.each do |row|
|
csv.each do |row|
|
||||||
domain_name = row['Domain']
|
domain_name = row['Domain']
|
||||||
transfer_code = row['Transfer code']
|
transfer_code = row['Transfer code']
|
||||||
domain_transfers << { 'domainName' => domain_name, 'transferCode' => transfer_code }
|
domain_transfers << { 'domain_name' => domain_name, 'transfer_code' => transfer_code }
|
||||||
end
|
end
|
||||||
|
|
||||||
uri = URI.parse("#{ENV['repp_url']}domain_transfers")
|
uri = URI.parse("#{ENV['repp_url']}domains/transfer")
|
||||||
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
||||||
request.body = { data: { domainTransfers: domain_transfers } }.to_json
|
request.body = { data: { domain_transfers: domain_transfers } }.to_json
|
||||||
request.basic_auth(current_registrar_user.username,
|
request.basic_auth(current_registrar_user.username,
|
||||||
current_registrar_user.plain_text_password)
|
current_registrar_user.plain_text_password)
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@ module Repp
|
||||||
|
|
||||||
return if @current_user
|
return if @current_user
|
||||||
|
|
||||||
|
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
|
||||||
|
rescue NoMethodError
|
||||||
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
|
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Repp
|
||||||
if @errors.any?
|
if @errors.any?
|
||||||
render_success(data: { errors: @errors })
|
render_success(data: { errors: @errors })
|
||||||
else
|
else
|
||||||
render_success(data: successful)
|
render_success(data: @successful)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Repp
|
||||||
|
|
||||||
def hostname_params
|
def hostname_params
|
||||||
params.require(:data).require(%i[type id])
|
params.require(:data).require(%i[type id])
|
||||||
params.require(:data).require(:attributes).require(%i[hostname ipv4 ipv6])
|
params.require(:data).require(:attributes)
|
||||||
|
|
||||||
params.permit(data: [:type, :id, attributes: [:hostname, ipv4: [], ipv6: []]])
|
params.permit(data: [:type, :id, attributes: [:hostname, ipv4: [], ipv6: []]])
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,7 +69,7 @@ Rails.application.routes.draw do
|
||||||
namespace :domains do
|
namespace :domains do
|
||||||
resources :contacts do
|
resources :contacts do
|
||||||
collection do
|
collection do
|
||||||
patch '/', to: 'contacts#update'
|
patch '/', to: 'domains/contacts#update'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,13 +16,20 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
||||||
post '/repp/v1/domains/transfer', params: request_params, as: :json,
|
post '/repp/v1/domains/transfer', params: request_params, as: :json,
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response 200
|
assert_response 200
|
||||||
assert_equal ({ data: [{
|
|
||||||
|
expected_body = {
|
||||||
|
code: 1000,
|
||||||
|
message: 'Command completed successfully',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
type: 'domain_transfer',
|
type: 'domain_transfer',
|
||||||
attributes: {
|
attributes: { domain_name: 'shop.test' },
|
||||||
domain_name: 'shop.test'
|
}
|
||||||
},
|
]
|
||||||
}] }),
|
}
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
|
||||||
|
real_body = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
assert_equal(expected_body, real_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_new_domain_transfer
|
def test_creates_new_domain_transfer
|
||||||
|
@ -78,8 +85,8 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
def test_fails_if_domain_does_not_exist
|
def test_fails_if_domain_does_not_exist
|
||||||
post '/repp/v1/domains/transfer',
|
post '/repp/v1/domains/transfer',
|
||||||
params: { data: { domainTransfers: [{ domainName: 'non-existent.test',
|
params: { data: { domain_transfers: [{ domain_name: 'non-existent.test',
|
||||||
transferCode: 'any' }] } },
|
transfer_code: 'any' }] } },
|
||||||
as: :json,
|
as: :json,
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response 400
|
assert_response 400
|
||||||
|
@ -89,8 +96,8 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
def test_fails_if_transfer_code_is_wrong
|
def test_fails_if_transfer_code_is_wrong
|
||||||
post '/repp/v1/domains/transfer',
|
post '/repp/v1/domains/transfer',
|
||||||
params: { data: { domainTransfers: [{ domainName: 'shop.test',
|
params: { data: { domain_transfers: [{ domain_name: 'shop.test',
|
||||||
transferCode: 'wrong' }] } },
|
transfer_code: 'wrong' }] } },
|
||||||
as: :json,
|
as: :json,
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response 400
|
assert_response 400
|
||||||
|
@ -102,7 +109,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
||||||
private
|
private
|
||||||
|
|
||||||
def request_params
|
def request_params
|
||||||
{ data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
{ data: { domain_transfers: [{ domain_name: 'shop.test', transfer_code: '65078d5' }] } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def http_auth_key
|
def http_auth_key
|
||||||
|
|
|
@ -60,14 +60,14 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
assert_response 200
|
assert_response 200
|
||||||
assert_equal ({ code: '1000',
|
assert_equal ({ code: 1000,
|
||||||
message: 'Command completed successfully',
|
message: 'Command completed successfully',
|
||||||
data: { type: 'nameserver',
|
data: { type: 'nameserver',
|
||||||
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"] }),
|
affected_domains: ["airport.test", "shop.test"] }}),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
assert_response 404
|
assert_response 404
|
||||||
assert_equal ({ errors: [{ title: 'Hostname non-existent.test does not exist' }] }),
|
assert_equal ({code: 2303, message: 'Object does not exist' }),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
assert_response 400
|
assert_response 400
|
||||||
assert_equal ({ code: '2003',
|
assert_equal ({ code: 2003,
|
||||||
message: 'param is missing or the value is empty: hostname' }),
|
message: 'param is missing or the value is empty: hostname' }),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,9 +6,9 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_transfer_multiple_domains_in_bulk
|
def test_transfer_multiple_domains_in_bulk
|
||||||
request_body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
request_body = { data: { domain_transfers: [{ domain_name: 'shop.test', transfer_code: '65078d5' }] } }
|
||||||
headers = { 'Content-type' => Mime[:json] }
|
headers = { 'Content-type' => Mime[:json] }
|
||||||
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
|
request_stub = stub_request(:post, /domains\/transfer/).with(body: request_body,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
basic_auth: ['test_goodnames', 'testtest'])
|
basic_auth: ['test_goodnames', 'testtest'])
|
||||||
.to_return(body: { data: [{
|
.to_return(body: { data: [{
|
||||||
|
@ -29,7 +29,7 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
|
||||||
def test_fail_gracefully
|
def test_fail_gracefully
|
||||||
body = { errors: [{ title: 'epic fail' }] }.to_json
|
body = { errors: [{ title: 'epic fail' }] }.to_json
|
||||||
headers = { 'Content-type' => Mime[:json] }
|
headers = { 'Content-type' => Mime[:json] }
|
||||||
stub_request(:post, /domain_transfers/).to_return(status: 400, body: body, headers: headers)
|
stub_request(:post, /domains\/transfer/).to_return(status: 400, body: body, headers: headers)
|
||||||
|
|
||||||
visit registrar_domains_url
|
visit registrar_domains_url
|
||||||
click_link 'Bulk change'
|
click_link 'Bulk change'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue