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.Transmogrifier.BlockHandlingTest do
6 use Pleroma.DataCase, async: true
10 alias Pleroma.Web.ActivityPub.Transmogrifier
12 import Pleroma.Factory
14 test "it works for incoming blocks" do
18 File.read!("test/fixtures/mastodon-block-activity.json")
20 |> Map.put("object", user.ap_id)
22 blocker = insert(:user, ap_id: data["actor"])
24 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
26 assert data["type"] == "Block"
27 assert data["object"] == user.ap_id
28 assert data["actor"] == "http://mastodon.example.org/users/admin"
30 assert User.blocks?(blocker, user)
33 test "incoming blocks successfully tear down any follow relationship" do
34 blocker = insert(:user)
35 blocked = insert(:user)
38 File.read!("test/fixtures/mastodon-block-activity.json")
40 |> Map.put("object", blocked.ap_id)
41 |> Map.put("actor", blocker.ap_id)
43 {:ok, blocker, blocked} = User.follow(blocker, blocked)
44 {:ok, blocked, blocker} = User.follow(blocked, blocker)
46 assert User.following?(blocker, blocked)
47 assert User.following?(blocked, blocker)
49 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
51 assert data["type"] == "Block"
52 assert data["object"] == blocked.ap_id
53 assert data["actor"] == blocker.ap_id
55 blocker = User.get_cached_by_ap_id(data["actor"])
56 blocked = User.get_cached_by_ap_id(data["object"])
58 assert User.blocks?(blocker, blocked)
60 refute User.following?(blocker, blocked)
61 refute User.following?(blocked, blocker)