Merge remote-tracking branch 'pleroma/develop' into poll-notification-fixes
This commit is contained in:
commit
62bf6d67e3
361 changed files with 8361 additions and 2945 deletions
|
|
@ -26,6 +26,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
|
@ -500,7 +505,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["tag"] == ["2hu"]
|
||||
assert Object.tags(object) == ["2hu"]
|
||||
end
|
||||
|
||||
test "it adds emoji in the object" do
|
||||
|
|
@ -521,7 +526,28 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"})
|
||||
|
||||
assert %{"blank" => url} = Object.normalize(activity).data["emoji"]
|
||||
assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png"
|
||||
assert url == "#{Pleroma.Web.Endpoint.url()}/emoji/blank.png"
|
||||
end
|
||||
|
||||
test "it copies emoji from the subject of the parent post" do
|
||||
%Object{} =
|
||||
object =
|
||||
Object.normalize("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f",
|
||||
fetch: true
|
||||
)
|
||||
|
||||
activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, reply_activity} =
|
||||
CommonAPI.post(user, %{
|
||||
in_reply_to_id: activity.id,
|
||||
status: ":joker_disapprove:",
|
||||
spoiler_text: ":joker_smile:"
|
||||
})
|
||||
|
||||
assert Object.normalize(reply_activity).data["emoji"]["joker_smile"]
|
||||
refute Object.normalize(reply_activity).data["emoji"]["joker_disapprove"]
|
||||
end
|
||||
|
||||
test "deactivated users can't post" do
|
||||
|
|
@ -578,7 +604,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>"
|
||||
assert object.data["source"] == post
|
||||
end
|
||||
|
||||
|
|
@ -808,13 +834,17 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
test "activity not found error", %{user: user} do
|
||||
assert {:error, :not_found} = CommonAPI.pin("id", user)
|
||||
end
|
||||
|
||||
test "pin status", %{user: user, activity: activity} do
|
||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id = activity.id
|
||||
%{data: %{"id" => object_id}} = Object.normalize(activity)
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
assert user.pinned_objects |> Map.keys() == [object_id]
|
||||
end
|
||||
|
||||
test "pin poll", %{user: user} do
|
||||
|
|
@ -826,10 +856,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id = activity.id
|
||||
%{data: %{"id" => object_id}} = Object.normalize(activity)
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
assert user.pinned_objects |> Map.keys() == [object_id]
|
||||
end
|
||||
|
||||
test "unlisted statuses can be pinned", %{user: user} do
|
||||
|
|
@ -840,7 +871,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
test "only self-authored can be pinned", %{activity: activity} do
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
|
||||
assert {:error, :ownership_error} = CommonAPI.pin(activity.id, user)
|
||||
end
|
||||
|
||||
test "max pinned statuses", %{user: user, activity: activity_one} do
|
||||
|
|
@ -850,8 +881,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert {:error, "You have already pinned the maximum number of statuses"} =
|
||||
CommonAPI.pin(activity_two.id, user)
|
||||
assert {:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity_two.id, user)
|
||||
end
|
||||
|
||||
test "only public can be pinned", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "private status", visibility: "private"})
|
||||
{:error, :visibility_error} = CommonAPI.pin(activity.id, user)
|
||||
end
|
||||
|
||||
test "unpin status", %{user: user, activity: activity} do
|
||||
|
|
@ -865,7 +900,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: []} = user
|
||||
assert user.pinned_objects == %{}
|
||||
end
|
||||
|
||||
test "should unpin when deleting a status", %{user: user, activity: activity} do
|
||||
|
|
@ -877,7 +912,40 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{pinned_activities: []} = user
|
||||
assert user.pinned_objects == %{}
|
||||
end
|
||||
|
||||
test "ephemeral activity won't be deleted if was pinned", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "Hello!", expires_in: 601})
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
|
||||
{:ok, _activity} = CommonAPI.pin(activity.id, user)
|
||||
refute Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
|
||||
user = refresh_record(user)
|
||||
{:ok, _} = CommonAPI.unpin(activity.id, user)
|
||||
|
||||
# recreates expiration job on unpin
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||
end
|
||||
|
||||
test "ephemeral activity deletion job won't be deleted on pinning error", %{
|
||||
user: user,
|
||||
activity: activity
|
||||
} do
|
||||
clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
{:ok, _activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
{:ok, activity2} = CommonAPI.post(user, %{status: "another status", expires_in: 601})
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
|
||||
|
||||
user = refresh_record(user)
|
||||
{:error, :pinned_statuses_limit_reached} = CommonAPI.pin(activity2.id, user)
|
||||
|
||||
assert Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity2.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue