@ -53,7 +53,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
{ :ok , _ } = CommonAPI . post ( user_two , %{ " status " = > " This isn't " } )
{ :ok , _ } = CommonAPI . post ( user_two , %{ " status " = > " This isn't " } )
results =
results =
get ( conn , " /api/v2/search " , %{ " q " = > " 2hu # private " } )
conn
|> get ( " /api/v2/search " , %{ " q " = > " 2hu # private " } )
|> json_response ( 200 )
|> json_response ( 200 )
[ account | _ ] = results [ " accounts " ]
[ account | _ ] = results [ " accounts " ]
@ -73,6 +74,30 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
[ status ] = results [ " statuses " ]
[ status ] = results [ " statuses " ]
assert status [ " id " ] == to_string ( activity . id )
assert status [ " id " ] == to_string ( activity . id )
end
end
test " excludes a blocked users from search results " , %{ conn : conn } do
user = insert ( :user )
user_smith = insert ( :user , %{ nickname : " Agent " , name : " I love 2hu " } )
user_neo = insert ( :user , %{ nickname : " Agent Neo " , name : " Agent " } )
{ :ok , act1 } = CommonAPI . post ( user , %{ " status " = > " This is about 2hu private 天子 " } )
{ :ok , act2 } = CommonAPI . post ( user_smith , %{ " status " = > " Agent Smith " } )
{ :ok , act3 } = CommonAPI . post ( user_neo , %{ " status " = > " Agent Smith " } )
Pleroma.User . block ( user , user_smith )
results =
conn
|> assign ( :user , user )
|> assign ( :token , insert ( :oauth_token , user : user , scopes : [ " read " ] ) )
|> get ( " /api/v2/search " , %{ " q " = > " Agent " } )
|> json_response ( 200 )
status_ids = Enum . map ( results [ " statuses " ] , fn g -> g [ " id " ] end )
assert act3 . id in status_ids
refute act2 . id in status_ids
refute act1 . id in status_ids
end
end
end
describe " .account_search " do
describe " .account_search " do
@ -146,11 +171,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
{ :ok , _ } = CommonAPI . post ( user_two , %{ " status " = > " This isn't " } )
{ :ok , _ } = CommonAPI . post ( user_two , %{ " status " = > " This isn't " } )
conn =
results =
conn
conn
|> get ( " /api/v1/search " , %{ " q " = > " 2hu " } )
|> get ( " /api/v1/search " , %{ " q " = > " 2hu " } )
|> json_response ( 200 )
assert results = json_response ( conn , 200 )
[ account | _ ] = results [ " accounts " ]
[ account | _ ] = results [ " accounts " ]
assert account [ " id " ] == to_string ( user_three . id )
assert account [ " id " ] == to_string ( user_three . id )
@ -168,11 +192,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
" status " = > " check out https://shitposter.club/notice/2827873 "
" status " = > " check out https://shitposter.club/notice/2827873 "
} )
} )
conn =
results =
conn
conn
|> get ( " /api/v1/search " , %{ " q " = > " https://shitposter.club/notice/2827873 " } )
|> get ( " /api/v1/search " , %{ " q " = > " https://shitposter.club/notice/2827873 " } )
|> json_response ( 200 )
assert results = json_response ( conn , 200 )
[ status , %{ " id " = > ^ activity_id } ] = results [ " statuses " ]
[ status , %{ " id " = > ^ activity_id } ] = results [ " statuses " ]
@ -189,11 +212,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
} )
} )
capture_log ( fn ->
capture_log ( fn ->
conn =
results =
conn
conn
|> get ( " /api/v1/search " , %{ " q " = > Object . normalize ( activity ) . data [ " id " ] } )
|> get ( " /api/v1/search " , %{ " q " = > Object . normalize ( activity ) . data [ " id " ] } )
|> json_response ( 200 )
assert results = json_response ( conn , 200 )
[ ] = results [ " statuses " ]
[ ] = results [ " statuses " ]
end )
end )
@ -202,23 +224,23 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
test " search fetches remote accounts " , %{ conn : conn } do
test " search fetches remote accounts " , %{ conn : conn } do
user = insert ( :user )
user = insert ( :user )
conn =
results =
conn
conn
|> assign ( :user , user )
|> assign ( :user , user )
|> assign ( :token , insert ( :oauth_token , user : user , scopes : [ " read " ] ) )
|> assign ( :token , insert ( :oauth_token , user : user , scopes : [ " read " ] ) )
|> get ( " /api/v1/search " , %{ " q " = > " mike@osada.macgirvin.com " , " resolve " = > " true " } )
|> get ( " /api/v1/search " , %{ " q " = > " mike@osada.macgirvin.com " , " resolve " = > " true " } )
|> json_response ( 200 )
assert results = json_response ( conn , 200 )
[ account ] = results [ " accounts " ]
[ account ] = results [ " accounts " ]
assert account [ " acct " ] == " mike@osada.macgirvin.com "
assert account [ " acct " ] == " mike@osada.macgirvin.com "
end
end
test " search doesn't fetch remote accounts if resolve is false " , %{ conn : conn } do
test " search doesn't fetch remote accounts if resolve is false " , %{ conn : conn } do
conn =
results =
conn
conn
|> get ( " /api/v1/search " , %{ " q " = > " mike@osada.macgirvin.com " , " resolve " = > " false " } )
|> get ( " /api/v1/search " , %{ " q " = > " mike@osada.macgirvin.com " , " resolve " = > " false " } )
|> json_response ( 200 )
assert results = json_response ( conn , 200 )
assert [ ] == results [ " accounts " ]
assert [ ] == results [ " accounts " ]
end
end