mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
parent
bb108efedd
commit
fa52001be6
141 changed files with 1388 additions and 1664 deletions
|
@ -2,9 +2,9 @@ require 'test_helper'
|
|||
|
||||
class APIDomainContactsTest < ApplicationIntegrationTest
|
||||
def test_replace_all_tech_contacts_of_the_current_registrar
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_nil domains(:shop).tech_contacts.find_by(code: 'william-001')
|
||||
assert domains(:shop).tech_contacts.find_by(code: 'john-001')
|
||||
|
@ -14,17 +14,17 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
def test_skip_discarded_domains
|
||||
domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE])
|
||||
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert domains(:airport).tech_contacts.find_by(code: 'william-001')
|
||||
end
|
||||
|
||||
def test_return_affected_domains_in_alphabetical_order
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response :ok
|
||||
assert_equal ({ affected_domains: %w[airport.test shop.test],
|
||||
|
@ -36,9 +36,9 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
domains(:shop).update!(statuses: [DomainStatus::DELETE_CANDIDATE])
|
||||
domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE])
|
||||
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response :ok
|
||||
assert_equal %w[airport.test shop.test], JSON.parse(response.body,
|
||||
|
@ -46,25 +46,25 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_keep_other_tech_contacts_intact
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert domains(:shop).tech_contacts.find_by(code: 'acme-ltd-001')
|
||||
end
|
||||
|
||||
def test_keep_admin_contacts_intact
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
new_contact_id: 'john-001' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert domains(:airport).admin_contacts.find_by(code: 'william-001')
|
||||
end
|
||||
|
||||
def test_restrict_contacts_to_the_current_registrar
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'jack-001',
|
||||
new_contact_id: 'william-002' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'jack-001',
|
||||
new_contact_id: 'william-002' },
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal ({ error: { type: 'invalid_request_error',
|
||||
|
@ -74,9 +74,9 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_non_existent_current_contact
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'non-existent',
|
||||
new_contact_id: 'john-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
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',
|
||||
|
@ -85,9 +85,9 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_non_existent_new_contact
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'non-existent' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
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',
|
||||
|
@ -96,9 +96,9 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_disallow_invalid_new_contact
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'invalid' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
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',
|
||||
|
@ -107,9 +107,9 @@ class APIDomainContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_disallow_self_replacement
|
||||
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
|
||||
new_contact_id: 'william-001' },
|
||||
{ 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001',
|
||||
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' } }),
|
||||
|
|
|
@ -13,7 +13,8 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_returns_domain_transfers
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 200
|
||||
assert_equal ({ data: [{
|
||||
type: 'domain_transfer',
|
||||
|
@ -26,17 +27,20 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
|
||||
def test_creates_new_domain_transfer
|
||||
assert_difference -> { @domain.transfers.size } do
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
end
|
||||
end
|
||||
|
||||
def test_approves_automatically_if_auto_approval_is_enabled
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert @domain.transfers.last.approved?
|
||||
end
|
||||
|
||||
def test_assigns_new_registrar
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
@domain.reload
|
||||
assert_equal @new_registrar, @domain.registrar
|
||||
end
|
||||
|
@ -44,7 +48,8 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
def test_regenerates_transfer_code
|
||||
@old_transfer_code = @domain.transfer_code
|
||||
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
@domain.reload
|
||||
refute_equal @domain.transfer_code, @old_transfer_code
|
||||
end
|
||||
|
@ -53,34 +58,41 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
@old_registrar = @domain.registrar
|
||||
|
||||
assert_difference -> { @old_registrar.notifications.count } do
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
end
|
||||
end
|
||||
|
||||
def test_duplicates_registrant_admin_and_tech_contacts
|
||||
assert_difference -> { @new_registrar.contacts.size }, 3 do
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
end
|
||||
end
|
||||
|
||||
def test_reuses_identical_contact
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers', params: request_params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_equal 1, @new_registrar.contacts.where(name: 'William').size
|
||||
end
|
||||
|
||||
def test_fails_if_domain_does_not_exist
|
||||
request_params = { format: :json,
|
||||
data: { domainTransfers: [{ domainName: 'non-existent.test', transferCode: 'any' }] } }
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers',
|
||||
params: { data: { domainTransfers: [{ domainName: 'non-existent.test',
|
||||
transferCode: 'any' }] } },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 400
|
||||
assert_equal ({ errors: [{ title: 'non-existent.test does not exist' }] }),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
||||
def test_fails_if_transfer_code_is_wrong
|
||||
request_params = { format: :json,
|
||||
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: 'wrong' }] } }
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
post '/repp/v1/domain_transfers',
|
||||
params: { data: { domainTransfers: [{ domainName: 'shop.test',
|
||||
transferCode: 'wrong' }] } },
|
||||
as: :json,
|
||||
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' }] }),
|
||||
|
@ -90,8 +102,7 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
|
|||
private
|
||||
|
||||
def request_params
|
||||
{ format: :json,
|
||||
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
||||
{ data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
||||
end
|
||||
|
||||
def http_auth_key
|
||||
|
|
|
@ -5,18 +5,23 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
|||
old_nameserver_ids = [nameservers(:shop_ns1).id,
|
||||
nameservers(:airport_ns1).id,
|
||||
nameservers(:metro_ns1).id]
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_empty (old_nameserver_ids & registrars(:bestnames).nameservers(true).ids)
|
||||
params = { data: { type: 'nameserver',
|
||||
id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_empty (old_nameserver_ids & registrars(:bestnames).nameservers.reload.ids)
|
||||
end
|
||||
|
||||
def test_saves_all_attributes
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] } } }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
params = { data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] } } }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
new_nameserver = domains(:shop).nameservers.find_by(hostname: 'ns55.bestnames.test')
|
||||
assert_equal ['192.0.2.55'], new_nameserver.ipv4
|
||||
|
@ -24,52 +29,60 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_keeps_other_nameserver_intact
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
params = { data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
|
||||
other_nameserver_hash = nameservers(:shop_ns2).attributes
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_equal other_nameserver_hash, nameservers(:shop_ns2).reload.attributes
|
||||
end
|
||||
|
||||
def test_keeps_other_registrar_nameservers_intact
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
params = { data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
|
||||
nameserver_hash = nameservers(:metro_ns1).attributes
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_equal nameserver_hash, nameservers(:metro_ns1).reload.attributes
|
||||
end
|
||||
|
||||
def test_returns_new_nameserver_record_and_affected_domain
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] } } }
|
||||
params = { data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] } } }
|
||||
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 200
|
||||
assert_equal ({ data: { type: 'nameserver',
|
||||
id: 'ns55.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test',
|
||||
ipv4: ['192.0.2.55'],
|
||||
ipv6: ['2001:db8::55'] }},
|
||||
ipv6: ['2001:db8::55'] } },
|
||||
affected_domains: ["airport.test", "shop.test"] }),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
||||
def test_optional_params
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
params = { data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: 'ns55.bestnames.test' } } }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
def test_non_existent_nameserver_hostname
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'non-existent.test',
|
||||
attributes: { hostname: 'any.bestnames.test' } } }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
params = { data: { type: 'nameserver', id: 'non-existent.test',
|
||||
attributes: { hostname: 'any.bestnames.test' } } }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 404
|
||||
assert_equal ({ errors: [{ title: 'Hostname non-existent.test does not exist' }] }),
|
||||
|
@ -77,9 +90,10 @@ class APINameserversPutTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_invalid_request_params
|
||||
request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: '' } } }
|
||||
put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
params = { data: { type: 'nameserver', id: 'ns1.bestnames.test',
|
||||
attributes: { hostname: '' } } }
|
||||
put '/repp/v1/registrar/nameservers', params: params, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
|
||||
assert_response 400
|
||||
assert_equal ({ errors: [{ title: 'Hostname is missing' }] }),
|
||||
|
|
|
@ -20,7 +20,7 @@ class RegistrantApiAuthenticationTest < ApplicationIntegrationTest
|
|||
last_name: 'Smith',
|
||||
}
|
||||
|
||||
post '/api/v1/registrant/auth/eid', params
|
||||
post '/api/v1/registrant/auth/eid', params: params
|
||||
assert(User.find_by(registrant_ident: 'EE-30110100103'))
|
||||
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -29,7 +29,7 @@ class RegistrantApiAuthenticationTest < ApplicationIntegrationTest
|
|||
|
||||
def test_request_returns_existing_user
|
||||
assert_no_changes User.count do
|
||||
post '/api/v1/registrant/auth/eid', @user_hash
|
||||
post '/api/v1/registrant/auth/eid', params: @user_hash
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ class RegistrantApiAuthenticationTest < ApplicationIntegrationTest
|
|||
@original_whitelist_ip = ENV['registrant_api_auth_allowed_ips']
|
||||
ENV['registrant_api_auth_allowed_ips'] = '1.2.3.4'
|
||||
|
||||
post '/api/v1/registrant/auth/eid', params
|
||||
post '/api/v1/registrant/auth/eid', params: params
|
||||
assert_equal(401, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
|
@ -50,7 +50,7 @@ class RegistrantApiAuthenticationTest < ApplicationIntegrationTest
|
|||
def test_request_documented_parameters_are_required
|
||||
params = { foo: :bar, test: :test }
|
||||
|
||||
post '/api/v1/registrant/auth/eid', params
|
||||
post '/api/v1/registrant/auth/eid', params: params
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ ident: ['parameter is required'] }] }, json)
|
||||
assert_equal(422, response.status)
|
||||
|
|
|
@ -14,18 +14,19 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
|||
contacts(:william).update!(ident: '1234', ident_type: 'priv', ident_country_code: 'US')
|
||||
assert_equal 3, @user.contacts.size
|
||||
|
||||
get '/api/v1/registrant/contacts', { 'limit' => 1, 'offset' => 0 }, @auth_headers
|
||||
get '/api/v1/registrant/contacts', params: { 'limit' => 1, 'offset' => 0 },
|
||||
headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(200, response.status)
|
||||
assert_equal(1, response_json.count)
|
||||
|
||||
get '/api/v1/registrant/contacts', {}, @auth_headers
|
||||
get '/api/v1/registrant/contacts', headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(3, response_json.count)
|
||||
end
|
||||
|
||||
def test_get_contact_details_by_uuid
|
||||
get api_v1_registrant_contact_path(@contact.uuid), nil, @auth_headers
|
||||
get api_v1_registrant_contact_path(@contact.uuid), headers: @auth_headers
|
||||
|
||||
assert_response :ok
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -33,21 +34,23 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_root_does_not_accept_limit_higher_than_200
|
||||
get '/api/v1/registrant/contacts', { 'limit' => 400, 'offset' => 0 }, @auth_headers
|
||||
get '/api/v1/registrant/contacts', params: { 'limit' => 400, 'offset' => 0 },
|
||||
headers: @auth_headers
|
||||
assert_equal(400, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ limit: ['parameter is out of range'] }] }, response_json)
|
||||
end
|
||||
|
||||
def test_root_does_not_accept_offset_lower_than_0
|
||||
get '/api/v1/registrant/contacts', { 'limit' => 200, 'offset' => "-10" }, @auth_headers
|
||||
get '/api/v1/registrant/contacts', params: { 'limit' => 200, 'offset' => "-10" },
|
||||
headers: @auth_headers
|
||||
assert_equal(400, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ offset: ['parameter is out of range'] }] }, response_json)
|
||||
end
|
||||
|
||||
def test_root_returns_401_without_authorization
|
||||
get '/api/v1/registrant/contacts', {}, {}
|
||||
get '/api/v1/registrant/contacts'
|
||||
assert_equal(401, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ require 'test_helper'
|
|||
|
||||
class RegistrantApiCorsHeadersTest < ApplicationIntegrationTest
|
||||
def test_returns_200_response_code_for_options_request
|
||||
options '/api/v1/registrant/auth/eid', {}, { 'Origin' => 'https://example.com' }
|
||||
|
||||
process :options, api_v1_registrant_auth_eid_path,
|
||||
headers: { 'Origin' => 'https://example.com' }
|
||||
assert_equal('200', response.code)
|
||||
end
|
||||
|
||||
def test_returns_expected_headers_for_options_requests
|
||||
options '/api/v1/registrant/auth/eid', {}, { 'Origin' => 'https://example.com' }
|
||||
process :options, api_v1_registrant_auth_eid_path, headers: { 'Origin' => 'https://example.com' }
|
||||
|
||||
assert_equal('https://example.com', response.headers['Access-Control-Allow-Origin'])
|
||||
assert_equal('POST, GET, PUT, PATCH, DELETE, OPTIONS',
|
||||
|
@ -20,16 +20,15 @@ class RegistrantApiCorsHeadersTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_returns_empty_body
|
||||
options '/api/v1/registrant/auth/eid', { 'Origin' => 'https://example.com' }
|
||||
|
||||
process :options, api_v1_registrant_auth_eid_path, headers: { 'Origin' => 'https://example.com' }
|
||||
assert_equal('', response.body)
|
||||
end
|
||||
|
||||
def test_it_returns_cors_headers_for_other_requests
|
||||
post '/api/v1/registrant/auth/eid', {}, { 'Origin' => 'https://example.com' }
|
||||
post '/api/v1/registrant/auth/eid', headers: { 'Origin' => 'https://example.com' }
|
||||
assert_equal('https://example.com', response.headers['Access-Control-Allow-Origin'])
|
||||
|
||||
get '/api/v1/registrant/contacts', {}, { 'Origin' => 'https://example.com' }
|
||||
get '/api/v1/registrant/contacts', headers: { 'Origin' => 'https://example.com' }
|
||||
assert_equal('https://example.com', response.headers['Access-Control-Allow-Origin'])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_get_domain_details_by_uuid
|
||||
get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37', {}, @auth_headers
|
||||
get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37', headers: @auth_headers
|
||||
assert_equal(200, response.status)
|
||||
|
||||
domain = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -30,7 +30,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_get_non_existent_domain_details_by_uuid
|
||||
get '/api/v1/registrant/domains/random-uuid', {}, @auth_headers
|
||||
get '/api/v1/registrant/domains/random-uuid', headers: @auth_headers
|
||||
assert_equal(404, response.status)
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -38,7 +38,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_root_returns_domain_list
|
||||
get '/api/v1/registrant/domains', {}, @auth_headers
|
||||
get '/api/v1/registrant/domains', headers: @auth_headers
|
||||
assert_equal(200, response.status)
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -50,20 +50,22 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_root_accepts_limit_and_offset_parameters
|
||||
get '/api/v1/registrant/domains', { 'limit' => 2, 'offset' => 0 }, @auth_headers
|
||||
get '/api/v1/registrant/domains', params: { 'limit' => 2, 'offset' => 0 },
|
||||
headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal(200, response.status)
|
||||
assert_equal(2, response_json.count)
|
||||
|
||||
get '/api/v1/registrant/domains', {}, @auth_headers
|
||||
get '/api/v1/registrant/domains', headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal(4, response_json.count)
|
||||
end
|
||||
|
||||
def test_root_does_not_accept_limit_higher_than_200
|
||||
get '/api/v1/registrant/domains', { 'limit' => 400, 'offset' => 0 }, @auth_headers
|
||||
get '/api/v1/registrant/domains', params: { 'limit' => 400, 'offset' => 0 },
|
||||
headers: @auth_headers
|
||||
|
||||
assert_equal(400, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -71,7 +73,8 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_root_does_not_accept_offset_lower_than_0
|
||||
get '/api/v1/registrant/domains', { 'limit' => 200, 'offset' => "-10" }, @auth_headers
|
||||
get '/api/v1/registrant/domains', params: { 'limit' => 200, 'offset' => "-10" },
|
||||
headers: @auth_headers
|
||||
|
||||
assert_equal(400, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -79,7 +82,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_root_returns_401_without_authorization
|
||||
get '/api/v1/registrant/domains', {}, {}
|
||||
get '/api/v1/registrant/domains'
|
||||
assert_equal(401, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
|
@ -87,7 +90,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_details_returns_401_without_authorization
|
||||
get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37', {}, {}
|
||||
get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37'
|
||||
assert_equal(401, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
|
||||
def test_can_lock_a_not_locked_domain
|
||||
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
|
@ -27,7 +27,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
def test_locking_a_domain_creates_a_version_record
|
||||
assert_difference '@domain.versions.count', 1 do
|
||||
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
end
|
||||
|
||||
@domain.reload
|
||||
|
@ -39,7 +39,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
@domain.save
|
||||
|
||||
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(422, response.status)
|
||||
|
@ -51,7 +51,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
assert(@domain.locked_by_registrant?)
|
||||
|
||||
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(422, response.status)
|
||||
|
@ -62,7 +62,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
@domain.apply_registry_lock
|
||||
|
||||
delete '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert(response_json[:statuses].include?(DomainStatus::OK))
|
||||
|
@ -73,7 +73,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
|
||||
def test_cannot_unlock_a_not_locked_domain
|
||||
delete '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(422, response.status)
|
||||
|
@ -81,8 +81,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_returns_404_when_domain_is_not_found
|
||||
post '/api/v1/registrant/domains/random-uuid/registry_lock',
|
||||
{}, @auth_headers
|
||||
post '/api/v1/registrant/domains/random-uuid/registry_lock', headers: @auth_headers
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(404, response.status)
|
||||
|
@ -99,7 +98,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
assert_equal '1234', contact.ident
|
||||
assert_equal 'US', contact.ident_country_code
|
||||
|
||||
post api_v1_registrant_domain_registry_lock_path(domain.uuid), nil, @auth_headers
|
||||
post api_v1_registrant_domain_registry_lock_path(domain.uuid), headers: @auth_headers
|
||||
|
||||
assert_response :unauthorized
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -109,7 +108,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
|
||||
def test_registrant_can_lock_a_domain
|
||||
post '/api/v1/registrant/domains/1b3ee442-e8fe-4922-9492-8fcb9dccc69c/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
assert_equal(200, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -125,7 +124,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
|
|||
assert_equal 'https://bestnames.test', @domain.registrar.website
|
||||
|
||||
post '/api/v1/registrant/domains/1b3ee442-e8fe-4922-9492-8fcb9dccc69c/registry_lock',
|
||||
{}, @auth_headers
|
||||
headers: @auth_headers
|
||||
|
||||
assert_equal(200, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
|
|
@ -15,18 +15,18 @@ class ApiV1AuctionDetailsTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'auction.test', @auction.domain
|
||||
assert_equal Auction.statuses[:no_bids], @auction.status
|
||||
|
||||
get api_v1_auction_path(@auction.uuid), nil, 'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_auction_path(@auction.uuid), as: :json
|
||||
|
||||
assert_response :ok
|
||||
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
|
||||
'domain' => 'auction.test',
|
||||
'status' => Auction.statuses[:no_bids] }), ActiveSupport::JSON
|
||||
.decode(response.body)
|
||||
.decode(response.body)
|
||||
end
|
||||
|
||||
def test_auction_not_found
|
||||
assert_raises ActiveRecord::RecordNotFound do
|
||||
get api_v1_auction_path('non-existing-uuid'), nil, 'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_auction_path('non-existing-uuid'), as: :json
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,19 +10,19 @@ class ApiV1AuctionListTest < ActionDispatch::IntegrationTest
|
|||
domain: 'auction.test',
|
||||
status: Auction.statuses[:started])
|
||||
|
||||
get api_v1_auctions_path, nil, 'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_auctions_path, as: :json
|
||||
|
||||
assert_response :ok
|
||||
assert_equal ([{ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
|
||||
'domain' => 'auction.test',
|
||||
'status' => Auction.statuses[:started] }]), ActiveSupport::JSON
|
||||
.decode(response.body)
|
||||
.decode(response.body)
|
||||
end
|
||||
|
||||
def test_does_not_return_finished_auctions
|
||||
@auction.update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
|
||||
|
||||
get api_v1_auctions_path, nil, 'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_auctions_path, as: :json
|
||||
|
||||
assert_response :ok
|
||||
assert_empty ActiveSupport::JSON.decode(response.body)
|
||||
|
|
|
@ -20,47 +20,53 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert_equal '1b3ee442-e8fe-4922-9492-8fcb9dccc69c', @auction.uuid
|
||||
assert_equal 'auction.test', @auction.domain
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:awaiting_payment] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:awaiting_payment] },
|
||||
as: :json
|
||||
|
||||
assert_response :ok
|
||||
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
|
||||
'domain' => 'auction.test',
|
||||
'status' => Auction.statuses[:awaiting_payment] }), ActiveSupport::JSON
|
||||
.decode(response.body)
|
||||
.decode(response.body)
|
||||
end
|
||||
|
||||
def test_marks_as_awaiting_payment
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:awaiting_payment] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:awaiting_payment] },
|
||||
as: :json
|
||||
@auction.reload
|
||||
assert @auction.awaiting_payment?
|
||||
end
|
||||
|
||||
def test_marks_as_no_bids
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:no_bids] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:no_bids] },
|
||||
as: :json
|
||||
@auction.reload
|
||||
assert @auction.no_bids?
|
||||
end
|
||||
|
||||
def test_marks_as_payment_received
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:payment_received] },
|
||||
as: :json
|
||||
@auction.reload
|
||||
assert @auction.payment_received?
|
||||
end
|
||||
|
||||
def test_marks_as_payment_not_received
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_not_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:payment_not_received] },
|
||||
as: :json
|
||||
@auction.reload
|
||||
assert @auction.payment_not_received?
|
||||
end
|
||||
|
||||
def test_marks_as_domain_not_registered
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:domain_not_registered] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:domain_not_registered] },
|
||||
as: :json
|
||||
@auction.reload
|
||||
assert @auction.domain_not_registered?
|
||||
end
|
||||
|
@ -69,8 +75,9 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
@auction.update!(registration_code: 'auction-001',
|
||||
status: Auction.statuses[:awaiting_payment])
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:payment_received] },
|
||||
as: :json
|
||||
|
||||
response_json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_not_nil response_json['registration_code']
|
||||
|
@ -79,8 +86,9 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
def test_conceals_registration_code_when_payment_is_not_received
|
||||
@auction.update!(status: Auction.statuses[:awaiting_payment])
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_not_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:payment_not_received] },
|
||||
as: :json
|
||||
|
||||
response_json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_nil response_json['registration_code']
|
||||
|
@ -91,8 +99,9 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'auction.test', @auction.domain
|
||||
@whois_record.update!(updated_at: '2010-07-04')
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:payment_received] },
|
||||
as: :json
|
||||
@whois_record.reload
|
||||
|
||||
assert_equal Time.zone.parse('2010-07-05 10:00'), @whois_record.updated_at
|
||||
|
@ -103,8 +112,9 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'auction.test', @auction.domain
|
||||
@whois_record.delete
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
|
||||
.to_json, 'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid),
|
||||
params: { status: Auction.statuses[:payment_received] },
|
||||
as: :json
|
||||
|
||||
new_whois_record = Whois::Record.find_by(name: @auction.domain)
|
||||
assert_equal Time.zone.parse('2010-07-05 10:00'), new_whois_record.updated_at
|
||||
|
@ -114,16 +124,16 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
|
|||
def test_inaccessible_when_ip_address_is_not_allowed
|
||||
ENV['auction_api_allowed_ips'] = ''
|
||||
|
||||
patch api_v1_auction_path(@auction.uuid), { status: 'any' }.to_json,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path(@auction.uuid), params: { status: 'any' }, as: :json
|
||||
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_auction_not_found
|
||||
assert_raises ActiveRecord::RecordNotFound do
|
||||
patch api_v1_auction_path('non-existing-uuid'), { status: Auction.statuses[:no_bids] }.to_json,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_auction_path('non-existing-uuid'),
|
||||
params: { status: Auction.statuses[:no_bids] },
|
||||
as: :json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,8 +14,8 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_returns_contact_details
|
||||
get api_v1_registrant_contact_path(@contact.uuid), nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contact_path(@contact.uuid), as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :ok
|
||||
assert_equal ({ id: @contact.uuid,
|
||||
|
@ -43,8 +43,8 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_non_existent_contact
|
||||
get api_v1_registrant_contact_path('non-existent'), nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contact_path('non-existent'), as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :not_found
|
||||
assert_equal({ errors: [base: ['Contact not found']] }, JSON.parse(response.body,
|
||||
|
@ -52,7 +52,7 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_anonymous_user
|
||||
get api_v1_registrant_contact_path(@contact.uuid), nil, 'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contact_path(@contact.uuid)
|
||||
|
||||
assert_response :unauthorized
|
||||
assert_equal({ errors: [base: ['Not authorized']] }, JSON.parse(response.body,
|
||||
|
@ -66,8 +66,8 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'US-1234', @user.registrant_ident
|
||||
|
||||
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
|
||||
get api_v1_registrant_contact_path(@contact.uuid), nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contact_path(@contact.uuid), as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
end
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -78,8 +78,8 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'US-1234', @user.registrant_ident
|
||||
@contact.update!(ident: '12345')
|
||||
|
||||
get api_v1_registrant_contact_path(@contact.uuid), nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contact_path(@contact.uuid), as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :not_found
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
|
|
@ -20,8 +20,7 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'US', @contact.ident_country_code
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
|
||||
get api_v1_registrant_contacts_path, nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contacts_path, as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal 1, response_json.size
|
||||
|
@ -33,8 +32,7 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest
|
|||
@contact = contacts(:acme_ltd)
|
||||
assert_equal 'acme-ltd-001', @contact.code
|
||||
|
||||
get api_v1_registrant_contacts_path, nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contacts_path, as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal 1, response_json.size
|
||||
|
@ -48,8 +46,8 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'US-1234', @user.registrant_ident
|
||||
|
||||
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
|
||||
get api_v1_registrant_contacts_path, nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
get api_v1_registrant_contacts_path, as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
end
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
|
|
@ -21,12 +21,11 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
email: 'john@shop.test',
|
||||
phone: '+111.1')
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'William',
|
||||
email: 'william@shop.test',
|
||||
phone: '+222.2' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'William',
|
||||
email: 'william@shop.test',
|
||||
phone: '+222.2' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
assert_response :ok
|
||||
@contact.reload
|
||||
|
||||
|
@ -37,10 +36,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
|
||||
def test_notify_registrar
|
||||
assert_difference -> { @contact.registrar.notifications.count } do
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
end
|
||||
notification = @contact.registrar.notifications.last
|
||||
assert_equal 'Contact john-001 has been updated by registrant', notification.text
|
||||
|
@ -50,10 +48,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
@contact.update!(fax: '+666.6')
|
||||
ENV['fax_enabled'] = 'true'
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { fax: '+777.7' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { fax: '+777.7' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :ok
|
||||
@contact.reload
|
||||
|
@ -63,10 +60,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
def test_fax_cannot_be_updated_when_disabled
|
||||
ENV['fax_enabled'] = 'false'
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { fax: '+823.7' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { fax: '+823.7' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :bad_request
|
||||
@contact.reload
|
||||
|
@ -80,14 +76,13 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
def test_update_address_when_enabled
|
||||
Setting.address_processing = true
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { address: { city: 'new city',
|
||||
street: 'new street',
|
||||
zip: '92837',
|
||||
country_code: 'RU',
|
||||
state: 'new state' } }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { address: { city: 'new city',
|
||||
street: 'new street',
|
||||
zip: '92837',
|
||||
country_code: 'RU',
|
||||
state: 'new state' } },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :ok
|
||||
@contact.reload
|
||||
|
@ -99,10 +94,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
@contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US')
|
||||
Setting.address_processing = true
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'any' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'any' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :ok
|
||||
end
|
||||
|
@ -111,11 +105,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
@contact.update!(street: 'old street')
|
||||
Setting.address_processing = false
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { address: { street: 'new street' } }
|
||||
.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid),
|
||||
params: { address: { street: 'new street' } },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
@contact.reload
|
||||
|
||||
assert_response :bad_request
|
||||
|
@ -130,10 +123,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
@contact.update!(ident_type: Contact::PRIV,
|
||||
disclosed_attributes: %w[])
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { disclosed_attributes: %w[name] }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid),
|
||||
params: { disclosed_attributes: %w[name] },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
@contact.reload
|
||||
|
||||
assert_response :ok
|
||||
|
@ -143,10 +136,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
def test_conceal_private_persons_data
|
||||
@contact.update!(ident_type: Contact::PRIV, disclosed_attributes: %w[name])
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { disclosed_attributes: [] }.to_json,
|
||||
{ 'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s }
|
||||
patch api_v1_registrant_contact_path(@contact.uuid),
|
||||
params: { disclosed_attributes: [] },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
@contact.reload
|
||||
|
||||
|
@ -166,11 +159,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'US-1234', @user.registrant_ident
|
||||
|
||||
assert_no_changes -> { @contact.disclosed_attributes } do
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { disclosed_attributes: %w[name] }
|
||||
.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid),
|
||||
params: { disclosed_attributes: %w[name] },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
@contact.reload
|
||||
end
|
||||
assert_response :bad_request
|
||||
|
@ -182,10 +174,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_return_contact_details
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
assert_equal ({ id: @contact.uuid,
|
||||
name: 'new name',
|
||||
code: @contact.code,
|
||||
|
@ -211,10 +202,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_errors
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { phone: 'invalid' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { phone: 'invalid' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal ({ errors: { phone: ['Phone nr is invalid'] } }), JSON.parse(response.body,
|
||||
|
@ -225,10 +215,9 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 'US-1234', @user.registrant_ident
|
||||
@contact.update!(ident: '12345')
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }.to_json,
|
||||
'HTTP_AUTHORIZATION' => auth_token,
|
||||
'Accept' => Mime::JSON,
|
||||
'Content-Type' => Mime::JSON.to_s
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { name: 'new name' },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
@contact.reload
|
||||
|
||||
assert_response :not_found
|
||||
|
@ -236,7 +225,8 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_non_existent_contact
|
||||
patch api_v1_registrant_contact_path('non-existent'), nil, 'HTTP_AUTHORIZATION' => auth_token
|
||||
patch api_v1_registrant_contact_path('non-existent'),
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
assert_response :not_found
|
||||
assert_equal ({ errors: [{ base: ['Not found'] }] }),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue