From 95f5bad64b46674cbfa86e32ccf9c6570738d6a2 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Fri, 10 Dec 2021 17:07:39 +0200 Subject: [PATCH] added registrar controller tests --- .../admin/registrars_controller.rb | 4 ++-- .../actions/record_date_of_test.rb | 9 -------- .../integration/admin_area/registrars_test.rb | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/registrars_controller.rb b/app/controllers/admin/registrars_controller.rb index 9c2485813..08dbbef2b 100644 --- a/app/controllers/admin/registrars_controller.rb +++ b/app/controllers/admin/registrars_controller.rb @@ -93,8 +93,8 @@ module Admin return redirect_to request.referrer, 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(a, api.accreditation_date) unless a.nil? + 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' diff --git a/app/interactions/actions/record_date_of_test.rb b/app/interactions/actions/record_date_of_test.rb index 53d309948..229929429 100644 --- a/app/interactions/actions/record_date_of_test.rb +++ b/app/interactions/actions/record_date_of_test.rb @@ -5,18 +5,9 @@ module Actions TEST_DEADLINE = 1.year.freeze def record_result_to_api_user(api_user:, date:) - p "+++++++++++" - p api_user - p "-----------" - p DateTime.parse(date) - p "+++++++++++" - api_user.accreditation_date = date api_user.accreditation_expire_date = api_user.accreditation_date + TEST_DEADLINE api_user.save - - # api_user.update(accreditation_date: date, - # accreditation_expire_date: DateTime.parse(date) + TEST_DEADLINE) end end end diff --git a/test/integration/admin_area/registrars_test.rb b/test/integration/admin_area/registrars_test.rb index 552650791..436769963 100644 --- a/test/integration/admin_area/registrars_test.rb +++ b/test/integration/admin_area/registrars_test.rb @@ -17,4 +17,27 @@ class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest assert_equal new_iban, @registrar.iban end + + def test_set_test_date + api_user = @registrar.api_users.first.dup + api_user.accreditation_date = Time.zone.now - 10.minutes + api_user.accreditation_expire_date = api_user.accreditation_date + 1.year + api_user.save + + 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( + 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 } + @registrar.reload + + assert_equal @registrar.api_users.first.accreditation_date.to_date, api_user.accreditation_date.to_date + assert_equal @registrar.api_users.first.accreditation_expire_date.to_date, api_user.accreditation_expire_date.to_date + end end