@@ -154,4 +154,51 @@ class ProfileTest < ActiveSupport::TestCase
154154 refute Profile . new . authenticate_orcid ( '0009-0006-0987-5702' )
155155 end
156156 end
157+
158+ test 'visible' do
159+ visible = Profile . visible
160+ assert_includes visible , profiles ( :one )
161+ assert_includes visible , profiles ( :two )
162+ refute_includes visible , profiles ( :basic_user_profile )
163+ refute_includes visible , profiles ( :banned_user_profile )
164+ end
165+
166+ test 'starting_with' do
167+ regi = Profile . starting_with ( 'regi' )
168+ assert_includes regi , profiles ( :one )
169+ refute_includes regi , profiles ( :two )
170+
171+ user = Profile . starting_with ( 'user' )
172+ assert_includes user , profiles ( :one )
173+ refute_includes user , profiles ( :two )
174+
175+ bla = Profile . starting_with ( 'bla' )
176+ refute_includes bla , profiles ( :one )
177+ refute_includes bla , profiles ( :two )
178+
179+ ad = Profile . starting_with ( 'ad' )
180+ refute_includes ad , profiles ( :two )
181+ assert_includes ad , profiles ( :three )
182+ assert_includes ad , profiles ( :admin_trainer_profile )
183+ end
184+
185+ test 'query' do
186+ josi = Profile . query ( 'josi' )
187+ assert_equal 1 , josi . length
188+ assert_includes josi , profiles ( :trainer_one_profile ) . becomes ( Profile ) # Need to cast back to Profile because it is a Trainer otherwise
189+
190+ # Excludes unauthenticated orcids
191+ unauth = profiles ( :trainer_two_profile )
192+ assert_includes Profile . starting_with ( 'luci' ) , unauth
193+ unauth_q = Profile . query ( 'luci' )
194+ assert_equal 0 , unauth_q . length
195+
196+ # Excludes non-visible:
197+ banned = profiles ( :banned_user_profile )
198+ banned . update! ( firstname : 'Banned' )
199+ assert banned . authenticate_orcid ( '0009-0006-0987-5702' )
200+ assert_includes Profile . starting_with ( 'banned' ) , banned
201+ banned_q = Profile . query ( 'Banned' )
202+ assert_equal 0 , banned_q . length
203+ end
157204end
0 commit comments