diff --git a/app/controllers/admin/api_users_controller.rb b/app/controllers/admin/api_users_controller.rb index 2b421cbad..01ac6ae88 100644 --- a/app/controllers/admin/api_users_controller.rb +++ b/app/controllers/admin/api_users_controller.rb @@ -50,7 +50,7 @@ module Admin def set_test_date_to_api_user user_api = User.find(params[:user_api_id]) - uri = URI.parse((ENV['registry_demo_registrar_api_user_url'] || 'testapi.test') + "?username=#{user_api.username}&identity_code=#{user_api.identity_code}") + uri = URI.parse((ENV['registry_demo_registrar_api_user_url'] || 'http://testapi.test') + "?username=#{user_api.username}&identity_code=#{user_api.identity_code}") response = base_get_request(uri: uri, port: ENV['registry_demo_registrar_port']) @@ -74,7 +74,7 @@ module Admin user_api.accreditation_date = nil user_api.accreditation_expire_date = nil user_api.save - + redirect_to request.referrer end diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 1824575f1..bc8c7e600 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -60,7 +60,7 @@ module Admin def set_test_date registrar = Registrar.find(params[:registrar_id]) - uri = URI.parse((ENV['registry_demo_registrar_results_url'] || 'testapi.test') + "?registrar_name=#{registrar.name}") + uri = URI.parse((ENV['registry_demo_registrar_results_url'] || 'http://testapi.test') + "?registrar_name=#{registrar.name}") response = base_get_request(uri: uri, port: ENV['registry_demo_registrar_port']) diff --git a/test/interactions/record_date_of_test_test.rb b/test/interactions/record_date_of_test_test.rb new file mode 100644 index 000000000..b8f228f62 --- /dev/null +++ b/test/interactions/record_date_of_test_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class RecordDateOfTestTest < ActiveSupport::TestCase + setup do + @api_bestname = users(:api_bestnames) + @api_bestname.accreditation_date = Time.zone.now - 10.minutes + @api_bestname.accreditation_expire_date = @api_bestname.accreditation_date + 1.year + @api_bestname.save + end + + def test_should_record_data_to_apiuser + api_goodname = users(:api_goodnames) + + assert_nil api_goodname.accreditation_date + assert_nil api_goodname.accreditation_expire_date + + Actions::RecordDateOfTest.record_result_to_api_user(api_user: api_goodname, date: @api_bestname.accreditation_date) + + assert_equal api_goodname.accreditation_date, @api_bestname.accreditation_date + assert_equal api_goodname.accreditation_expire_date, @api_bestname.accreditation_expire_date + end +end diff --git a/test/system/admin_area/api_users_test.rb b/test/system/admin_area/api_users_test.rb index d79434ef6..8f7b73155 100644 --- a/test/system/admin_area/api_users_test.rb +++ b/test/system/admin_area/api_users_test.rb @@ -3,6 +3,7 @@ require 'application_system_test_case' class AdminApiUsersSystemTest < ApplicationSystemTestCase setup do sign_in users(:admin) + @registrar = registrars(:bestnames) end def test_shows_api_user_list @@ -11,4 +12,71 @@ class AdminApiUsersSystemTest < ApplicationSystemTestCase api_user = users(:api_bestnames) assert_link api_user.username, href: admin_registrar_api_user_path(api_user.registrar, api_user) end + + def test_should_display_tests_button_in_api_user + visit admin_api_users_path + + assert_button 'Set Test' + assert_no_button 'Remove Test' + end + + def test_should_display_remove_test_if_there_accreditated_apiuser + date = Time.zone.now - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_api_users_path + + assert_button 'Remove Test' + end + + def test_should_not_display_remove_test_if_api_user_accreditation_date_is_expired + date = Time.zone.now - 1.year - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_api_users_path + + assert_no_button 'Remove' + end + + def test_should_display_tests_button_in_api_user_details + api_user = @registrar.api_users.first + + visit admin_api_user_path(api_user) + assert_button 'Set Test' + assert_no_button 'Remove Test' + end + + def test_should_display_remove_test_in_api_user_details_if_there_accreditated_apiuser + date = Time.zone.now - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_api_user_path(api_user) + + assert_button 'Remove Test' + end + + def test_should_not_display_remove_test_if_api_user_accreditation_date_is_expired_in_api_details + date = Time.zone.now - 1.year - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_api_user_path(api_user) + + assert_no_button 'Remove' + end end diff --git a/test/system/admin_area/registrars_test.rb b/test/system/admin_area/registrars_test.rb index f3ee31020..aa61d10e3 100644 --- a/test/system/admin_area/registrars_test.rb +++ b/test/system/admin_area/registrars_test.rb @@ -93,4 +93,70 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase assert_text 'Language English' assert_text 'billing@bestnames.test' end + + def test_should_display_btn_for_set_test_date + visit admin_registrars_path + + assert_button 'Set Test' + assert_no_button 'Remove Test' + end + + def test_should_display_remove_test_if_there_accreditated_registrars + date = Time.zone.now - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_registrars_path + + assert_button 'Remove Test' + end + + def test_should_not_display_remove_test_if_accreditation_date_is_expired + date = Time.zone.now - 1.year - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_registrars_path + + assert_no_button 'Remove' + end + + def test_should_display_tests_button_in_registrar_deftails + visit admin_registrar_path(@registrar) + + assert_button 'Set Test' + assert_no_button 'Remove Test' + end + + def test_should_display_remove_test_if_there_accreditated_registrars_in_registrar_details + date = Time.zone.now - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_registrar_path(@registrar) + + assert_button 'Remove Test' + end + + def test_should_not_display_remove_test_if_accreditation_date_is_expired_in_registrar_details + date = Time.zone.now - 1.year - 10.minutes + + api_user = @registrar.api_users.first + api_user.accreditation_date = date + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + visit admin_registrar_path(@registrar) + + assert_no_button 'Remove' + end end \ No newline at end of file