logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

block_handling_test.exs (1881B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.User
  8. alias Pleroma.Web.ActivityPub.Transmogrifier
  9. import Pleroma.Factory
  10. test "it works for incoming blocks" do
  11. user = insert(:user)
  12. data =
  13. File.read!("test/fixtures/mastodon-block-activity.json")
  14. |> Poison.decode!()
  15. |> Map.put("object", user.ap_id)
  16. blocker = insert(:user, ap_id: data["actor"])
  17. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  18. assert data["type"] == "Block"
  19. assert data["object"] == user.ap_id
  20. assert data["actor"] == "http://mastodon.example.org/users/admin"
  21. assert User.blocks?(blocker, user)
  22. end
  23. test "incoming blocks successfully tear down any follow relationship" do
  24. blocker = insert(:user)
  25. blocked = insert(:user)
  26. data =
  27. File.read!("test/fixtures/mastodon-block-activity.json")
  28. |> Poison.decode!()
  29. |> Map.put("object", blocked.ap_id)
  30. |> Map.put("actor", blocker.ap_id)
  31. {:ok, blocker} = User.follow(blocker, blocked)
  32. {:ok, blocked} = User.follow(blocked, blocker)
  33. assert User.following?(blocker, blocked)
  34. assert User.following?(blocked, blocker)
  35. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  36. assert data["type"] == "Block"
  37. assert data["object"] == blocked.ap_id
  38. assert data["actor"] == blocker.ap_id
  39. blocker = User.get_cached_by_ap_id(data["actor"])
  40. blocked = User.get_cached_by_ap_id(data["object"])
  41. assert User.blocks?(blocker, blocked)
  42. refute User.following?(blocker, blocked)
  43. refute User.following?(blocked, blocker)
  44. end
  45. end