From cde4d00b55bb5ca84249d689f240cd5b8c6d135f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 22 Feb 2018 17:36:43 +0200 Subject: [PATCH 1/4] Improve tests #693 --- test/models/contact/contact_transfer_test.rb | 1 - test/models/domain/domain_transfer_test.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/test/models/contact/contact_transfer_test.rb b/test/models/contact/contact_transfer_test.rb index 6c403bb23..7346a6375 100644 --- a/test/models/contact/contact_transfer_test.rb +++ b/test/models/contact/contact_transfer_test.rb @@ -8,7 +8,6 @@ class ContactTransferTest < ActiveSupport::TestCase def test_invalid_without_auth_info @contact.auth_info = nil - @contact.validate assert @contact.invalid? end diff --git a/test/models/domain/domain_transfer_test.rb b/test/models/domain/domain_transfer_test.rb index 7b2d2d4c2..ad8088718 100644 --- a/test/models/domain/domain_transfer_test.rb +++ b/test/models/domain/domain_transfer_test.rb @@ -8,7 +8,6 @@ class DomainTransferTest < ActiveSupport::TestCase def test_invalid_without_transfer_code @domain.transfer_code = nil - @domain.validate assert @domain.invalid? end From 923d2d544658187ea7125f4fe395a281254d87bb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 22 Feb 2018 18:03:48 +0200 Subject: [PATCH 2/4] Fix status code #693 --- app/controllers/registrar/domain_transfers_controller.rb | 2 +- test/integration/registrar/domain_transfers_test.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/registrar/domain_transfers_controller.rb b/app/controllers/registrar/domain_transfers_controller.rb index 0c72b2d93..7205f246c 100644 --- a/app/controllers/registrar/domain_transfers_controller.rb +++ b/app/controllers/registrar/domain_transfers_controller.rb @@ -51,7 +51,7 @@ class Registrar end end - if response.code == '204' + if response.code == '200' flash[:notice] = t '.transferred' redirect_to registrar_domains_url else diff --git a/test/integration/registrar/domain_transfers_test.rb b/test/integration/registrar/domain_transfers_test.rb index 46a92859b..c54790bb2 100644 --- a/test/integration/registrar/domain_transfers_test.rb +++ b/test/integration/registrar/domain_transfers_test.rb @@ -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' From 0eca515c3d4aadac70f4867a58044f216774ac75 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 22 Feb 2018 18:27:00 +0200 Subject: [PATCH 3/4] Return domain name in domain transfers API #693 --- app/api/repp/domain_transfers_v1.rb | 2 +- test/integration/api/domain_transfers_test.rb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/api/repp/domain_transfers_v1.rb b/app/api/repp/domain_transfers_v1.rb index addae67b2..eca21b62d 100644 --- a/app/api/repp/domain_transfers_v1.rb +++ b/app/api/repp/domain_transfers_v1.rb @@ -26,7 +26,7 @@ module Repp if domain if domain.transfer_code == transfer_code domain.transfer(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 diff --git a/test/integration/api/domain_transfers_test.rb b/test/integration/api/domain_transfers_test.rb index 8d6cd6c5e..69d1e7d52 100644 --- a/test/integration/api/domain_transfers_test.rb +++ b/test/integration/api/domain_transfers_test.rb @@ -8,7 +8,10 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest assert_equal registrars(:goodnames), domains(:shop).registrar 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 From 0122c4226865de060268be02955217f07c5b0b73 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 24 Feb 2018 08:07:42 +0200 Subject: [PATCH 4/4] Update translation #693 --- app/controllers/registrar/domain_transfers_controller.rb | 6 ++++-- config/locales/registrar/domain_transfers.en.yml | 2 +- test/integration/registrar/domain_transfers_test.rb | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/registrar/domain_transfers_controller.rb b/app/controllers/registrar/domain_transfers_controller.rb index 7205f246c..65127155e 100644 --- a/app/controllers/registrar/domain_transfers_controller.rb +++ b/app/controllers/registrar/domain_transfers_controller.rb @@ -51,11 +51,13 @@ class Registrar end end + parsed_response = JSON.parse(response.body, symbolize_names: true) + if response.code == '200' - flash[:notice] = t '.transferred' + 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 diff --git a/config/locales/registrar/domain_transfers.en.yml b/config/locales/registrar/domain_transfers.en.yml index 64663b558..d162110ce 100644 --- a/config/locales/registrar/domain_transfers.en.yml +++ b/config/locales/registrar/domain_transfers.en.yml @@ -8,7 +8,7 @@ en: create: header: Domain transfer - transferred: Domains have been successfully transferred + transferred: "%{count} domains have been successfully transferred" form: single: diff --git a/test/integration/registrar/domain_transfers_test.rb b/test/integration/registrar/domain_transfers_test.rb index c54790bb2..e29a11070 100644 --- a/test/integration/registrar/domain_transfers_test.rb +++ b/test/integration/registrar/domain_transfers_test.rb @@ -25,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