Implement domain transfer API

#660
This commit is contained in:
Artur Beljajev 2018-01-24 13:38:51 +02:00
parent 05bdb11ee3
commit 0751a69d83
3 changed files with 69 additions and 17 deletions

View file

@ -1,19 +1,37 @@
require 'test_helper'
class Repp::DomainTransfersTest < ActionDispatch::IntegrationTest
def test_post_to_domain_transfers
request_params = { format: :json, domainTransfers: [{ domainName: domains(:shop).name, transferCode: domains(:shop).transfer_code }] }
def test_transfers_domain
request_params = { format: :json,
data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :created
assert_response 204
assert_equal registrars(:goodnames), domains(:shop).registrar
assert_empty response.body
end
assert_difference -> { domains(:shop).domain_transfers.count } do
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
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 }
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 }
assert_response 400
refute_equal registrars(:goodnames), domains(:shop).registrar
assert_equal ({ errors: [{ title: 'shop.test transfer code is wrong' }] }),
JSON.parse(response.body, symbolize_names: true)
end
private
def http_auth_key
ActionController::HttpAuthentication::Basic.encode_credentials(users(:api_bestnames).username, users(:api_bestnames).password)
ActionController::HttpAuthentication::Basic.encode_credentials('test_goodnames', 'testtest')
end
end