MastoAPI StatusController: add tests for fetching context via Activity
This commit is contained in:
parent
ba8235ef50
commit
7c93cd351b
1 changed files with 265 additions and 1 deletions
|
|
@ -812,7 +812,34 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
{:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params)
|
||||
{:ok, remote_activity} = ObanHelpers.perform(job)
|
||||
|
||||
%{locals: [id1, id2], remote: remote_activity.id, context: context}
|
||||
{:ok, %{id: local_to_local_react_id}} = CommonAPI.react_with_emoji(id1, local_user_2, "🦊")
|
||||
|
||||
{:ok, %{id: local_to_remote_react_id}} =
|
||||
CommonAPI.react_with_emoji(remote_activity.id, local_user_1, "🦊")
|
||||
|
||||
{:ok, %{id: remote_to_local_react_id}} = CommonAPI.react_with_emoji(id1, remote_user, "🦊")
|
||||
|
||||
{:ok, %{id: remote_to_remote_react_id}} =
|
||||
CommonAPI.react_with_emoji(remote_activity.id, remote_user, "🦊")
|
||||
|
||||
%{
|
||||
locals: [id1, id2],
|
||||
remote: remote_activity.id,
|
||||
local_interactions: [local_to_local_react_id, local_to_remote_react_id],
|
||||
remote_interactions: [remote_to_local_react_id, remote_to_remote_react_id],
|
||||
context: context
|
||||
}
|
||||
end
|
||||
|
||||
defp extract_activity_ids_from_response(list) when is_list(list) do
|
||||
list
|
||||
|> Enum.map(& &1["id"])
|
||||
end
|
||||
|
||||
defp all_ids_included?(checked, authority) when is_list(checked) and is_list(authority) do
|
||||
set1 = MapSet.new(checked)
|
||||
set2 = MapSet.new(authority)
|
||||
MapSet.equal?(set1, set2)
|
||||
end
|
||||
|
||||
defp local_interactions_to_remote do
|
||||
|
|
@ -1182,6 +1209,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
# Note: Context route on EmojiReact/Announce activities puts everything into the ancestors field
|
||||
describe "getting status contexts restricted unauthenticated for local and remote" do
|
||||
setup do: local_and_remote_context_activities()
|
||||
|
||||
|
|
@ -1207,6 +1235,40 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "if user is unauthenticated Activity interactions", %{
|
||||
conn: conn,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
assert json_response_and_validate_schema(res_conn, 200) == %{
|
||||
"ancestors" => [],
|
||||
"descendants" => []
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{locals: [post_id, reply_id], remote: remote_reply_id} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{post_id}/context")
|
||||
|
|
@ -1240,6 +1302,47 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post_id in ancestor_ids
|
||||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is authenticated Activity interactions", %{
|
||||
locals: [post_id, reply_id],
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
all_ids = [post_id, reply_id, remote_reply_id]
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting status contexts restricted unauthenticated for local" do
|
||||
|
|
@ -1289,6 +1392,45 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is unauthenticated Activity interactions", %{
|
||||
conn: conn,
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, [remote_reply_id])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, [remote_reply_id])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, [remote_reply_id])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, [remote_reply_id])
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{locals: [post_id, reply_id], remote: remote_reply_id} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{post_id}/context")
|
||||
|
|
@ -1322,6 +1464,47 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post_id in ancestor_ids
|
||||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is authenticated Activity interactions", %{
|
||||
locals: [post_id, reply_id],
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
all_ids = [post_id, reply_id, remote_reply_id]
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting status contexts restricted unauthenticated for remote" do
|
||||
|
|
@ -1371,6 +1554,46 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert remote_reply_id not in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is unauthenticated Activity interactions", %{
|
||||
conn: conn,
|
||||
locals: [post_id, reply_id],
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
all_ids = [post_id, reply_id]
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{locals: [post_id, reply_id], remote: remote_reply_id} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{post_id}/context")
|
||||
|
|
@ -1404,6 +1627,47 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post_id in ancestor_ids
|
||||
assert remote_reply_id in descendant_ids
|
||||
end
|
||||
|
||||
test "if user is authenticated Activity interactions", %{
|
||||
locals: [post_id, reply_id],
|
||||
remote: remote_reply_id,
|
||||
local_interactions: [local_to_local, local_to_remote],
|
||||
remote_interactions: [remote_to_local, remote_to_remote]
|
||||
} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
all_ids = [post_id, reply_id, remote_reply_id]
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors1, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids1 = extract_activity_ids_from_response(ancestors1)
|
||||
assert all_ids_included?(ancestor_ids1, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors2, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids2 = extract_activity_ids_from_response(ancestors2)
|
||||
assert all_ids_included?(ancestor_ids2, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_local}/context")
|
||||
|
||||
%{"ancestors" => ancestors3, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids3 = extract_activity_ids_from_response(ancestors3)
|
||||
assert all_ids_included?(ancestor_ids3, all_ids)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote_to_remote}/context")
|
||||
|
||||
%{"ancestors" => ancestors4, "descendants" => []} =
|
||||
json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
ancestor_ids4 = extract_activity_ids_from_response(ancestors4)
|
||||
assert all_ids_included?(ancestor_ids4, all_ids)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleting a status" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue