added new test, changed contacts values

This commit is contained in:
Oleg Hasjanov 2021-01-29 14:41:23 +02:00 committed by Alex Sherman
parent 275da4645a
commit efdb445488

View file

@ -1,29 +1,52 @@
require 'test_helper' require 'test_helper'
class APIDomainAdminContactsTest < ApplicationIntegrationTest class APIDomainAdminContactsTest < ApplicationIntegrationTest
def test_replace_all_admin_contacts_of_the_current_registrar setup do
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', @admin_current = domains(:shop).admin_contacts.find_by(code: 'jane-001')
new_contact_id: 'john-001' }, @admin_new = contacts(:william)
@admin_new.update(ident: @admin_current.ident,
ident_type: @admin_current.ident_type,
ident_country_code: @admin_current.ident_country_code)
end
def test_replace_all_admin_contacts_when_ident_data_doesnt_match
@admin_new.update(ident: '777' ,
ident_type: 'priv',
ident_country_code: 'LV')
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_nil domains(:shop).admin_contacts.find_by(code: 'william-001') assert_response :bad_request
assert domains(:shop).admin_contacts.find_by(code: 'john-001') assert_equal ({ code: 2304, message: 'New admin contact must have same ident' }),
assert domains(:airport).admin_contacts.find_by(code: 'john-001') JSON.parse(response.body, symbolize_names: true)
end
def test_replace_all_admin_contacts_of_the_current_registrar
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_nil domains(:shop).admin_contacts.find_by(code: @admin_current)
assert domains(:shop).admin_contacts.find_by(code: @admin_new)
assert domains(:airport).admin_contacts.find_by(code: @admin_new)
end end
def test_skip_discarded_domains def test_skip_discarded_domains
domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE])
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'john-001' }, new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert domains(:airport).admin_contacts.find_by(code: 'william-001') assert domains(:shop).admin_contacts.find_by(code: @admin_current)
end end
def test_return_affected_domains_in_alphabetical_order def test_return_affected_domains_in_alphabetical_order
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'john-001' }, new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok assert_response :ok
@ -36,8 +59,8 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
domains(:shop).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) domains(:shop).update!(statuses: [DomainStatus::DELETE_CANDIDATE])
domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE])
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'john-001' }, new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok assert_response :ok
@ -46,23 +69,23 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
end end
def test_keep_other_admin_contacts_intact def test_keep_other_admin_contacts_intact
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'john-001' }, new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert domains(:shop).admin_contacts.find_by(code: 'acme-ltd-001') assert domains(:airport).admin_contacts.find_by(code: 'john-001')
end end
def test_keep_tech_contacts_intact def test_keep_tech_contacts_intact
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'john-001' }, new_contact_id: @admin_new },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert domains(:airport).tech_contacts.find_by(code: 'william-001') assert domains(:airport).tech_contacts.find_by(code: 'william-001')
end end
def test_restrict_contacts_to_the_current_registrar def test_restrict_contacts_to_the_current_registrar
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'jack-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'william-002' }, new_contact_id: 'william-002' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
@ -73,7 +96,7 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
def test_non_existent_current_contact def test_non_existent_current_contact
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'non-existent', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'non-existent',
new_contact_id: 'john-001' }, new_contact_id: @admin_new},
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :not_found assert_response :not_found
assert_equal ({ code: 2303, message: 'Object does not exist' }), assert_equal ({ code: 2303, message: 'Object does not exist' }),
@ -81,7 +104,7 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
end end
def test_non_existent_new_contact def test_non_existent_new_contact
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'non-existent' }, new_contact_id: 'non-existent' },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :not_found assert_response :not_found
@ -90,7 +113,7 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
end end
def test_disallow_invalid_new_contact def test_disallow_invalid_new_contact
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
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
@ -99,8 +122,8 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
end end
def test_disallow_self_replacement def test_disallow_self_replacement
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: 'william-001', patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current,
new_contact_id: 'william-001' }, new_contact_id: @admin_current },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key } headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request assert_response :bad_request
assert_equal ({ code: 2304, message: 'New contact must be different from current', data: {} }), assert_equal ({ code: 2304, message: 'New contact must be different from current', data: {} }),