mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
Fix tests
This commit is contained in:
parent
f2a1ee101b
commit
220e0d7993
6 changed files with 29 additions and 31 deletions
|
@ -59,9 +59,12 @@ module Repp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_epp_error(status = :bad_request)
|
def render_epp_error(status = :bad_request, data = {})
|
||||||
|
@epp_errors ||= []
|
||||||
|
@epp_errors << { code: 2304, msg: 'Command failed' } if data != {}
|
||||||
|
|
||||||
render(
|
render(
|
||||||
json: { code: @epp_errors[0][:code], message: @epp_errors[0][:msg] },
|
json: { code: @epp_errors[0][:code], message: @epp_errors[0][:msg], data: data },
|
||||||
status: status
|
status: status
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,12 +16,15 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@epp_errors << { code: '2304', msg: 'New contact must be valid' } if @new_contact.invalid?
|
@epp_errors ||= []
|
||||||
|
@epp_errors << { code: 2304, msg: 'New contact must be valid' } if @new_contact.invalid?
|
||||||
|
|
||||||
if @new_contact == @current_contact
|
if @new_contact == @current_contact
|
||||||
@epp_errors << { code: '2304', msg: 'New contact must be different from current' }
|
@epp_errors << { code: 2304, msg: 'New contact must be different from current' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return handle_errors if @epp_errors.any?
|
||||||
|
|
||||||
affected, skipped = TechDomainContact.replace(@current_contact, @new_contact)
|
affected, skipped = TechDomainContact.replace(@current_contact, @new_contact)
|
||||||
data = { affected_domains: affected, skipped_domains: skipped }
|
data = { affected_domains: affected, skipped_domains: skipped }
|
||||||
render_success(data: data)
|
render_success(data: data)
|
||||||
|
|
|
@ -34,7 +34,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
if @errors.any?
|
if @errors.any?
|
||||||
render_success(data: { errors: @errors })
|
render_epp_error(:bad_request, @errors)
|
||||||
else
|
else
|
||||||
render_success(data: @successful)
|
render_success(data: @successful)
|
||||||
end
|
end
|
||||||
|
@ -52,10 +52,11 @@ module Repp
|
||||||
domain = Domain.find_by(name: domain_name)
|
domain = Domain.find_by(name: domain_name)
|
||||||
# rubocop:disable Style/AndOr
|
# rubocop:disable Style/AndOr
|
||||||
add_error("#{domain_name} does not exist") and return unless domain
|
add_error("#{domain_name} does not exist") and return unless domain
|
||||||
valid_transfer_code = domain.transfer_code.eql?(transfer_code)
|
|
||||||
add_error("#{domain_name} transfer code is wrong") and return unless valid_transfer_code
|
|
||||||
# rubocop:enable Style/AndOr
|
# rubocop:enable Style/AndOr
|
||||||
|
unless domain.transfer_code.eql?(transfer_code)
|
||||||
|
add_error("#{domain_name} transfer code is wrong")
|
||||||
|
return
|
||||||
|
end
|
||||||
domain
|
domain
|
||||||
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)
|
params.require(:data).require(:attributes).require([:hostname])
|
||||||
|
|
||||||
params.permit(data: [:type, :id, attributes: [:hostname, ipv4: [], ipv6: []]])
|
params.permit(data: [:type, :id, attributes: [:hostname, ipv4: [], ipv6: []]])
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,8 +27,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_equal ({ affected_domains: %w[airport.test shop.test],
|
assert_equal ({ code: 1000, message: 'Command completed successfully', data: { affected_domains: %w[airport.test shop.test],
|
||||||
skipped_domains: [] }),
|
skipped_domains: [] }}),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_equal %w[airport.test shop.test], JSON.parse(response.body,
|
assert_equal %w[airport.test shop.test], JSON.parse(response.body,
|
||||||
symbolize_names: true)[:skipped_domains]
|
symbolize_names: true)[:data][:skipped_domains]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_keep_other_tech_contacts_intact
|
def test_keep_other_tech_contacts_intact
|
||||||
|
@ -66,10 +66,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
new_contact_id: 'william-002' },
|
new_contact_id: 'william-002' },
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
|
||||||
assert_response :bad_request
|
assert_response :not_found
|
||||||
assert_equal ({ error: { type: 'invalid_request_error',
|
assert_equal ({ code: 2303, message: 'Object does not exist' }),
|
||||||
param: 'current_contact_id',
|
|
||||||
message: 'No such contact: jack-001' } }),
|
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,10 +75,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'non-existent',
|
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'non-existent',
|
||||||
new_contact_id: 'john-001' },
|
new_contact_id: 'john-001' },
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response :bad_request
|
assert_response :not_found
|
||||||
assert_equal ({ error: { type: 'invalid_request_error',
|
assert_equal ({ code: 2303, message: 'Object does not exist' }),
|
||||||
param: 'current_contact_id',
|
|
||||||
message: 'No such contact: non-existent' } }),
|
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,10 +84,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||||
new_contact_id: 'non-existent' },
|
new_contact_id: 'non-existent' },
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response :bad_request
|
assert_response :not_found
|
||||||
assert_equal ({ error: { type: 'invalid_request_error',
|
assert_equal ({code: 2303, message: 'Object does not exist'}),
|
||||||
param: 'new_contact_id',
|
|
||||||
message: 'No such contact: non-existent' } }),
|
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,9 +94,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
new_contact_id: 'invalid' },
|
new_contact_id: 'invalid' },
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response :bad_request
|
assert_response :bad_request
|
||||||
assert_equal ({ error: { type: 'invalid_request_error',
|
assert_equal ({ code: 2304, message: 'New contact must be valid', data: {} }),
|
||||||
param: 'new_contact_id',
|
|
||||||
message: 'New contact must be valid' } }),
|
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,8 +103,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
||||||
new_contact_id: 'william-001' },
|
new_contact_id: 'william-001' },
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response :bad_request
|
assert_response :bad_request
|
||||||
assert_equal ({ error: { type: 'invalid_request_error',
|
assert_equal ({ code: 2304, message: 'New contact must be different from current', data: {} }),
|
||||||
message: 'New contact ID must be different from current contact ID' } }),
|
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
||||||
as: :json,
|
as: :json,
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response 400
|
assert_response 400
|
||||||
assert_equal ({ errors: [{ title: 'non-existent.test does not exist' }] }),
|
assert_equal ({ code: 2304, message: 'Command failed', data: [{ title: 'non-existent.test does not exist' }] }),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
||||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
assert_response 400
|
assert_response 400
|
||||||
refute_equal @new_registrar, @domain.registrar
|
refute_equal @new_registrar, @domain.registrar
|
||||||
assert_equal ({ errors: [{ title: 'shop.test transfer code is wrong' }] }),
|
assert_equal ({ code: 2304, message: 'Command failed', data: [{ title: 'shop.test transfer code is wrong' }] }),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue