Browse Source

Announcements: Fix all tests.

revert-6dd1575c
lain 4 years ago
parent
commit
23e248694d
21 changed files with 64 additions and 136 deletions
  1. +5
    -4
      lib/pleroma/web/activity_pub/relay.ex
  2. +1
    -4
      lib/pleroma/web/activity_pub/side_effects.ex
  3. +1
    -1
      lib/pleroma/web/mastodon_api/controllers/status_controller.ex
  4. +3
    -3
      test/notification_test.exs
  5. +4
    -1
      test/tasks/user_test.exs
  6. +2
    -2
      test/user_test.exs
  7. +8
    -77
      test/web/activity_pub/activity_pub_test.exs
  8. +6
    -9
      test/web/activity_pub/relay_test.exs
  9. +0
    -8
      test/web/activity_pub/side_effects_test.exs
  10. +1
    -1
      test/web/activity_pub/transmogrifier_test.exs
  11. +1
    -1
      test/web/activity_pub/utils_test.exs
  12. +1
    -1
      test/web/activity_pub/views/object_view_test.exs
  13. +3
    -1
      test/web/admin_api/admin_api_controller_test.exs
  14. +5
    -0
      test/web/common_api/common_api_test.exs
  15. +3
    -3
      test/web/mastodon_api/controllers/account_controller_test.exs
  16. +4
    -4
      test/web/mastodon_api/controllers/notification_controller_test.exs
  17. +9
    -9
      test/web/mastodon_api/controllers/status_controller_test.exs
  18. +1
    -1
      test/web/mastodon_api/views/notification_view_test.exs
  19. +2
    -2
      test/web/mastodon_api/views/status_view_test.exs
  20. +1
    -1
      test/web/push/impl_test.exs
  21. +3
    -3
      test/web/streamer/streamer_test.exs

+ 5
- 4
lib/pleroma/web/activity_pub/relay.ex View File

@@ -4,9 +4,10 @@


defmodule Pleroma.Web.ActivityPub.Relay do defmodule Pleroma.Web.ActivityPub.Relay do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
require Logger require Logger


@relay_nickname "relay" @relay_nickname "relay"
@@ -48,11 +49,11 @@ defmodule Pleroma.Web.ActivityPub.Relay do
end end
end end


@spec publish(any()) :: {:ok, Activity.t(), Object.t()} | {:error, any()}
@spec publish(any()) :: {:ok, Activity.t()} | {:error, any()}
def publish(%Activity{data: %{"type" => "Create"}} = activity) do def publish(%Activity{data: %{"type" => "Create"}} = activity) do
with %User{} = user <- get_actor(), with %User{} = user <- get_actor(),
%Object{} = object <- Object.normalize(activity) do
ActivityPub.announce(user, object, nil, true, false)
true <- Visibility.is_public?(activity) do
CommonAPI.repeat(activity.id, user)
else else
error -> format_error(error) error -> format_error(error)
end end


+ 1
- 4
lib/pleroma/web/activity_pub/side_effects.ex View File

@@ -11,7 +11,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils


def handle(object, meta \\ []) def handle(object, meta \\ [])
@@ -35,9 +34,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
def handle(%{data: %{"type" => "Announce"}} = object, meta) do def handle(%{data: %{"type" => "Announce"}} = object, meta) do
announced_object = Object.get_by_ap_id(object.data["object"]) announced_object = Object.get_by_ap_id(object.data["object"])


if Visibility.is_public?(object) do
Utils.add_announce_to_object(object, announced_object)
end
Utils.add_announce_to_object(object, announced_object)


Notification.create_notifications(object) Notification.create_notifications(object)
ActivityPub.stream_out(object) ActivityPub.stream_out(object)


+ 1
- 1
lib/pleroma/web/mastodon_api/controllers/status_controller.ex View File

@@ -210,7 +210,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do


@doc "POST /api/v1/statuses/:id/reblog" @doc "POST /api/v1/statuses/:id/reblog"
def reblog(%{assigns: %{user: user}, body_params: params} = conn, %{id: ap_id_or_id}) do def reblog(%{assigns: %{user: user}, body_params: params} = conn, %{id: ap_id_or_id}) do
with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user, params),
with {:ok, announce} <- CommonAPI.repeat(ap_id_or_id, user, params),
%Activity{} = announce <- Activity.normalize(announce.data) do %Activity{} = announce <- Activity.normalize(announce.data) do
try_render(conn, "show.json", %{activity: announce, for: user, as: :activity}) try_render(conn, "show.json", %{activity: announce, for: user, as: :activity})
end end


+ 3
- 3
test/notification_test.exs View File

@@ -648,7 +648,7 @@ defmodule Pleroma.NotificationTest do
status: "hey @#{other_user.nickname}!" status: "hey @#{other_user.nickname}!"
}) })


{:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
{:ok, activity_two} = CommonAPI.repeat(activity_one.id, third_user)


{enabled_receivers, _disabled_receivers} = {enabled_receivers, _disabled_receivers} =
Notification.get_notified_from_activity(activity_two) Notification.get_notified_from_activity(activity_two)
@@ -778,7 +778,7 @@ defmodule Pleroma.NotificationTest do


assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))


{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
{:ok, _} = CommonAPI.repeat(activity.id, other_user)


assert length(Notification.for_user(user)) == 1 assert length(Notification.for_user(user)) == 1


@@ -795,7 +795,7 @@ defmodule Pleroma.NotificationTest do


assert Enum.empty?(Notification.for_user(user)) assert Enum.empty?(Notification.for_user(user))


{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
{:ok, _} = CommonAPI.repeat(activity.id, other_user)


assert length(Notification.for_user(user)) == 1 assert length(Notification.for_user(user)) == 1




+ 4
- 1
test/tasks/user_test.exs View File

@@ -91,6 +91,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do


describe "running rm" do describe "running rm" do
test "user is deleted" do test "user is deleted" do
clear_config([:instance, :federating], true)
user = insert(:user) user = insert(:user)


with_mock Pleroma.Web.Federator, with_mock Pleroma.Web.Federator,
@@ -108,8 +109,10 @@ defmodule Mix.Tasks.Pleroma.UserTest do


test "a remote user's create activity is deleted when the object has been pruned" do test "a remote user's create activity is deleted when the object has been pruned" do
user = insert(:user) user = insert(:user)

{:ok, post} = CommonAPI.post(user, %{status: "uguu"}) {:ok, post} = CommonAPI.post(user, %{status: "uguu"})

clear_config([:instance, :federating], true)

object = Object.normalize(post) object = Object.normalize(post)
Object.prune(object) Object.prune(object)




+ 2
- 2
test/user_test.exs View File

@@ -992,7 +992,7 @@ defmodule Pleroma.UserTest do
user = insert(:user, local: true) user = insert(:user, local: true)


{:ok, activity} = CommonAPI.post(actor, %{status: "hello"}) {:ok, activity} = CommonAPI.post(actor, %{status: "hello"})
{:ok, announce, _} = CommonAPI.repeat(activity.id, user)
{:ok, announce} = CommonAPI.repeat(activity.id, user)


recipients = User.get_recipients_from_activity(announce) recipients = User.get_recipients_from_activity(announce)


@@ -1147,7 +1147,7 @@ defmodule Pleroma.UserTest do


{:ok, like} = CommonAPI.favorite(user, activity_two.id) {:ok, like} = CommonAPI.favorite(user, activity_two.id)
{:ok, like_two} = CommonAPI.favorite(follower, activity.id) {:ok, like_two} = CommonAPI.favorite(follower, activity.id)
{:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
{:ok, repeat} = CommonAPI.repeat(activity_two.id, user)


{:ok, job} = User.delete(user) {:ok, job} = User.delete(user)
{:ok, _user} = ObanHelpers.perform(job) {:ok, _user} = ObanHelpers.perform(job)


+ 8
- 77
test/web/activity_pub/activity_pub_test.exs View File

@@ -537,7 +537,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_one) assert Enum.member?(activities, activity_one)


{:ok, _user_relationship} = User.block(user, %{ap_id: activity_three.data["actor"]}) {:ok, _user_relationship} = User.block(user, %{ap_id: activity_three.data["actor"]})
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
{:ok, %{data: %{"object" => id}}} = CommonAPI.repeat(activity_three.id, booster)
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id) %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Activity.get_by_id(activity_three.id) activity_three = Activity.get_by_id(activity_three.id)


@@ -592,7 +592,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do


{:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"}) {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})


{:ok, activity_three, _} = CommonAPI.repeat(activity_two.id, friend)
{:ok, activity_three} = CommonAPI.repeat(activity_two.id, friend)


activities = activities =
ActivityPub.fetch_activities([], %{"blocking_user" => blocker}) ActivityPub.fetch_activities([], %{"blocking_user" => blocker})
@@ -618,7 +618,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do


followed_user = insert(:user) followed_user = insert(:user)
ActivityPub.follow(user, followed_user) ActivityPub.follow(user, followed_user)
{:ok, repeat_activity, _} = CommonAPI.repeat(activity.id, followed_user)
{:ok, repeat_activity} = CommonAPI.repeat(activity.id, followed_user)


activities = activities =
ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true}) ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
@@ -651,7 +651,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
another_user = insert(:user, %{ap_id: "https://#{domain}/@meanie2"}) another_user = insert(:user, %{ap_id: "https://#{domain}/@meanie2"})
bad_note = insert(:note, %{data: %{"actor" => another_user.ap_id}}) bad_note = insert(:note, %{data: %{"actor" => another_user.ap_id}})
bad_activity = insert(:note_activity, %{note: bad_note}) bad_activity = insert(:note_activity, %{note: bad_note})
{:ok, repeat_activity, _} = CommonAPI.repeat(bad_activity.id, domain_user)
{:ok, repeat_activity} = CommonAPI.repeat(bad_activity.id, domain_user)


