1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do
6 use Oban.Testing, repo: Pleroma.Repo
7 use Pleroma.DataCase, async: true
12 alias Pleroma.Tests.ObanHelpers
14 alias Pleroma.Web.ActivityPub.ActivityPub
15 alias Pleroma.Web.ActivityPub.Builder
16 alias Pleroma.Web.ActivityPub.SideEffects
17 alias Pleroma.Web.CommonAPI
19 alias Pleroma.LoggerMock
20 alias Pleroma.Web.ActivityPub.ActivityPubMock
23 import Pleroma.Factory
25 describe "user deletion" do
29 {:ok, delete_user_data, _meta} = Builder.delete(user, user.ap_id)
30 {:ok, delete_user, _meta} = ActivityPub.persist(delete_user_data, local: true)
34 delete_user: delete_user
38 test "it handles user deletions", %{delete_user: delete, user: user} do
39 {:ok, _delete, _} = SideEffects.handle(delete)
40 ObanHelpers.perform_all()
42 assert User.get_cached_by_ap_id(user.ap_id).deactivated
46 describe "object deletion" do
49 other_user = insert(:user)
51 {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"})
52 {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op})
53 {:ok, favorite} = CommonAPI.favorite(user, post.id)
54 object = Object.normalize(post, fetch: false)
55 {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
56 {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true)
68 test "it handles object deletions", %{
80 |> expect(:stream_out, fn ^delete -> nil end)
81 |> expect(:stream_out_participations, fn %Object{id: ^object_id}, %User{id: ^user_id} ->
85 {:ok, _delete, _} = SideEffects.handle(delete)
86 user = User.get_cached_by_ap_id(object.data["actor"])
88 object = Object.get_by_id(object.id)
89 assert object.data["type"] == "Tombstone"
90 refute Activity.get_by_id(post.id)
91 refute Activity.get_by_id(favorite.id)
93 user = User.get_by_id(user.id)
94 assert user.note_count == 0
96 object = Object.normalize(op.data["object"], fetch: false)
98 assert object.data["repliesCount"] == 0
101 test "it handles object deletions when the object itself has been pruned", %{
108 object_id = object.id
112 |> expect(:stream_out, fn ^delete -> nil end)
113 |> expect(:stream_out_participations, fn %Object{id: ^object_id}, %User{id: ^user_id} ->
117 {:ok, _delete, _} = SideEffects.handle(delete)
118 user = User.get_cached_by_ap_id(object.data["actor"])
120 object = Object.get_by_id(object.id)
121 assert object.data["type"] == "Tombstone"
122 refute Activity.get_by_id(post.id)
124 user = User.get_by_id(user.id)
125 assert user.note_count == 0
127 object = Object.normalize(op.data["object"], fetch: false)
129 assert object.data["repliesCount"] == 0
132 test "it logs issues with objects deletion", %{
138 |> Object.change(%{data: Map.delete(object.data, "actor")})
142 |> expect(:error, fn str -> assert str =~ "The object doesn't have an actor" end)
144 {:error, :no_object_actor} = SideEffects.handle(delete)