Fix tests

This commit is contained in:
Karl Erik Õunapuu 2020-10-16 12:33:50 +03:00
parent f2a1ee101b
commit 220e0d7993
No known key found for this signature in database
GPG key ID: C9DD647298A34764
6 changed files with 29 additions and 31 deletions

View file

@ -59,9 +59,12 @@ module Repp
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(
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
)
end

View file

@ -16,12 +16,15 @@ module Repp
end
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
@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
return handle_errors if @epp_errors.any?
affected, skipped = TechDomainContact.replace(@current_contact, @new_contact)
data = { affected_domains: affected, skipped_domains: skipped }
render_success(data: data)

View file

@ -34,7 +34,7 @@ module Repp
end
if @errors.any?
render_success(data: { errors: @errors })
render_epp_error(:bad_request, @errors)
else
render_success(data: @successful)
end
@ -52,10 +52,11 @@ module Repp
domain = Domain.find_by(name: domain_name)
# rubocop:disable Style/AndOr
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
unless domain.transfer_code.eql?(transfer_code)
add_error("#{domain_name} transfer code is wrong")
return
end
domain
end

View file

@ -22,7 +22,7 @@ module Repp
def hostname_params
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: []]])
end

View file

@ -27,8 +27,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok
assert_equal ({ affected_domains: %w[airport.test shop.test],
skipped_domains: [] }),
assert_equal ({ code: 1000, message: 'Command completed successfully', data: { affected_domains: %w[airport.test shop.test],
skipped_domains: [] }}),
JSON.parse(response.body, symbolize_names: true)
end
@ -42,7 +42,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
assert_response :ok
assert_equal %w[airport.test shop.test], JSON.parse(response.body,
symbolize_names: true)[:skipped_domains]
symbolize_names: true)[:data][:skipped_domains]
end
def test_keep_other_tech_contacts_intact
@ -66,10 +66,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
new_contact_id: 'william-002' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'current_contact_id',
message: 'No such contact: jack-001' } }),
assert_response :not_found
assert_equal ({ code: 2303, message: 'Object does not exist' }),
JSON.parse(response.body, symbolize_names: true)
end
@ -77,10 +75,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'non-existent',
new_contact_id: 'john-001' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'current_contact_id',
message: 'No such contact: non-existent' } }),
assert_response :not_found
assert_equal ({ code: 2303, message: 'Object does not exist' }),
JSON.parse(response.body, symbolize_names: true)
end
@ -88,10 +84,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
new_contact_id: 'non-existent' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'new_contact_id',
message: 'No such contact: non-existent' } }),
assert_response :not_found
assert_equal ({code: 2303, message: 'Object does not exist'}),
JSON.parse(response.body, symbolize_names: true)
end
@ -100,9 +94,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
new_contact_id: 'invalid' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
param: 'new_contact_id',
message: 'New contact must be valid' } }),
assert_equal ({ code: 2304, message: 'New contact must be valid', data: {} }),
JSON.parse(response.body, symbolize_names: true)
end
@ -111,8 +103,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest
new_contact_id: 'william-001' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ error: { type: 'invalid_request_error',
message: 'New contact ID must be different from current contact ID' } }),
assert_equal ({ code: 2304, message: 'New contact must be different from current', data: {} }),
JSON.parse(response.body, symbolize_names: true)
end

View file

@ -90,7 +90,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
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)
end
@ -102,7 +102,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
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)
end