activities = activities =
ActivityPub.fetch_activities([], %{"blocking_user" => blocker, "skip_preload" => true}) ActivityPub.fetch_activities([], %{"blocking_user" => blocker, "skip_preload" => true})
@@ -699,7 +699,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do


activity_three_actor = User.get_by_ap_id(activity_three.data["actor"]) activity_three_actor = User.get_by_ap_id(activity_three.data["actor"])
{:ok, _user_relationships} = User.mute(user, activity_three_actor) {:ok, _user_relationships} = User.mute(user, activity_three_actor)
{:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
{:ok, %{data: %{"object" => id}}} = CommonAPI.repeat(activity_three.id, booster)
%Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id) %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
activity_three = Activity.get_by_id(activity_three.id) activity_three = Activity.get_by_id(activity_three.id)


@@ -749,7 +749,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do


{:ok, user} = User.follow(user, booster) {:ok, user} = User.follow(user, booster)


{:ok, announce, _object} = CommonAPI.repeat(activity_three.id, booster)
{:ok, announce} = CommonAPI.repeat(activity_three.id, booster)


[announce_activity] = ActivityPub.fetch_activities([user.ap_id | User.following(user)]) [announce_activity] = ActivityPub.fetch_activities([user.ap_id | User.following(user)])


@@ -846,7 +846,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
booster = insert(:user) booster = insert(:user)
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster)


{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
{:ok, activity} = CommonAPI.repeat(activity.id, booster)


activities = ActivityPub.fetch_activities([], %{"muting_user" => user}) activities = ActivityPub.fetch_activities([], %{"muting_user" => user})


@@ -860,7 +860,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster)
{:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster) {:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster)


{:ok, activity, _} = CommonAPI.repeat(activity.id, booster)
{:ok, activity} = CommonAPI.repeat(activity.id, booster)


activities = ActivityPub.fetch_activities([], %{"muting_user" => user}) activities = ActivityPub.fetch_activities([], %{"muting_user" => user})


@@ -868,75 +868,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end end
end end


describe "announcing an object" do
test "adds an announce activity to the db" do
note_activity = insert(:note_activity)
object = Object.normalize(note_activity)
user = insert(:user)

{:ok, announce_activity, object} = ActivityPub.announce(user, object)
assert object.data["announcement_count"] == 1
assert object.data["announcements"] == [user.ap_id]

assert announce_activity.data["to"] == [
User.ap_followers(user),
note_activity.data["actor"]
]

assert announce_activity.data["object"] == object.data["id"]
assert announce_activity.data["actor"] == user.ap_id
assert announce_activity.data["context"] == object.data["context"]
end

test "reverts annouce from object on error" do
note_activity = insert(:note_activity)
object = Object.normalize(note_activity)
user = insert(:user)

with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
assert {:error, :reverted} = ActivityPub.announce(user, object)
end

reloaded_object = Object.get_by_ap_id(object.data["id"])
assert reloaded_object == object
refute reloaded_object.data["announcement_count"]
refute reloaded_object.data["announcements"]
end
end

describe "announcing a private object" do
test "adds an announce activity to the db if the audience is not widened" do
user = insert(:user)
{:ok, note_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
object = Object.normalize(note_activity)

{:ok, announce_activity, object} = ActivityPub.announce(user, object, nil, true, false)

assert announce_activity.data["to"] == [User.ap_followers(user)]

assert announce_activity.data["object"] == object.data["id"]
assert announce_activity.data["actor"] == user.ap_id
assert announce_activity.data["context"] == object.data["context"]
end

test "does not add an announce activity to the db if the audience is widened" do
user = insert(:user)
{:ok, note_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
object = Object.normalize(note_activity)

assert {:error, _} = ActivityPub.announce(user, object, nil, true, true)
end

test "does not add an announce activity to the db if the announcer is not the author" do
user = insert(:user)
announcer = insert(:user)
{:ok, note_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
object = Object.normalize(note_activity)

assert {:error, _} = ActivityPub.announce(announcer, object, nil, true, false)
end
end

describe "uploading files" do describe "uploading files" do
test "copies the file to the configured folder" do test "copies the file to the configured folder" do
file = %Plug.Upload{ file = %Plug.Upload{


+ 6
- 9
test/web/activity_pub/relay_test.exs View File

@@ -6,7 +6,6 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
use Pleroma.DataCase use Pleroma.DataCase


alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Relay
@@ -95,21 +94,20 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
end) end)


assert capture_log(fn -> assert capture_log(fn ->
assert Relay.publish(activity) == {:error, nil}
end) =~ "[error] error: nil"
assert Relay.publish(activity) == {:error, false}
end) =~ "[error] error: false"
end end


test_with_mock "returns announce activity and publish to federate", test_with_mock "returns announce activity and publish to federate",
Pleroma.Web.Federator, Pleroma.Web.Federator,
[:passthrough], [:passthrough],
[] do [] do
Pleroma.Config.put([:instance, :federating], true)
clear_config([:instance, :federating], true)
service_actor = Relay.get_actor() service_actor = Relay.get_actor()
note = insert(:note_activity) note = insert(:note_activity)
assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
assert {:ok, %Activity{} = activity} = Relay.publish(note)
assert activity.data["type"] == "Announce" assert activity.data["type"] == "Announce"
assert activity.data["actor"] == service_actor.ap_id assert activity.data["actor"] == service_actor.ap_id
assert activity.data["object"] == obj.data["id"]
assert called(Pleroma.Web.Federator.publish(activity)) assert called(Pleroma.Web.Federator.publish(activity))
end end


@@ -117,13 +115,12 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
Pleroma.Web.Federator, Pleroma.Web.Federator,
[:passthrough], [:passthrough],
[] do [] do
Pleroma.Config.put([:instance, :federating], false)
clear_config([:instance, :federating], false)
service_actor = Relay.get_actor() service_actor = Relay.get_actor()
note = insert(:note_activity) note = insert(:note_activity)
assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
assert {:ok, %Activity{} = activity} = Relay.publish(note)
assert activity.data["type"] == "Announce" assert activity.data["type"] == "Announce"
assert activity.data["actor"] == service_actor.ap_id assert activity.data["actor"] == service_actor.ap_id
assert activity.data["object"] == obj.data["id"]
refute called(Pleroma.Web.Federator.publish(activity)) refute called(Pleroma.Web.Federator.publish(activity))
end end
end end


+ 0
- 8
test/web/activity_pub/side_effects_test.exs View File

@@ -325,14 +325,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
assert user.ap_id in object.data["announcements"] assert user.ap_id in object.data["announcements"]
end end


test "does not add the announce to the original object if the announce is private", %{
private_announce: announce
} do
{:ok, announce, _} = SideEffects.handle(announce)
object = Object.get_by_ap_id(announce.data["object"])
assert object.data["announcement_count"] == nil
end

test "does not add the announce to the original object if the actor is a service actor", %{ test "does not add the announce to the original object if the actor is a service actor", %{
relay_announce: announce relay_announce: announce
} do } do


+ 1
- 1
test/web/activity_pub/transmogrifier_test.exs View File

@@ -1079,7 +1079,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do


{:ok, activity} = CommonAPI.post(user, %{status: "hey", visibility: "private"}) {:ok, activity} = CommonAPI.post(user, %{status: "hey", visibility: "private"})


{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
{:ok, announce_activity} = CommonAPI.repeat(activity.id, user)


{:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data) {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)




+ 1
- 1
test/web/activity_pub/utils_test.exs View File

@@ -334,7 +334,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert object = Object.normalize(note_activity) assert object = Object.normalize(note_activity)
actor = insert(:user) actor = insert(:user)


{:ok, announce, _object} = ActivityPub.announce(actor, object)
{:ok, announce} = CommonAPI.repeat(note_activity.id, actor)
assert Utils.get_existing_announce(actor.ap_id, object) == announce assert Utils.get_existing_announce(actor.ap_id, object) == announce
end end
end end


+ 1
- 1
test/web/activity_pub/views/object_view_test.exs View File

@@ -73,7 +73,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
object = Object.normalize(note) object = Object.normalize(note)
user = insert(:user) user = insert(:user)


{:ok, announce_activity, _} = CommonAPI.repeat(note.id, user)
{:ok, announce_activity} = CommonAPI.repeat(note.id, user)


result = ObjectView.render("object.json", %{object: announce_activity}) result = ObjectView.render("object.json", %{object: announce_activity})




+ 3
- 1
test/web/admin_api/admin_api_controller_test.exs View File

@@ -148,6 +148,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "DELETE /api/pleroma/admin/users" do describe "DELETE /api/pleroma/admin/users" do
test "single user", %{admin: admin, conn: conn} do test "single user", %{admin: admin, conn: conn} do
user = insert(:user) user = insert(:user)
clear_config([:instance, :federating], true)


with_mock Pleroma.Web.Federator, with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do publish: fn _ -> nil end do
@@ -2944,6 +2945,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert ":proxy_url" in db assert ":proxy_url" in db
end end


@tag capture_log: true
test "doesn't set keys not in the whitelist", %{conn: conn} do test "doesn't set keys not in the whitelist", %{conn: conn} do
clear_config(:database_config_whitelist, [ clear_config(:database_config_whitelist, [
{:pleroma, :key1}, {:pleroma, :key1},
@@ -3096,7 +3098,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
test "excludes reblogs by default", %{conn: conn, user: user} do test "excludes reblogs by default", %{conn: conn, user: user} do
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "."}) {:ok, activity} = CommonAPI.post(user, %{status: "."})
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, other_user)
{:ok, %Activity{}} = CommonAPI.repeat(activity.id, other_user)


conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses") conn_res = get(conn, "/api/pleroma/admin/users/#{other_user.nickname}/statuses")
assert json_response(conn_res, 200) |> length() == 0 assert json_response(conn_res, 200) |> length() == 0


+ 5
- 0
test/web/common_api/common_api_test.exs View File

@@ -41,6 +41,8 @@ defmodule Pleroma.Web.CommonAPITest do


{:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"}) {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})


clear_config([:instance, :federating], true)

Object.normalize(post, false) Object.normalize(post, false)
|> Object.prune() |> Object.prune()


@@ -59,6 +61,8 @@ defmodule Pleroma.Web.CommonAPITest do


{:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"}) {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})


clear_config([:instance, :federating], true)

with_mock Pleroma.Web.Federator, with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do publish: fn _ -> nil end do
assert {:ok, delete} = CommonAPI.delete(post.id, user) assert {:ok, delete} = CommonAPI.delete(post.id, user)
@@ -440,6 +444,7 @@ defmodule Pleroma.Web.CommonAPITest do
CommonAPI.repeat(activity.id, user, %{visibility: "private"}) CommonAPI.repeat(activity.id, user, %{visibility: "private"})


assert Visibility.is_private?(announce_activity) assert Visibility.is_private?(announce_activity)
refute Visibility.visible_for_user?(announce_activity, nil)
end end


test "favoriting a status" do test "favoriting a status" do


+ 3
- 3
test/web/mastodon_api/controllers/account_controller_test.exs View File

@@ -256,7 +256,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
User.block(user_one, user_two) User.block(user_one, user_two)


{:ok, activity} = CommonAPI.post(user_two, %{status: "User one sux0rz"}) {:ok, activity} = CommonAPI.post(user_two, %{status: "User one sux0rz"})
{:ok, repeat, _} = CommonAPI.repeat(activity.id, user_three)
{:ok, repeat} = CommonAPI.repeat(activity.id, user_three)


assert resp = assert resp =
conn conn
@@ -375,7 +375,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do


test "gets a user's statuses without reblogs", %{user: user, conn: conn} do test "gets a user's statuses without reblogs", %{user: user, conn: conn} do
{:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "HI!!!"}) {:ok, %{id: post_id}} = CommonAPI.post(user, %{status: "HI!!!"})
{:ok, _, _} = CommonAPI.repeat(post_id, user)
{:ok, _} = CommonAPI.repeat(post_id, user)


conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_reblogs=true") conn = get(conn, "/api/v1/accounts/#{user.id}/statuses?exclude_reblogs=true")
assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200) assert [%{"id" => ^post_id}] = json_response_and_validate_schema(conn, 200)
@@ -678,7 +678,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert %{"showing_reblogs" => false} = json_response_and_validate_schema(ret_conn, 200) assert %{"showing_reblogs" => false} = json_response_and_validate_schema(ret_conn, 200)


{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"}) {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
{:ok, %{id: reblog_id}, _} = CommonAPI.repeat(activity.id, followed)
{:ok, %{id: reblog_id}} = CommonAPI.repeat(activity.id, followed)


assert [] == assert [] ==
conn conn


+ 4
- 4
test/web/mastodon_api/controllers/notification_controller_test.exs View File

@@ -280,8 +280,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
{:ok, unlisted_activity} = {:ok, unlisted_activity} =
CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"}) CommonAPI.post(other_user, %{status: ".", visibility: "unlisted"})


{:ok, _, _} = CommonAPI.repeat(public_activity.id, user)
{:ok, _, _} = CommonAPI.repeat(unlisted_activity.id, user)
{:ok, _} = CommonAPI.repeat(public_activity.id, user)
{:ok, _} = CommonAPI.repeat(unlisted_activity.id, user)


activity_ids = activity_ids =
conn conn
@@ -301,7 +301,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
{:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)


mention_notification_id = get_notification_id_by_activity(mention_activity) mention_notification_id = get_notification_id_by_activity(mention_activity)
@@ -339,7 +339,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
{:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"})
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)


mention_notification_id = get_notification_id_by_activity(mention_activity) mention_notification_id = get_notification_id_by_activity(mention_activity)


+ 9
- 9
test/web/mastodon_api/controllers/status_controller_test.exs View File

@@ -878,8 +878,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
user3 = insert(:user) user3 = insert(:user)
{:ok, _} = CommonAPI.favorite(user2, activity.id) {:ok, _} = CommonAPI.favorite(user2, activity.id)
{:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id) {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
{:ok, reblog_activity1} = CommonAPI.repeat(activity.id, user1)
{:ok, _} = CommonAPI.repeat(activity.id, user2)


conn_res = conn_res =
build_conn() build_conn()
@@ -917,7 +917,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
test "unreblogs and returns the unreblogged status", %{user: user, conn: conn} do test "unreblogs and returns the unreblogged status", %{user: user, conn: conn} do
activity = insert(:note_activity) activity = insert(:note_activity)


{:ok, _, _} = CommonAPI.repeat(activity.id, user)
{:ok, _} = CommonAPI.repeat(activity.id, user)


conn = conn =
conn conn
@@ -1427,7 +1427,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do


test "returns users who have reblogged the status", %{conn: conn, activity: activity} do test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
{:ok, _} = CommonAPI.repeat(activity.id, other_user)


response = response =
conn conn
@@ -1458,7 +1458,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
other_user = insert(:user) other_user = insert(:user)
{:ok, _user_relationship} = User.block(user, other_user) {:ok, _user_relationship} = User.block(user, other_user)


{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
{:ok, _} = CommonAPI.repeat(activity.id, other_user)


response = response =
conn conn
@@ -1469,12 +1469,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
end end


test "does not return users who have reblogged the status privately", %{ test "does not return users who have reblogged the status privately", %{
conn: conn,
activity: activity
conn: conn
} do } do
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{status: "my secret post"})


{:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{visibility: "private"})
{:ok, _} = CommonAPI.repeat(activity.id, other_user, %{visibility: "private"})


response = response =
conn conn
@@ -1486,7 +1486,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do


test "does not fail on an unauthenticated request", %{activity: activity} do test "does not fail on an unauthenticated request", %{activity: activity} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
{:ok, _} = CommonAPI.repeat(activity.id, other_user)


response = response =
build_conn() build_conn()


+ 1
- 1
test/web/mastodon_api/views/notification_view_test.exs View File

@@ -78,7 +78,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
user = insert(:user) user = insert(:user)
another_user = insert(:user) another_user = insert(:user)
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, reblog_activity, _object} = CommonAPI.repeat(create_activity.id, another_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, another_user)
{:ok, [notification]} = Notification.create_notifications(reblog_activity) {:ok, [notification]} = Notification.create_notifications(reblog_activity)
reblog_activity = Activity.get_by_id(create_activity.id) reblog_activity = Activity.get_by_id(create_activity.id)




+ 2
- 2
test/web/mastodon_api/views/status_view_test.exs View File

@@ -442,7 +442,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
user = insert(:user) user = insert(:user)
activity = insert(:note_activity) activity = insert(:note_activity)


{:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
{:ok, reblog} = CommonAPI.repeat(activity.id, user)


represented = StatusView.render("show.json", %{for: user, activity: reblog}) represented = StatusView.render("show.json", %{for: user, activity: reblog})


@@ -600,7 +600,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status: "˙˙ɐʎns" status: "˙˙ɐʎns"
}) })


{:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user)
{:ok, activity} = CommonAPI.repeat(activity.id, other_user)


result = StatusView.render("show.json", %{activity: activity, for: user}) result = StatusView.render("show.json", %{activity: activity, for: user})




+ 1
- 1
test/web/push/impl_test.exs View File

@@ -151,7 +151,7 @@ defmodule Pleroma.Web.Push.ImplTest do
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis." "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
}) })


