REPP: Extend domain transfer test

This commit is contained in:
Karl Erik Õunapuu 2020-10-22 16:18:07 +03:00
parent f2983da14c
commit 8790d1415a
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 75 additions and 43 deletions

View file

@ -12,26 +12,6 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
Setting.transfer_wait_time = @original_transfer_wait_time
end
def test_returns_domain_transfers
post '/repp/v1/domains/transfer', params: request_params, as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
expected_body = {
code: 1000,
message: 'Command completed successfully',
data: [
{
type: 'domain_transfer',
attributes: { domain_name: 'shop.test' },
}
]
}
real_body = JSON.parse(response.body, symbolize_names: true)
assert_equal(expected_body, real_body)
end
def test_creates_new_domain_transfer
assert_difference -> { @domain.transfers.size } do
post '/repp/v1/domains/transfer', params: request_params, as: :json,
@ -83,29 +63,6 @@ class APIDomainTransfersTest < ApplicationIntegrationTest
assert_equal 1, @new_registrar.contacts.where(name: 'William').size
end
def test_fails_if_domain_does_not_exist
post '/repp/v1/domains/transfer',
params: { data: { domain_transfers: [{ domain_name: 'non-existent.test',
transfer_code: 'any' }] } },
as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
assert_equal ({ code: 2304, message: 'Command failed', data: [{ title: 'non-existent.test does not exist' }] }),
JSON.parse(response.body, symbolize_names: true)
end
def test_fails_if_transfer_code_is_wrong
post '/repp/v1/domains/transfer',
params: { data: { domain_transfers: [{ domain_name: 'shop.test',
transfer_code: 'wrong' }] } },
as: :json,
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 400
refute_equal @new_registrar, @domain.registrar
assert_equal ({ code: 2304, message: 'Command failed', data: [{ title: 'shop.test transfer code is wrong' }] }),
JSON.parse(response.body, symbolize_names: true)
end
private
def request_params

View file

@ -32,6 +32,31 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest
assert @domain.registrar = @user.registrar
end
def test_does_not_transfer_domain_if_not_transferable
@domain.schedule_force_delete(type: :fast_track)
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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_equal 'Object status prohibits operation', json[:data][:failed][0][:errors][0][:msg]
@domain.reload
assert_not @domain.registrar == @user.registrar
end
def test_does_not_transfer_domain_with_invalid_auth_code
payload = {
"data": {
@ -49,4 +74,54 @@ class ReppV1DomainsTransferTest < ActionDispatch::IntegrationTest
assert_equal "Invalid authorization information", json[:data][:failed][0][:errors][0][:msg]
end
def test_does_not_transfer_domain_to_same_registrar
@domain.update!(registrar: @user.registrar)
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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_equal 'Domain already belongs to the querying registrar', json[:data][:failed][0][:errors][0][:msg]
@domain.reload
assert @domain.registrar == @user.registrar
end
def test_does_not_transfer_domain_if_discarded
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
payload = {
"data": {
"domain_transfers": [
{ "domain_name": @domain.name, "transfer_code": @domain.transfer_code }
]
}
}
post "/repp/v1/domains/transfer", 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_equal 'Object is not eligible for transfer', json[:data][:failed][0][:errors][0][:msg]
@domain.reload
assert_not @domain.registrar == @user.registrar
end
end