mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +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|
|
||||
domain_name = row['Domain']
|
||||
transfer_code = row['Transfer code']
|
||||
domain_transfers << { 'domainName' => domain_name, 'transferCode' => transfer_code }
|
||||
domain_transfers << { 'domain_name' => domain_name, 'transfer_code' => transfer_code }
|
||||
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.body = { data: { domainTransfers: domain_transfers } }.to_json
|
||||
request.body = { data: { domain_transfers: domain_transfers } }.to_json
|
||||
request.basic_auth(current_registrar_user.username,
|
||||
current_registrar_user.plain_text_password)
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ module Repp
|
|||
|
||||
return if @current_user
|
||||
|
||||
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
|
||||
rescue NoMethodError
|
||||
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
|
||||
end
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ module Repp
|
|||
if @errors.any?
|
||||
render_success(data: { errors: @errors })
|
||||
else
|
||||
render_success(data: successful)
|
||||
render_success(data: @successful)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ module Repp
|
|||
|
||||
def hostname_params
|
||||
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: []]])
|
||||
end
|
||||
|
|
|
@ -69,7 +69,7 @@ Rails.application.routes.draw do
|
|||
namespace :domains do
|
||||
resources :contacts do
|
||||
collection do
|
||||
patch '/', to: 'contacts#update'
|
||||
patch '/', to: 'domains/contacts#update'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,13 +16,20 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
post '/repp/v1/domains/transfer', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 200
|
||||
assert_equal ({ data: [{
|
||||
|
||||
expected_body = {
|
||||
code: 1000,
|
||||
message: 'Command completed successfully',
|
||||
data: [
|
||||
{
|
||||
type: 'domain_transfer',
|
||||
attributes: {
|
||||
domain_name: 'shop.test'
|
||||
},
|
||||
}] }),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
attributes: { domain_name: 'shop.test' },
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
real_body = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(expected_body, real_body)
|
||||
end
|
||||
|
||||
def test_creates_new_domain_transfer
|
||||
|
@ -78,8 +85,8 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
|
||||
def test_fails_if_domain_does_not_exist
|
||||
post '/repp/v1/domains/transfer',
|
||||
params: { data: { domainTransfers: [{ domainName: 'non-existent.test',
|
||||
transferCode: 'any' }] } },
|
||||
params: { data: { domain_transfers: [{ domain_name: 'non-existent.test',
|
||||
transfer_code: 'any' }] } },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 400
|
||||
|
@ -89,8 +96,8 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
|
||||
def test_fails_if_transfer_code_is_wrong
|
||||
post '/repp/v1/domains/transfer',
|
||||
params: { data: { domainTransfers: [{ domainName: 'shop.test',
|
||||
transferCode: 'wrong' }] } },
|
||||
params: { data: { domain_transfers: [{ domain_name: 'shop.test',
|
||||
transfer_code: 'wrong' }] } },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 400
|
||||
|
@ -102,7 +109,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
private
|
||||
|
||||
def request_params
|
||||
{ data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
||||
{ data: { domain_transfers: [{ domain_name: 'shop.test', transfer_code: '65078d5' }] } }
|
||||
end
|
||||
|
||||
def http_auth_key
|
||||
|
|
|
@ -60,14 +60,14 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
|||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 200
|
||||
assert_equal ({ code: '1000',
|
||||
assert_equal ({ code: 1000,
|
||||
message: 'Command completed successfully',
|
||||
data: { type: 'nameserver',
|
||||
id: 'ns55.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] } },
|
||||
affected_domains: ["airport.test", "shop.test"] }),
|
||||
ipv6: ['2001:db8::55'] },
|
||||
affected_domains: ["airport.test", "shop.test"] }}),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
||||
|
@ -87,7 +87,7 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
|||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -98,7 +98,7 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
|||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 400
|
||||
assert_equal ({ code: '2003',
|
||||
assert_equal ({ code: 2003,
|
||||
message: 'param is missing or the value is empty: hostname' }),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
|
|
@ -6,9 +6,9 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
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] }
|
||||
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
|
||||
request_stub = stub_request(:post, /domains\/transfer/).with(body: request_body,
|
||||
headers: headers,
|
||||
basic_auth: ['test_goodnames', 'testtest'])
|
||||
.to_return(body: { data: [{
|
||||
|
@ -29,7 +29,7 @@ class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
|
|||
def test_fail_gracefully
|
||||
body = { errors: [{ title: 'epic fail' }] }.to_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
|
||||
click_link 'Bulk change'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue