mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
test refactoring
This commit is contained in:
parent
4567e56457
commit
72f184d9b0
7 changed files with 65 additions and 73 deletions
|
@ -17,8 +17,7 @@ module Admin
|
|||
|
||||
if @api_user.valid?
|
||||
@api_user.save!
|
||||
redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user),
|
||||
notice: t('.created')
|
||||
redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user), notice: t('.created')
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
|
@ -35,8 +34,7 @@ module Admin
|
|||
|
||||
if @api_user.valid?
|
||||
@api_user.save!
|
||||
redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user),
|
||||
notice: t('.updated')
|
||||
redirect_to admin_registrar_api_user_path(@api_user.registrar, @api_user), notice: t('.updated')
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
|
@ -50,7 +48,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'] || '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,8 +56,7 @@ module Admin
|
|||
result = JSON.parse(response.body)
|
||||
demo_user_api = result['user_api']
|
||||
|
||||
Actions::RecordDateOfTest.record_result_to_api_user(
|
||||
api_user:user_api,
|
||||
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
|
||||
|
|
|
@ -60,17 +60,17 @@ module Admin
|
|||
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'])
|
||||
|
||||
if response.code == "200"
|
||||
return record_result_for_each_api_user(response: response)
|
||||
else
|
||||
return redirect_to request.referrer, notice: 'Registrar no found'
|
||||
return redirect_to request.referer, notice: 'Registrar no found'
|
||||
end
|
||||
|
||||
redirect_to request.referrer, notice: 'Something goes wrong'
|
||||
redirect_to request.referer, notice: 'Something goes wrong'
|
||||
end
|
||||
|
||||
def remove_test_date
|
||||
|
@ -81,7 +81,7 @@ module Admin
|
|||
api.save
|
||||
end
|
||||
|
||||
redirect_to request.referrer
|
||||
redirect_to request.referer
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -90,14 +90,14 @@ module Admin
|
|||
result = JSON.parse(response.body)
|
||||
registrar_users = result['registrar_users']
|
||||
|
||||
return redirect_to request.referrer, notice: 'Registrar found, but not accreditated yet' if registrar_users.empty?
|
||||
return redirect_to request.referer, notice: 'Registrar found, but not accreditated yet' if registrar_users.empty?
|
||||
|
||||
registrar_users.each do |api|
|
||||
a = ApiUser.find_by(username: api['username'], identity_code: api['identity_code'])
|
||||
Actions::RecordDateOfTest.record_result_to_api_user(api_user: a, date: api['accreditation_date']) unless a.nil?
|
||||
end
|
||||
|
||||
redirect_to request.referrer, notice: 'Registrar found'
|
||||
redirect_to request.referer, notice: 'Registrar found'
|
||||
end
|
||||
|
||||
def base_get_request(uri:, port:)
|
||||
|
|
|
@ -1,22 +1,11 @@
|
|||
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']
|
||||
|
||||
users.each do |api|
|
||||
result['users'].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
|
||||
|
@ -24,7 +13,7 @@ class SyncAccreditedUsersJob < ApplicationJob
|
|||
logger.warn 'User not found'
|
||||
end
|
||||
|
||||
return
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -5416,5 +5416,3 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20220504090512'),
|
||||
('20220524130709'),
|
||||
('20220818075833');
|
||||
|
||||
|
||||
|
|
|
@ -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,16 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest
|
|||
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}").
|
||||
with(
|
||||
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 }
|
||||
'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 }
|
||||
@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
|
||||
|
|
|
@ -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
|
||||
|
@ -26,15 +28,17 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest
|
|||
|
||||
assert_nil @registrar.api_users.first.accreditation_date
|
||||
|
||||
stub_request(:get, "http://registry.test:3000/api/v1/accreditation_center/results?registrar_name=#{@registrar.name}").
|
||||
with(
|
||||
stub_request(:get, "http://registry.test:3000/api/v1/accreditation_center/results?registrar_name=#{@registrar.name}")
|
||||
.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, registrar_users: [api_user] }.to_json, 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, 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue