mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
parent
e84a1dc0de
commit
4ab6821d8a
9 changed files with 236 additions and 78 deletions
|
@ -1,11 +1,12 @@
|
|||
require 'test_helper'
|
||||
|
||||
class APIDomainTransfersTest < ActionDispatch::IntegrationTest
|
||||
def test_transfers_domain
|
||||
request_params = { format: :json,
|
||||
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
||||
def setup
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
def test_returns_domain_transfers
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_equal registrars(:goodnames), domains(:shop).registrar
|
||||
assert_response 200
|
||||
assert_equal ({ data: [{
|
||||
type: 'domain_transfer'
|
||||
|
@ -13,6 +14,39 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
|
|||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
||||
def test_approves_automatically
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert @domain.domain_transfers.last.approved?
|
||||
end
|
||||
|
||||
def test_changes_registrar
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
@domain.reload
|
||||
assert_equal registrars(:goodnames), @domain.registrar
|
||||
end
|
||||
|
||||
def test_regenerates_transfer_code
|
||||
@old_transfer_code = @domain.transfer_code
|
||||
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
@domain.reload
|
||||
refute_equal @domain.transfer_code, @old_transfer_code
|
||||
end
|
||||
|
||||
def test_notifies_old_registrar
|
||||
@old_registrar = @domain.registrar
|
||||
|
||||
assert_difference -> { @old_registrar.messages.count } do
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
end
|
||||
end
|
||||
|
||||
def test_creates_copy_of_registrant_admin_and_tech_contacts
|
||||
assert_difference 'Contact.count', 3 do
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
end
|
||||
end
|
||||
|
||||
def test_fails_if_domain_does_not_exist
|
||||
request_params = { format: :json,
|
||||
data: { domainTransfers: [{ domainName: 'non-existent.test', transferCode: 'any' }] } }
|
||||
|
@ -27,13 +61,18 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
|
|||
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: 'wrong' }] } }
|
||||
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||
assert_response 400
|
||||
refute_equal registrars(:goodnames), domains(:shop).registrar
|
||||
refute_equal registrars(:goodnames), @domain.registrar
|
||||
assert_equal ({ errors: [{ title: 'shop.test transfer code is wrong' }] }),
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_params
|
||||
{ format: :json,
|
||||
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
|
||||
end
|
||||
|
||||
def http_auth_key
|
||||
ActionController::HttpAuthentication::Basic.encode_credentials('test_goodnames', 'testtest')
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue