aboutsummaryrefslogtreecommitdiff
path: root/test/web/ostatus/incoming_documents/delete_handling_test.exs
blob: cd0447af7e4787826db9455a23ca31a53d833269 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
  use Pleroma.DataCase

  import Pleroma.Factory
  import Tesla.Mock

  alias Pleroma.Activity
  alias Pleroma.Object
  alias Pleroma.Web.OStatus

  setup do
    mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
    :ok
  end

  describe "deletions" do
    test "it removes the mentioned activity" do
      note = insert(:note_activity)
      second_note = insert(:note_activity)
      object = Object.normalize(note)
      second_object = Object.normalize(second_note)
      user = insert(:user)

      {:ok, like, _object} = Pleroma.Web.ActivityPub.ActivityPub.like(user, object)

      incoming =
        File.read!("test/fixtures/delete.xml")
        |> String.replace(
          "tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status",
          object.data["id"]
        )

      {:ok, [delete]} = OStatus.handle_incoming(incoming)

      refute Activity.get_by_id(note.id)
      refute Activity.get_by_id(like.id)
      assert Object.get_by_ap_id(object.data["id"]).data["type"] == "Tombstone"
      assert Activity.get_by_id(second_note.id)
      assert Object.get_by_ap_id(second_object.data["id"])

      assert delete.data["type"] == "Delete"
    end
  end
end