{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
{:ok, announce_activity} = CommonAPI.repeat(activity.id, user)
object = Object.normalize(activity) object = Object.normalize(activity)


assert Impl.format_body(%{activity: announce_activity}, user, object) == assert Impl.format_body(%{activity: announce_activity}, user, object) ==


+ 3
- 3
test/web/streamer/streamer_test.exs View File

@@ -106,7 +106,7 @@ defmodule Pleroma.Web.StreamerTest do


other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"}) {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
{:ok, announce, _} = CommonAPI.repeat(activity.id, user)
{:ok, announce} = CommonAPI.repeat(activity.id, user)


assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce} assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
refute Streamer.filtered_by_user?(user, announce) refute Streamer.filtered_by_user?(user, announce)
@@ -427,7 +427,7 @@ defmodule Pleroma.Web.StreamerTest do
{:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})


Streamer.get_topic_and_add_socket("user", user1) Streamer.get_topic_and_add_socket("user", user1)
{:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
{:ok, announce_activity} = CommonAPI.repeat(create_activity.id, user2)
assert_receive {:render_with_user, _, _, ^announce_activity} assert_receive {:render_with_user, _, _, ^announce_activity}
assert Streamer.filtered_by_user?(user1, announce_activity) assert Streamer.filtered_by_user?(user1, announce_activity)
end end
@@ -440,7 +440,7 @@ defmodule Pleroma.Web.StreamerTest do


{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
Streamer.get_topic_and_add_socket("user", user1) Streamer.get_topic_and_add_socket("user", user1)
{:ok, _favorite_activity, _} = CommonAPI.repeat(create_activity.id, user2)
{:ok, _announce_activity} = CommonAPI.repeat(create_activity.id, user2)


assert_receive {:render_with_user, _, "notification.json", notif} assert_receive {:render_with_user, _, "notification.json", notif}
assert Streamer.filtered_by_user?(user1, notif) assert Streamer.filtered_by_user?(user1, notif)


Loading…
Cancel
Save