Merge pull request #722 from internetee/registry-693

REST API: Return successful domain transfers
This commit is contained in:
Timo Võhmar 2018-02-28 16:33:45 +02:00 committed by GitHub
commit 7c45a85cea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 12 deletions

View file

@ -26,7 +26,7 @@ module Repp
if domain
if domain.transfer_code == transfer_code
DomainTransfer.request(domain, new_registrar)
successful_domain_transfers << { type: 'domain_transfer' }
successful_domain_transfers << { type: 'domain_transfer', attributes: { domain_name: domain.name } }
else
errors << { title: "#{domain_name} transfer code is wrong" }
end

View file

@ -51,11 +51,13 @@ class Registrar
end
end
if response.code == '204'
flash[:notice] = t '.transferred'
parsed_response = JSON.parse(response.body, symbolize_names: true)
if response.code == '200'
flash[:notice] = t '.transferred', count: parsed_response[:data].size
redirect_to registrar_domains_url
else
@api_errors = JSON.parse(response.body, symbolize_names: true)[:errors]
@api_errors = parsed_response[:errors]
render :new
end
else

View file

@ -8,7 +8,7 @@ en:
create:
header: Domain transfer
transferred: Domains have been successfully transferred
transferred: "%{count} domains have been successfully transferred"
form:
single:

View file

@ -10,7 +10,10 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest
post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response 200
assert_equal ({ data: [{
type: 'domain_transfer'
type: 'domain_transfer',
attributes: {
domain_name: 'shop.test'
},
}] }),
JSON.parse(response.body, symbolize_names: true)
end

View file

@ -7,12 +7,14 @@ class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest
end
def test_batch_transfer_succeeds
body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
request_body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
headers = { 'Content-type' => 'application/json' }
request_stub = stub_request(:post, /domain_transfers/).with(body: body,
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(status: 204)
.to_return(body: { data: [{
type: 'domain_transfer'
}] }.to_json, status: 200)
visit registrar_domains_url
click_link 'Transfer'
@ -23,7 +25,7 @@ class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Domains have been successfully transferred'
assert_text '1 domains have been successfully transferred'
end
def test_batch_transfer_fails_gracefully

View file

@ -8,7 +8,6 @@ class ContactTransferTest < ActiveSupport::TestCase
def test_invalid_without_auth_info
@contact.auth_info = nil
@contact.validate
assert @contact.invalid?
end

View file

@ -8,7 +8,6 @@ class DomainTransferableTest < ActiveSupport::TestCase
def test_invalid_without_transfer_code
@domain.transfer_code = nil
@domain.validate
assert @domain.invalid?
end