mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
REPP: Domain tech contact replace test
This commit is contained in:
parent
774ada6ebb
commit
06ad8c8c77
3 changed files with 69 additions and 4 deletions
|
@ -7,7 +7,7 @@ module Repp
|
||||||
|
|
||||||
def set_current_contact
|
def set_current_contact
|
||||||
@current_contact = current_user.registrar.contacts.find_by!(
|
@current_contact = current_user.registrar.contacts.find_by!(
|
||||||
code: params[:current_contact_id]
|
code: contact_params[:current_contact_id]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Repp
|
||||||
def index
|
def index
|
||||||
records = current_user.registrar.domains
|
records = current_user.registrar.domains
|
||||||
domains = records.limit(limit).offset(offset)
|
domains = records.limit(limit).offset(offset)
|
||||||
domains = domains.pluck(:name) unless params[:details] == 'true'
|
domains = domains.pluck(:name) unless index_params[:details] == 'true'
|
||||||
|
|
||||||
render_success(data: { domains: domains, total_number_of_records: records.count })
|
render_success(data: { domains: domains, total_number_of_records: records.count })
|
||||||
end
|
end
|
||||||
|
@ -96,11 +96,11 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def limit
|
def limit
|
||||||
params[:limit] || 200
|
index_params[:limit] || 200
|
||||||
end
|
end
|
||||||
|
|
||||||
def offset
|
def offset
|
||||||
params[:offset] || 0
|
index_params[:offset] || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def index_params
|
def index_params
|
||||||
|
|
65
test/integration/repp/v1/domains/contact_replacement_test.rb
Normal file
65
test/integration/repp/v1/domains/contact_replacement_test.rb
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ReppV1DomainsContactReplacementTest < 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_contact_with_new_one
|
||||||
|
replaceable_contact = contacts(:william)
|
||||||
|
replacing_contact = contacts(:jane)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"current_contact_id": replaceable_contact.code,
|
||||||
|
"new_contact_id": replacing_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_equal 'Command completed successfully', json[:message]
|
||||||
|
|
||||||
|
assert json[:data][:affected_domains].include? 'airport.test'
|
||||||
|
assert json[:data][:affected_domains].include? 'shop.test'
|
||||||
|
|
||||||
|
assert_empty json[:data][:skipped_domains]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_tech_contact_id_must_differ
|
||||||
|
replaceable_contact = contacts(:william)
|
||||||
|
replacing_contact = contacts(:william)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"current_contact_id": replaceable_contact.code,
|
||||||
|
"new_contact_id": replacing_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
|
||||||
|
|
||||||
|
def test_contact_codes_must_be_valid
|
||||||
|
payload = {
|
||||||
|
"current_contact_id": 'dfgsdfg',
|
||||||
|
"new_contact_id": 'vvv'
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue