@@ -491,71 +491,38 @@ class UsersControllerTest < ActionController::TestCase
491491 end
492492 end
493493
494- test 'authenticate orcid logged-in user' do
495- sign_in users ( :regular_user )
496-
497- post :authenticate_orcid
498-
499- assert_redirected_to /https:\/ \/ sandbox\. orcid\. org\/ oauth\/ authorize\? .+/
500- end
501-
502- test 'do not authenticate orcid if user not logged-in' do
503- post :authenticate_orcid
504-
505- assert_redirected_to new_user_session_path
506- end
494+ test 'should show authenticate orcid button if own profile' do
495+ user = users ( :private_user )
496+ assert user . profile . orcid . present?
497+ refute user . profile . orcid_authenticated?
507498
508- test 'handle callback and assign orcid if free' do
509- mock_images
510- user = users ( :regular_user )
511499 sign_in user
512500
513- VCR . use_cassette ( 'orcid/get_token_free_orcid' ) do
514- get :orcid_callback , params : { code : '123xyz' }
515- end
516-
517- profile = user . profile . reload
518- assert_equal '0009-0006-0987-5702' , profile . orcid
519- assert profile . orcid_authenticated?
520- assert_redirected_to user
521- end
522-
523- test 'handle callback and assign orcid if unauthenticated' do
524- mock_images
525- user = users ( :regular_user )
526- sign_in user
527-
528- VCR . use_cassette ( 'orcid/get_token_unauth_orcid' ) do
529- get :orcid_callback , params : { code : '123xyz' }
530- end
501+ get :show , params : { id : user }
531502
532- profile = user . profile . reload
533- assert_equal '0000-0002-0048-3300' , profile . orcid
534- assert profile . orcid_authenticated?
535- assert_redirected_to user
503+ assert_response :success
504+ assert_select '#sidebar button' , text : 'Authenticate your ORCID'
536505 end
537506
538- test 'handle callback but do not assign orcid if already used ' do
539- mock_images
540- user = users ( :regular_user )
541- sign_in user
507+ test 'should not show authenticate orcid button if not own profile ' do
508+ user = users ( :private_user )
509+ assert user . profile . orcid . present?
510+ refute user . profile . orcid_authenticated?
542511
543- VCR . use_cassette ( 'orcid/get_token_existing_orcid' ) do
544- get :orcid_callback , params : { code : '123xyz' }
545- end
512+ get :show , params : { id : user }
546513
547- profile = user . profile . reload
548- assert profile . orcid . blank?
549- refute profile . orcid_authenticated?
550- assert_redirected_to user
551- assert_includes flash [ :error ] , 'ORCID has already been'
514+ assert_response :success
515+ assert_select '#sidebar button' , text : 'Authenticate your ORCID' , count : 0
552516 end
553517
554- test 'do not handle callback if not logged-in' do
555- mock_images
518+ test 'should not show authenticate orcid button if already authenticated' do
519+ user = users ( :trainer_user )
520+ assert user . profile . orcid . present?
521+ assert user . profile . orcid_authenticated?
556522
557- get :orcid_callback , params : { code : '123xyz' }
523+ get :show , params : { id : user }
558524
559- assert_redirected_to new_user_session_path
525+ assert_response :success
526+ assert_select '#sidebar button' , text : 'Authenticate your ORCID' , count : 0
560527 end
561528end
0 commit comments