mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 22:24:47 +02:00
REPP: Domain contacts test
This commit is contained in:
parent
4c7f9709ad
commit
b3cf665ed5
4 changed files with 159 additions and 5 deletions
50
test/integration/repp/v1/contacts/tech_replace_test.rb
Normal file
50
test/integration/repp/v1/contacts/tech_replace_test.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1ContactsTechReplaceTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_replaces_tech_contacts
|
||||
old_contact = contacts(:john)
|
||||
new_contact = contacts(:william)
|
||||
|
||||
assert DomainContact.where(contact: old_contact, type: 'TechDomainContact').any?
|
||||
|
||||
payload = { current_contact_id: old_contact.code, new_contact_id: new_contact.code}
|
||||
patch "/repp/v1/domains/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_empty ["hospital.test", "library.test"] - json[:data][:affected_domains]
|
||||
|
||||
assert DomainContact.where(contact: old_contact, type: 'TechDomainContact').blank?
|
||||
end
|
||||
|
||||
def test_validates_contact_codes
|
||||
payload = { current_contact_id: 'aaa', new_contact_id: 'bbb'}
|
||||
patch "/repp/v1/domains/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :not_found
|
||||
assert_equal 2303, json[:code]
|
||||
assert_equal 'Object does not exist', json[:message]
|
||||
end
|
||||
|
||||
def test_new_contact_must_be_different
|
||||
old_contact = contacts(:john)
|
||||
|
||||
payload = { current_contact_id: old_contact.code, new_contact_id: old_contact.code }
|
||||
patch "/repp/v1/domains/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 2304, json[:code]
|
||||
assert_equal 'New contact must be different from current', json[:message]
|
||||
end
|
||||
end
|
100
test/integration/repp/v1/domains/contacts_test.rb
Normal file
100
test/integration/repp/v1/domains/contacts_test.rb
Normal file
|
@ -0,0 +1,100 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
@domain = domains(:shop)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_shows_existing_domain_contacts
|
||||
get "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal @domain.admin_contacts.length, json[:data][:admin_contacts].length
|
||||
assert_equal @domain.tech_contacts.length, json[:data][:tech_contacts].length
|
||||
end
|
||||
|
||||
def test_can_add_new_admin_contacts
|
||||
new_contact = contacts(:john)
|
||||
refute @domain.admin_contacts.find_by(code: new_contact.code).present?
|
||||
|
||||
payload = { contacts: [ { code: new_contact.code, type: 'admin' } ] }
|
||||
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
|
||||
assert @domain.admin_contacts.find_by(code: new_contact.code).present?
|
||||
end
|
||||
|
||||
def test_can_add_new_tech_contacts
|
||||
new_contact = contacts(:john)
|
||||
refute @domain.tech_contacts.find_by(code: new_contact.code).present?
|
||||
|
||||
payload = { contacts: [ { code: new_contact.code, type: 'tech' } ] }
|
||||
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
@domain.reload
|
||||
|
||||
assert @domain.tech_contacts.find_by(code: new_contact.code).present?
|
||||
end
|
||||
|
||||
def test_can_remove_admin_contacts
|
||||
contact = contacts(:john)
|
||||
payload = { contacts: [ { code: contact.code, type: 'admin' } ] }
|
||||
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
assert @domain.admin_contacts.find_by(code: contact.code).present?
|
||||
|
||||
# Actually delete the contact
|
||||
delete "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
|
||||
refute @domain.admin_contacts.find_by(code: contact.code).present?
|
||||
end
|
||||
|
||||
def test_can_remove_tech_contacts
|
||||
contact = contacts(:john)
|
||||
payload = { contacts: [ { code: contact.code, type: 'tech' } ] }
|
||||
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
assert @domain.tech_contacts.find_by(code: contact.code).present?
|
||||
|
||||
# Actually delete the contact
|
||||
delete "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
|
||||
refute @domain.tech_contacts.find_by(code: contact.code).present?
|
||||
end
|
||||
|
||||
def test_can_not_remove_one_and_only_contact
|
||||
contact = @domain.admin_contacts.last
|
||||
|
||||
payload = { contacts: [ { code: contact.code, type: 'admin' } ] }
|
||||
delete "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
@domain.reload
|
||||
assert_response :bad_request
|
||||
assert_equal 2004, json[:code]
|
||||
|
||||
assert @domain.admin_contacts.any?
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1DomainsStatusesTest < ActionDispatch::IntegrationTest
|
||||
class ReppV1DomainsNameserversTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
@domain = domains(:shop)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue