Allow batch domain transfer

#660
This commit is contained in:
Artur Beljajev 2018-01-26 00:34:55 +02:00
parent 490528ca18
commit e60380c60a
9 changed files with 103 additions and 30 deletions

View file

@ -0,0 +1,37 @@
require 'test_helper'
class APIDomainTransfersTest < ActionDispatch::IntegrationTest
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 204
assert_equal registrars(:goodnames), domains(:shop).registrar
assert_empty response.body
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('test_goodnames', 'testtest')
end
end

View file

@ -0,0 +1,43 @@
require 'test_helper'
class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest
def setup
WebMock.reset!
login_as users(:api_goodnames)
end
def test_batch_transfer_succeeds
body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
headers = { 'Content-type' => 'application/json' }
request_stub = stub_request(:post, /domain_transfers/).with(body: body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(status: 204)
visit registrar_domains_url
click_link 'Transfer'
click_on 'Batch'
attach_file 'Batch file', Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_transfer.csv').to_s
click_button 'Transfer batch'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Domains have been successfully transferred'
end
def test_batch_transfer_fails_gracefully
body = { errors: [{ title: 'epic fail' }] }.to_json
headers = { 'Content-type' => 'application/json' }
stub_request(:post, /domain_transfers/).to_return(status: 400, body: body, headers: headers)
visit registrar_domains_url
click_link 'Transfer'
click_on 'Batch'
attach_file 'Batch file', Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_transfer.csv').to_s
click_button 'Transfer batch'
assert_text 'epic fail'
end
end

View file

@ -1,11 +1,8 @@
require 'test_helper'
class RegistrarDomainsTest < ActionDispatch::IntegrationTest
def setup
login_as users(:api_bestnames)
end
def test_downloads_domain_list_as_csv
login_as users(:api_bestnames)
travel_to Time.zone.parse('2010-07-05 10:30')
expected_csv = <<-CSV.strip_heredoc
@ -20,22 +17,4 @@ class RegistrarDomainsTest < ActionDispatch::IntegrationTest
assert_equal 'attachment; filename="Domains_2010-07-05_10.30.csv"', response_headers['Content-Disposition']
assert_equal expected_csv, page.body
end
def test_transfers_domain
travel_to Time.zone.parse('2010-07-05 10:30:00')
visit registrar_domains_url
click_link 'Transfer'
fill_in 'Domain name', with: 'shop.test'
fill_in 'Transfer code', with: '65078d5'
click_button 'Transfer'
assert_text 'Transfer requested at: 2010-07-05 10:30:00'
end
def test_prefills_domain_transfer_form
visit info_registrar_domains_url(domain_name: 'airport.test')
click_link 'Transfer'
assert_field 'domain_name', with: 'airport.test'
end
end