Skip to content

Commit

Permalink
test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
olegphenomenon committed Dec 13, 2021
1 parent c2e2d93 commit 27c4d31
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
7 changes: 3 additions & 4 deletions app/controllers/admin/api_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ 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'])

if response.code == "200"
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'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/registrars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down
14 changes: 3 additions & 11 deletions app/jobs/sync_accredited_users_job.rb
Original file line number Diff line number Diff line change
@@ -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']

Expand All @@ -24,7 +16,7 @@ def perform
logger.warn 'User not found'
end

return
nil
end

private
Expand All @@ -35,4 +27,4 @@ def base_get_request(uri:, port:)

http.request(req)
end
end
end
6 changes: 4 additions & 2 deletions test/integration/admin_area/api_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/integration/admin_area/registrars_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 27c4d31

Please sign in to comment.