From 27c4d31e955e183b01e82d277c83ce2b35266e9a Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 13 Dec 2021 10:54:09 +0200 Subject: [PATCH] test refactoring --- app/controllers/admin/api_users_controller.rb | 7 +++---- app/controllers/admin/registrars_controller.rb | 2 +- app/jobs/sync_accredited_users_job.rb | 14 +++----------- test/integration/admin_area/api_users_test.rb | 6 ++++-- test/integration/admin_area/registrars_test.rb | 4 +++- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/api_users_controller.rb b/app/controllers/admin/api_users_controller.rb index 01ac6ae882..5b9bdf7339 100644 --- a/app/controllers/admin/api_users_controller.rb +++ b/app/controllers/admin/api_users_controller.rb @@ -50,7 +50,7 @@ def destroy 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'] || 'http://testapi.test') + "?username=#{user_api.username}&identity_code=#{user_api.identity_code}") + uri = URI.parse((ENV['registry_demo_registrar_api_user_url']) + "?username=#{user_api.username}&identity_code=#{user_api.identity_code}") response = base_get_request(uri: uri, port: ENV['registry_demo_registrar_port']) @@ -58,9 +58,8 @@ def set_test_date_to_api_user result = JSON.parse(response.body) demo_user_api = result['user_api'] - Actions::RecordDateOfTest.record_result_to_api_user( - api_user:user_api, - date: demo_user_api['accreditation_date']) unless demo_user_api.empty? + Actions::RecordDateOfTest.record_result_to_api_user(api_user:user_api, + date: demo_user_api['accreditation_date']) unless demo_user_api.empty? return redirect_to request.referrer, notice: 'User Api found' else return redirect_to request.referrer, notice: 'User Api no found or not accriditated yet' diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index bc8c7e6003..0d8e7c647d 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -60,7 +60,7 @@ def destroy def set_test_date registrar = Registrar.find(params[:registrar_id]) - uri = URI.parse((ENV['registry_demo_registrar_results_url'] || 'http://testapi.test') + "?registrar_name=#{registrar.name}") + uri = URI.parse((ENV['registry_demo_registrar_results_url']) + "?registrar_name=#{registrar.name}") response = base_get_request(uri: uri, port: ENV['registry_demo_registrar_port']) diff --git a/app/jobs/sync_accredited_users_job.rb b/app/jobs/sync_accredited_users_job.rb index 8e02956e5c..8349d69f63 100644 --- a/app/jobs/sync_accredited_users_job.rb +++ b/app/jobs/sync_accredited_users_job.rb @@ -1,18 +1,10 @@ class SyncAccreditedUsersJob < ApplicationJob def perform - # apiusers_from_test = Actions::GetAccrResultsFromAnotherDb.list_of_accredated_users - - # return if apiusers_from_test.nil? - - # apiusers_from_test.each do |api| - # a = ApiUser.find_by(username: api.username, identity_code: api.identity_code) - # Actions::RecordDateOfTest.record_result_to_api_user(a, api.accreditation_date) unless a.nil? - # end uri = URI.parse(ENV['registry_demo_accredited_users_url']) response = base_get_request(uri: uri, port: ENV['registry_demo_registrar_port']) - if response.code == "200" + if response.code == '200' result = JSON.parse(response.body) users = result['users'] @@ -24,7 +16,7 @@ def perform logger.warn 'User not found' end - return + nil end private @@ -35,4 +27,4 @@ def base_get_request(uri:, port:) http.request(req) end -end \ No newline at end of file +end diff --git a/test/integration/admin_area/api_users_test.rb b/test/integration/admin_area/api_users_test.rb index f0ae5620ad..c8d9079dda 100644 --- a/test/integration/admin_area/api_users_test.rb +++ b/test/integration/admin_area/api_users_test.rb @@ -4,6 +4,8 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers setup do + ENV['registry_demo_registrar_api_user_url'] = 'http://registry.test:3000/api/v1/accreditation_center/show_api_user' + ENV['registry_demo_registrar_port'] = '3000' @api_user = users(:api_bestnames) sign_in users(:admin) end @@ -22,14 +24,14 @@ def test_set_test_date_to_api_user assert_equal api_user.accreditation_date, date # api_v1_accreditation_center_show_api_user_url - stub_request(:get, "http://registry.test:3000/api/v1/accreditation_center/show_api_user?identity_code=#{@api_user.identity_code}&username=#{@api_user.username}"). + stub_request(:get, "http://registry.test:3000/api/v1/accreditation_center/show_api_user?username=#{@api_user.username}&identity_code=#{@api_user.identity_code}"). with( headers: { 'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby' }).to_return(status: 200, body: { code: 200, user_api: api_user }.to_json, headers: {}) - post set_test_date_to_api_user_admin_registrars_path, params: { user_api_id: @api_user.id }, headers: { "HTTP_REFERER" => root_path } + post set_test_date_to_api_user_admin_registrars_path, params: { user_api_id: @api_user.id }, headers: { 'HTTP_REFERER' => root_path } @api_user.reload assert_equal @api_user.accreditation_date.to_date, api_user.accreditation_date.to_date assert_equal @api_user.accreditation_expire_date.to_date, api_user.accreditation_expire_date.to_date diff --git a/test/integration/admin_area/registrars_test.rb b/test/integration/admin_area/registrars_test.rb index 4367699637..80a88d6aca 100644 --- a/test/integration/admin_area/registrars_test.rb +++ b/test/integration/admin_area/registrars_test.rb @@ -4,6 +4,8 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers setup do + ENV['registry_demo_registrar_results_url'] = 'http://registry.test:3000/api/v1/accreditation_center/results' + ENV['registry_demo_registrar_port'] = '3000' @registrar = registrars(:bestnames) sign_in users(:admin) end @@ -34,7 +36,7 @@ def test_set_test_date 'User-Agent'=>'Ruby' }).to_return(status: 200, body: { code: 200, registrar_users: [api_user] }.to_json, headers: {}) - post set_test_date_admin_registrars_path, params: { registrar_id: @registrar.id }, headers: { "HTTP_REFERER" => root_path } + post set_test_date_admin_registrars_path, params: { registrar_id: @registrar.id }, headers: { 'HTTP_REFERER' => root_path } @registrar.reload assert_equal @registrar.api_users.first.accreditation_date.to_date, api_user.accreditation_date.to_date